junrao commented on code in PR #24170:
URL: https://github.com/apache/kafka/pull/24170#discussion_r4558033237
##########
clients/src/main/java/org/apache/kafka/common/network/KafkaChannel.java:
##########
@@ -437,7 +439,20 @@ public long write() throws IOException {
return 0;
midWrite = true;
- return send.writeTo(transportLayer);
+ // A ByteBufferSend is written with one call, but SSL writes each of
its buffers as its own TLS record
+ boolean singleWrite = send.send() instanceof ByteBufferSend &&
!(transportLayer instanceof SslTransportLayer);
+ if (!OperatingSystem.IS_LINUX || singleWrite)
+ return send.writeTo(transportLayer);
+
+ // With TCP_NODELAY off the kernel joins the small parts of a send
into full segments, and on Linux
+ // turning it back on sends the queued data at once instead of waiting
for an ACK (see tcp(7)).
+ SocketChannel socketChannel = transportLayer.socketChannel();
+ socketChannel.setOption(StandardSocketOptions.TCP_NODELAY, false);
Review Comment:
The SSL tests show slightly increased CPU usage, potentially due to the
additional system call overhead. I am a bit concerned that this will show up
even more on lower volume traffic.
Another option is to fix the issue only for the SSL case, which most
production deployment probably enables. Since SslTransportLayer needs to wrap
the bytes for encryption before sending them to the socket, it gives us a
chance to control when to flush the bytes to socket packets. Claude suggested
the following high level approach.
There may be a better fix for SSL. The extra SSL packets come from
SslTransportLayer.write(ByteBuffer[]) (:767-788): it wraps each buffer into its
own TLS record and flushes it separately (write(src), :723-755). For example,
the 4-byte size prefix of every ByteBufferSend becomes its own TLS record and
segment. SSLEngine.wrap(ByteBuffer[] srcs, int offset, int length, ByteBuffer
dst) can wrap consecutive buffers into one record, up to the 16 KB record
limit. That would cut:
TLS records, meaning fewer encryption calls and about 22–29 bytes of
overhead each;
segments, on every platform, with no setsockopt.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]