Optimize request buffer release #12239 (#12240)

Release request buffer before handling when there is no content

---------

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Co-authored-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Greg Wilkins 2024-09-18 07:11:32 +10:00 committed by GitHub
parent e52bd7a9c7
commit dc43f3d498
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -422,6 +422,11 @@ public class HttpParser
return _state;
}
public boolean hasContent()
{
return _endOfContent != EndOfContent.NO_CONTENT;
}
public boolean inContentState()
{
return _state.ordinal() >= State.CONTENT.ordinal() && _state.ordinal() < State.END.ordinal();

View File

@ -398,6 +398,15 @@ public class HttpConnection extends AbstractMetaDataConnection implements Runnab
if (LOG.isDebugEnabled())
LOG.debug("HANDLE {} {}", request, this);
// If the buffer is empty and no body is expected, then release the buffer
if (isRequestBufferEmpty() && !_parser.hasContent())
{
// try parsing now to the end of the message
parseRequestBuffer();
if (_parser.isComplete())
releaseRequestBuffer();
}
// Handle the request by running the task.
_handling.set(true);
Runnable onRequest = _onRequest;
@ -424,9 +433,17 @@ public class HttpConnection extends AbstractMetaDataConnection implements Runnab
{
if (LOG.isDebugEnabled())
LOG.debug("upgraded {} -> {}", this, getEndPoint().getConnection());
if (_requestBuffer != null)
releaseRequestBuffer();
break;
}
// If we have already released the request buffer, then use fill interest before allocating another
if (_requestBuffer == null)
{
fillInterested();
break;
}
}
else if (filled == 0)
{