Skip to content

Commit

Permalink
Optimize request buffer release #12239 (#12240)
Browse files Browse the repository at this point in the history
Release request buffer before handling when there is no content

---------

Signed-off-by: Simone Bordet <[email protected]>
Co-authored-by: Simone Bordet <[email protected]>
  • Loading branch information
gregw and sbordet authored Sep 17, 2024
1 parent e52bd7a commit dc43f3d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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;
}

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();
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)
releaseRequestBuffer();
break;
}

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

0 comments on commit dc43f3d

Please sign in to comment.