Skip to content

Commit

Permalink
Combines prologue and headers into a single write to prevent potentia…
Browse files Browse the repository at this point in the history
…l TCP delays when using TLS. With TLS, each write becomes a record and a small record can be delayed due to Nagle's algorithm. (#9842)
  • Loading branch information
spericas authored Feb 27, 2025
1 parent a7c477c commit 25bc0ed
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,16 @@ private void sendPrologueAndHeader() {
headers.remove(HeaderNames.CONTENT_LENGTH);
}

// write prologue and headers in single buffer to avoid multiple TLS records,
// which in turn can result in a delay when TCP_NO_DELAY is false
BufferData buffer = BufferData.growing(512);
buffer.write(prologue);
if (LOGGER.isLoggable(System.Logger.Level.TRACE)) {
ctx.log(LOGGER, System.Logger.Level.TRACE, "send prologue: %n%s", prologue.debugDataHex());
}
writer.writeNow(prologue);

BufferData headerBuffer = BufferData.growing(128);
if (LOGGER.isLoggable(System.Logger.Level.TRACE)) {
ctx.log(LOGGER, System.Logger.Level.TRACE, "send headers:%n%s", headers);
}
writeHeaders(headers, headerBuffer, protocolConfig.validateRequestHeaders());
writer.writeNow(headerBuffer);
writeHeaders(headers, buffer, protocolConfig.validateRequestHeaders());
writer.writeNow(buffer);

whenSent.complete(request);

Expand Down

0 comments on commit 25bc0ed

Please sign in to comment.