Skip to content

perf(mux): getsockopt(TCP_INFO) is sampled every pass instead of once per access log #1590

Closed

Description

@FlorentinDUBOIS

Problem

getsockopt(TCP_INFO) is issued far more often than any consumer needs it. Measured on a release build of b5169d44 (python http.server backend on loopback, curl, N=20, one worker, LD_PRELOAD backtrace interposer on getsockopt, intentrace -p as cross-check):

scenario TCP_INFO per request (interposer) needed
H1, 20 sequential connections 2.95 2 (client_rtt + server_rtt of the access log)
H2, 20 sequential connections 7.80 2
H2, 20 requests multiplexed on one connection 5.70 ≤ 2

The only consumer of those values is the access log (client_rtt / server_rtt, command/src/logging/access_logs.rs). No metric and no load-balancing cost reads TCP_INFO: PeakEWMA is fed from the connect time (lib/src/backends.rs:312).

Attribution of the surplus, relocated on e49d78ab:

  1. One sample per Mux pass, whether or not the pass emits a log. Mux::refresh_client_rtt (lib/src/protocol/mux/mod.rs:1594) runs at the top of SessionState::ready (:1622), Mux::timeout_inner (:2944) and Mux::shutting_down_inner (:3321). An H2 request takes about five passes, so it pays about five samples for the one client_rtt its access log prints.
  2. The first pass after the TLS handshake pays one too. The TCP_INFO attributed to lib/src/https.rs:1109 is not in upgrade(): it is the recursive self.ready(session) that re-enters the new Mux, and therefore case 1 again. Fixing case 1 removes it without touching https.rs.
  3. Mux::close samples the frontend unconditionally (mod.rs:1778) before looking for a stream that still owes an access log. On a normal close every stream has already been logged, so the sample is thrown away: one per connection, H1 and H2.

Proposal

Take the frontend sample lazily: at most once per pass, at the first access log the pass emits, and never in a pass that emits none. The H2 core still never touches a socket: it asks for the value through its Endpoint, the way it already asks for server_rtt through Endpoint::peer_rtt, and the shell that owns the socket answers and memoizes it for the rest of the pass. Mux::close samples only when it finds a stream to log.

What the access log reports does not change meaning: several H2 streams finishing in one pass still share one client_rtt, and the value is now taken when the first of them is logged instead of at the top of the pass.

Prior art: HAProxy reads TCP_INFO on demand, when a fc_rtt / bc_rtt sample fetch is evaluated (src/tcp_sample.c, get_tcp_info), never on a per-event cadence.

Expected: H1 2.95 → 2, H2 7.80 → 2, multiplexed H2 5.70 → at most 2 per request.

Activity

  1. added a commit that references this issue on Sep 26, 2026
    04a6524
  2. added a commit that references this issue on Sep 26, 2026
    f165a3d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions