Repository navigation
perf(mux): sample the access-log RTT once per connection - #1634
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 27, 2026 22:24
FlorentinDUBOIS
force-pushed
the
perf/tcp-info-per-connection
branch
2 times, most recently
from
September 27, 2026 23:51
b90603d to
07fb780
Compare
client_rtt and server_rtt each cost one getsockopt(TCP_INFO) per request: the H1 access-log sites and Endpoint::peer_rtt read their socket at every log line, and Mux::expire_client_rtt forgot the H2 frontend sample at every pass. On an H1 keep-alive connection that was two of the worker's 11.55 syscalls per request. Each connection now reads its own socket once. memoized_rtt (lib/src/protocol/mux/mod.rs) stores the first sample in the connection (ConnectionH1::rtt, H2Shell::local_rtt), and Connection::rtt answers every later ask from it: the H1 log sites, EndpointServer and EndpointClient::peer_rtt, ShellEndpoint::local_rtt and Mux::close. A backend connection keeps its sample across keep-alive pool reuse. Mux::expire_client_rtt and H2Shell::expire_local_rtt are removed. Pipe and TCP already logged once per session and are unchanged. The sample is taken at the connection's first access log, not at accept: Linux already reports the handshake RTT straight out of accept (27-34 us on loopback, and likewise after connect), so an earlier read would be valid, but the lazy one is free on a connection that never logs, and a backend dial is still in flight when its non-blocking connect(2) returns. Operator-visible: both cells now mean "the SRTT at the connection's first request", repeated on every line of that connection; doc/configure.md, doc/observability.md, doc/h2_mux_internals.md, LIFECYCLE.md and CHANGELOG.md say so. intentrace -p, release build, 20 requests on one client connection: H1 keep-alive 11.55 -> 9.65 syscalls/request (getsockopt 2.00 -> 0.10), H1 over TLS 11.85 -> 9.95, 20 multiplexed H2 streams 12.35 -> 11.35 (getsockopt 2.00 -> 1.05; one backend connection per concurrent stream). keep_alive_requests_read_tcp_info_once_per_connection (h1.rs) and a_mux_pass_keeps_the_connection_sample_and_reads_none_without_a_log (mod.rs) were seen red on 58550dd (40 reads instead of 2; the pass forgot the sample). The once-per-pass H2 test is rewritten into snapshot_rtts_samples_the_frontend_once_per_connection, forwarded in check_doc_citations.py, and the line citations this changeset moved are re-anchored. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
perf/tcp-info-per-connection
branch
from
September 28, 2026 01:21
07fb780 to
cc59abf
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.
Problem
The access log's
client_rttandserver_rtteach cost onegetsockopt(TCP_INFO)per request. The H1 log sites (H1::Complete,H1::Upgrade,H1::EarlyHint) andEndpoint::peer_rttread their socket at every line, andMux::expire_client_rttforgot the H2 frontend sample at every pass (#1598 made the read lazy, not rarer). On an H1 keep-alive connection that was 2.00 of the worker's 11.55 syscalls per request.Change
Operator decision: accept one sample per connection.
memoized_rtt(lib/src/protocol/mux/mod.rs) keeps a connection's first sample in aCell<Option<Option<Duration>>>on the connection (ConnectionH1::rtt, new field;H2Shell::local_rtt, existing field) and answers every later request from it.Connection::rttdispatches H1/H2.EndpointServer::peer_rtt,EndpointClient::peer_rtt,ShellEndpoint::local_rttandMux::close. A backend connection keeps its sample across keep-alive pool reuse, since theConnectioncarries it.Mux::expire_client_rttandH2Shell::expire_local_rttare removed.Pipe::log_requeststill readssocket_rttonce, at the end of the session. That is one read per session, left out of scope.No syscall added anywhere, no allocation added (one
Cellof 16 bytes perConnectionH1), no I/O path touched.Sampling point, and why
Hypothesis tested: "
tcpi_rttis 0 before the first data ACK". Refuted on Linux 7.2.7, loopback. A Python probe readingTCP_INFO(tcpi_rtt,tcpi_rttvar):accept: 34 / 27 / 29 µs over three trials. This is the SYN/SYN-ACK measurement.connect: 80 / 30 / 33 µs.So a sample at
acceptwould be valid. The chosen point is still the connection's first access log:The lazy read is free on a connection that never logs. A backend dial is still in flight when its non-blocking
connect(2)returns. Semantics, now documented: "RTT sampled at the connection's first request", repeated on every line of that connection. The value is frozen and no longer follows the kernel's SRTT. The two cells of one line come from two different instants.Measurement
intentrace -pon the worker. Release build--no-default-features --features jemallocator,crypto-aws-lc-rs, one worker, pythonhttp.serverbackend on loopback,curl, 20 requests on one client connection (plus warmup). Base58550dd4, runs interleaved base/after, two runs per cell, 1-minute load average 21–48 (shared host):getsockopt/req beforeconnects in the window), so the 20 backend reads remain, one per connection. Only the 19 repeated frontend reads disappear.client_rttandserver_rtt, with no-cell. There are 4 distinct (client, server) pairs, one per client connection (readiness probe, two warmups, the measured one). Before: 27 distinct pairs.Tests
Seen red on
58550dd4before the fix, green after:keep_alive_requests_read_tcp_info_once_per_connection(h1.rs, new). It drives 20 keep-alive requests through the realH1::Completesite ofConnectionH1::writable, with the backend recycled byend_stream/start_streamas aMuxdoes. It asserts two things:TCP_INFOreads in total. Red:left: 40, right: 2.a_mux_pass_keeps_the_connection_sample_and_reads_none_without_a_log(mod.rs). This rewritesa_mux_pass_forgets_the_previous_sample_and_reads_none_without_a_log. Red:left: None, right: Some(Some(4321s)).Also rewritten:
snapshot_rtts_samples_the_frontend_once_per_passbecamesnapshot_rtts_samples_the_frontend_once_per_connection(h2.rs). Its documented red (the memo hit removed frommemoized_rtt) was checked:left: 2, right: 1. The old names are forwarded incheck_doc_citations.pyRENAMED_TESTS, because the CHANGELOG cites them.Docs
doc/configure.md"When each cell is measured": Changed RTT semantics in access logs.doc/observability.md.doc/h2_mux_internals.md: new "One sample per connection" section, with the measurements.lib/src/protocol/mux/LIFECYCLE.md.CHANGELOG.md(Changed).My line shifts in
h1.rs,h2.rsandmod.rsmoved 27file.rs:NNNcitations and three pinned blocks. They are re-anchored mechanically from a line diff, in bothLIFECYCLE.md,doc/testing.mdanddoc/h2_mux_internals.md, and--base origin/mainconfirms every cited line's text is unchanged.Conflicts with open PRs
git merge-treeagainst perf(h1): 24.6 → 15.6 heap operations per keep-alive request #1628 and refactor(command): share cluster ids as Arc<str> instead of copying Strings #1629: clean. The new test uses"test-cluster".into(), so it compiles with refactor(command): share cluster ids as Arc<str> instead of copying Strings #1629'sClusterIdtoo.h2.rs:NNNNfence numbers indoc/h2_mux_internals.md/LIFECYCLE.mdconflict, numbers only. Whichever PR merges second re-anchors them.kawa_h1/editor.rsandHttpContextare untouched.Commands run
cargo build --lockedcargo build --all-features --lockedcargo clippy --all-targets --locked -- -D warningscargo clippy --all-targets --locked --no-default-features --features crypto-ring,opentelemetry,splice,simd -- -D warningscargo +nightly fmt --all -- --checkcheck_doc_citations.py(tree,--base origin/main,--self-test, broken-fixture--rootexit 1 with its failure report)cargo test --workspace --locked -- --skip tests::fuzz_tests:: --test-threads=8: 2160 passed, 0 failed.Results:
to_owned()→into()). After it I re-ran fmt, both clippy cells, the citation runs and the new test.tests::tests::test_async(client1 99/100 responses) under--test-threads=8at load average 40+. I ran it 3 times in isolation on this branch and 3 times on58550dd4: 6/6 green. The second full battery run was green.Protocol/security impact: none. No framing, parsing, readiness or I/O change. The only change is when an access-log value is read.
Signed-off-by: Florentin Dubois [email protected]