Coalesce response head with body to avoid extra flush#311
Closed
rnro wants to merge 1 commit into
Closed
Conversation
Motivation * `HTTPDrippingDownloadHandler` used `writeAndFlush` for the response head, causing it to be flushed separately from the body. This results in two flushes per response instead of one, which can produce extra packets on the wire for small downloads. Modifications * Change `onResponseDelayCompleted` to use `context.write` instead of `context.writeAndFlush` for the response head, so it is coalesced with the body in the same flush. * Add a `needsFlush` flag to ensure the head is still flushed promptly if `writeChunk` doesn't flush (e.g. zero-size chunks or channel not writable). * Add `testSmallDownloadDoesNotFlushHeadSeparately` verifying that head, body, and end are all written before the first flush. Result * For small single-chunk downloads, the response head and body are sent in a single flush instead of two.
5737c6c to
175f10d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
HTTPDrippingDownloadHandlerusedwriteAndFlushfor the response head, causing it to be flushed separately from the body. This results in two flushes per response instead of one, which can produce extra packets on the wire for small downloads.Modifications
onResponseDelayCompletedto usecontext.writeinstead ofcontext.writeAndFlushfor the response head, so it is coalesced with the body in the same flush.needsFlushflag to ensure the head is still flushed promptly ifwriteChunkdoesn't flush (e.g. zero-size chunks or channel not writable).testSmallDownloadDoesNotFlushHeadSeparatelyverifying that head, body, and end are all written before the first flush.Result