Repository navigation
refactor(mux-h2): sample the frontend RTT once per Mux pass (#1339, Q11) - #1515
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 24, 2026 23:55
`ConnectionH2::snapshot_rtts` called `stats::socket_rtt` on every stream recycle, at five call sites. That was the last `SocketHandler::socket_ref` reach in production `h2.rs`, and a concrete `mio::net::TcpStream` is exactly what no in-memory transport can synthesise, so it was one of the last things tying the core to an operating-system type. Q11's remote half already shipped: `Endpoint::socket` became `Endpoint::peer_rtt`, so `server_rtt` was injected already. `ConnectionH2::client_rtt` is now a carried field, written only by `Mux::refresh_client_rtt` and read only by `snapshot_rtts`. `Mux` samples at the three entry points that can reach an access log: `SessionState::ready`, `Mux::timeout_inner` and `Mux::shutting_down_inner`. In `ready` the sample sits above `ready_inner`'s outer loop rather than inside it, where `Context::now` is refreshed: a clock read is free and a `getsockopt(TCP_INFO)` is not, so one readiness sweep must pay for at most one. In `timeout_inner` it sits below `Mux::consume_timer_entry`, because the wheel rounds to the nearest tick and a firing that re-validates as early would otherwise spend a syscall on a pass that does nothing. `Mux::close` keeps its own existing sample and `ConnectionH2::close` emits no access log. Behaviour change, stated in `doc/configure.md` for operators: on HTTP/2 the access log's `client_rtt` no longer means "the frontend SRTT when this stream finished" but "the frontend SRTT at the last readiness sweep". Streams completing in one sweep report one identical value, a percentile over H2 access logs is weighted by how many streams finished together, and the value can be one sweep old. `server_rtt` still samples per access log through `Endpoint::peer_rtt`, so the two cells on an H2 log line no longer share a sampling instant. H1, Pipe and the TCP frontend are untouched. This costs syscalls rather than saving them at e2e concurrency, because a per-sweep sample beats a per-stream one only above one recycle per sweep. Counted three times per workload at a 1-minute load average of 3.5, with `stats::socket_info` and `Mux::refresh_client_rtt` marked: `client_rtt` TCP_INFO calls went 50 -> 140 (2.80x) on `test_h2_concurrent_streams` and 250 -> 483 (1.93x) on `test_h2_50_concurrent_streams_no_crosstalk`; all TCP_INFO went 110 -> 200 (1.82x) and 505 -> 738 (1.46x). The before-counts are exactly the stream-recycle counts and identical across runs; the after-counts vary a few percent because the rate now follows event-loop wake-ups rather than work completed. The rejected per-entry-point shape measured 7.8-9.7x with +6.5% / +5.3% CPU, so this is the cheaper extraction and not a free one. Emitting the access log as an output the shell fills in removes the cost outright and is a larger change. Pinned by `snapshot_rtts_reports_the_carried_pass_sample_to_every_stream` and `a_mux_pass_refreshes_the_carried_client_rtt`, each seen red first against a surgical revert and carrying its own recipe. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
refactor/h2-rtt-per-sweep
branch
from
September 25, 2026 02:00
a0f2bcb to
54d9292
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.
Question 11 of #1339, local half. The remote half already shipped in #1471:
Endpoint::socketbecameEndpoint::peer_rtt, soserver_rttwas injectedalready. This is the
client_rtthalf.What changed
ConnectionH2::snapshot_rttscalledstats::socket_rtton every streamrecycle, at five call sites. That was the last
SocketHandler::socket_refreach in production
h2.rs—socket_mutnever had one, and everyremaining spelling is in
mod tests. A concretemio::net::TcpStreamisexactly what no in-memory transport can synthesise, so this was one of the
last things tying the core to an operating-system type.
ConnectionH2::client_rttis now a carried field, written only byMux::refresh_client_rttand read only bysnapshot_rtts. The five callsites are untouched.
This costs syscalls, it does not save them
A per-sweep sample beats a per-stream one only above one recycle per
readiness sweep, and at e2e concurrency it is well under that. Counted by
marking
stats::socket_infoandMux::refresh_client_rtt, three runs perworkload, 1-minute load average 3.5 before and after:
client_rttTCP_INFO beforetest_h2_concurrent_streams(10 × 5 streams)test_h2_50_concurrent_streams_no_crosstalk(5 × 50)The before-counts are exactly the stream-recycle counts (50 and 250) and are
identical across all three runs; the after-counts vary a few percent, because
the rate now follows event-loop wake-ups rather than work completed. Recycles
per sweep were 0.36 and 0.52, where 1.0 is break-even — so the ratio improves
as multiplexing rises, and a busy connection amortises the sample the way the
shape intends while a quiet one does not.
For scale: the rejected per-entry-point shape (mirroring the value in wherever
ConnectionH2::nowis mirrored fromContext::now) measured 7.8–9.7× with+6.5% / +5.3% CPU. So per-sweep is the cheaper of the two extraction shapes,
and it is not a free one. Emitting the access log as an output the shell fills
in removes the cost outright and is a larger change.
What the access log's RTT now means
On HTTP/2 only,
client_rttno longer means "the frontend SRTT when thisstream finished". It means "the frontend SRTT at the last readiness sweep".
client_rtt. Repeated values across concurrent streams are expected and arenot a stuck measurement.
happened to complete together, and a value can be up to one sweep old.
server_rttis unchanged — still read per access log throughEndpoint::peer_rtt, because the backend socket is the other side of theconnection. So the two cells on one H2 log line no longer share a sampling
instant, and their difference is not a network asymmetry.
access log.
doc/configure.mdgains a "When each cell is measured" subsection saying allof this where an operator trending the field will find it.
Where the sample is taken
Muxsamples at the three entry points that can reach an access log:SessionState::ready,Mux::timeout_inner,Mux::shutting_down_inner.ready, aboveready_inner's outer loop rather than inside it whereContext::nowis refreshed — a clock read is free, agetsockopt(TCP_INFO)is not, so one sweep pays at most one.
timeout_inner, belowMux::consume_timer_entry: the wheel rounds tothe nearest tick and a firing that re-validates as early is common (§7.6),
so sampling above the gate would spend a syscall on passes that do nothing.
Mux::closekeeps its own pre-existing sample;ConnectionH2::closeemitsno access log.
Docs
doc/configure.md(operator contract),doc/h2_mux_internals.md(decision,the three shapes, the measurement table — and the now-false "the RTT read is
deliberately not taken here" paragraph rewritten),
lib/src/protocol/mux/LIFECYCLE.md§7.5 (the RTT joins the per-pass snapshot discipline, with its two differences
from the clock),
CHANGELOG.md.Tests
snapshot_rtts_reports_the_carried_pass_sample_to_every_stream(h2.rs) —two streams finishing in one pass report the same carried value. Premise
asserted: the live loopback socket answers a µs SRTT that can never equal the
sentinel, so a
snapshot_rttsthat merely lost the ability to read thesocket would not pass.
a_mux_pass_refreshes_the_carried_client_rtt(mod.rs) — a later passreports a freshly sampled value. Entered through
SessionState::timeout,which needs no mock;
SessionState::readytakesdyn ProxySession+dyn L7Proxyand this crate has no test implementation of either.Both seen red first against a surgical revert, each carrying its own
TO SEE THIS REDrecipe with the measured assertion text.