iatsuk commented on PR #24170: URL: https://github.com/apache/kafka/pull/24170#issuecomment-6768113802
Notes for reviewers (tests and measurements). This replaces #10333, which added a config to turn TCP_NODELAY off; see the dev@ thread for KIP-723 why that was not a good idea. **Tests** - New `KafkaChannelTest#testWriteTurnsTcpNoDelayOffDuringSendOnLinux`, and `testSending` gets a mocked socket channel. - `KafkaChannelTest`, `SelectorTest`, `Tls12SelectorTest`, `Tls13SelectorTest`, `SslTransportLayerTest`: all pass. - `checkstyleMain`, `checkstyleTest`, `spotlessCheck` for `clients`: pass. **Platforms.** The change is only active on Linux. `tcp(7)` documents that setting `TCP_NODELAY` flushes the pending output. A small test with a request and an answer in two writes (Nagle + delayed ACK) gives on Linux: Nagle on 41 ms, `TCP_NODELAY` 0.03 ms, toggle 0.03 ms. On macOS the same test was inconclusive (loopback is ACKed at once), so on other platforms the behaviour does not change. **Benchmark.** 3 brokers (KRaft, combined mode) on one Linux host with 16 vCPU, 5 topics x 600 partitions, RF=3, 5 producers with `acks=all` and 3,000 records/s in total, round-robin over all partitions. Latency probe: the loop of `EndToEndLatency` (`acks=all`, `fetch.max.wait.ms=0`, 3,000 messages), changed to keep every result. Brokers and clients run the same build. Packets are counted with `ss` (`segs_out`) on all broker connections. Baseline is trunk at cfcdfb7654, runs are interleaved. | | trunk | this PR | |---|---|---| | PLAINTEXT packets/s (7 runs) | 18,838 | 2,633 (-86%) | | PLAINTEXT avg packet | 137 B | 999 B | | PLAINTEXT broker CPU | 232% | 209% | | PLAINTEXT probe p50 / p99 (median of runs) | 17.6 / 87 ms | 17.0 / 91 ms | | SSL packets/s (3 runs) | 31,150 | 1,386 (-96%) | | SSL broker CPU | 231% | 228% | | SSL probe p50 / p99 (median of runs) | 17.3 / 86 ms | 17.3 / 111 ms | With SSL the gain is bigger because `SslTransportLayer` wraps every buffer of a send into its own TLS record and writes it alone, also for the requests of the clients. There are rare outliers of 500-600 ms with `acks=all`, also on trunk. To check that this change does not make them worse, I counted the probe messages over 400 ms in all four combinations of brokers and clients (PLAINTEXT, 3 runs each, order rotated): | brokers / clients | messages > 400 ms per run (of 3,000) | |---|---| | trunk / trunk | 8, 22, 6 | | trunk / this PR | 7, 12, 23 | | this PR / trunk | 10, 12, 13 | | this PR / this PR | 10, 8, 13 | In all cases the time is spent waiting for the produce response, not in the consumer. Generated-by: Claude Opus 5.5 -- 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]
