Improvements to keepalive-connection shedding #2628
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
As a followup to df72887, this PR is an attempt to refactor the 'keepalive-connection shedding' logic to improve its performance and reliability.
Summary of changes:
Instead of closing the socket by breaking out of the
Server#process_client
loop from the 'keepalive == true' branch, move the connection-shedding logic to modify theres_info[:keep_alive]
variable inRequest#str_headers
. This writes theConnection: close
header as part of the final response before closing the socket, allowing clients to reopen a new connection more gracefully (for example, preventing 'socket read' errors from being logged inwrk
).Instead of shedding the keepalive connection after a fixed number of consecutive inline requests, shed the connection whenever the server is 'at capacity' (busy threads >= max), and there is a new pending connection in the listener socket waiting to be accepted.
Additionally, push a keepalive connection back to the reactor whenever there's a pending request in the threadpool backlog (but not a new connection pending), to ensure that requests are serviced fairly across all the keepalive connections already accepted in the server.
Your checklist for this pull request
[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.