Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize request buffer release #12239 #12240

Merged
merged 12 commits into from
Sep 17, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ public State getState()
return _state;
}

public boolean hasContent()
{
return _endOfContent != EndOfContent.NO_CONTENT;
}
gregw marked this conversation as resolved.
Show resolved Hide resolved

public boolean inContentState()
{
return _state.ordinal() >= State.CONTENT.ordinal() && _state.ordinal() < State.END.ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,15 @@ public void onFillable()
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();
gregw marked this conversation as resolved.
Show resolved Hide resolved
if (_parser.isComplete())
releaseRequestBuffer();
}

// Handle the request by running the task.
_handling.set(true);
Runnable onRequest = _onRequest;
Expand All @@ -424,7 +433,15 @@ public void onFillable()
{
if (LOG.isDebugEnabled())
LOG.debug("upgraded {} -> {}", this, getEndPoint().getConnection());
releaseRequestBuffer();
if (_requestBuffer != null)
gregw marked this conversation as resolved.
Show resolved Hide resolved
releaseRequestBuffer();
break;
}

// If we have already released the request buffer, then use fill interest before allocating another
if (_requestBuffer == null)
{
fillInterested();
break;
}
}
Expand Down
Loading