You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(socket): FrontRustls::socket_read issues one EAGAIN recv per H2 frame while plaintext is already buffered #1588
FrontRustls::socket_read (lib/src/socket.rs:588-640 at b5169d44, read_tls at :622) calls ServerConnection::read_tls on every entry, before it looks at the plaintext rustls has already decrypted. The H2 read path (lib/src/protocol/mux/h2.rs:8034) reads frame by frame: a 9-byte header, then the payload. One TLS record usually carries several frames, so every call after the first finds the plaintext it needs already buffered, yet still issues a recv(2) that returns EAGAIN.
Measurement
Release build of origin/mainb5169d44, one worker, 20 requests to a local backend, syscalls counted with an LD_PRELOAD fd interposer and with intentrace -p on the worker:
scenario
recv/req
recv EAGAIN/req
H2 TLS, one connection per request
19.85
12.85
H2 TLS, 20 requests multiplexed on one connection
10.30
6.50
Of the 234 recv that returned EAGAIN in the H2 per-connection window that was attributed by backtrace, 206 come from this one call site, in runs of 4 to 5 consecutive calls: one per frame after the first frame of a record.
Proposed fix
rustls's Reader::read returns WouldBlock only when no plaintext is buffered (rustls-0.23.45/src/conn.rs:193), and wants_read() is false while plaintext is pending (src/common_state.rs:674-684). So:
drain the already-decrypted plaintext first;
call read_tls only when that leaves the caller's buffer unfilled;
after a read_tls that returned bytes without producing plaintext (partial record), loop and read again, exactly as today.
This is what tokio-rustls does (poll_fill_buf only reads TLS while wants_read()), and what OpenSSL/HAProxy do implicitly (SSL_read serves buffered records without touching the BIO).
EOF, close_notify, SocketResult and the edge-triggered readiness contract must stay unchanged: every EAGAIN still ends the call with WouldBlock, which update_readiness turns into "drop READABLE until the next event". A separate "WouldBlock seen this readiness turn" memory would need the mux to reset it on every READABLE event; whether it saves anything on top of the reordering is to be measured before adding it.
Expected gain (estimate, to be verified): about -9.8 syscalls per request for H2 one-connection-per-request, -4.65 for multiplexed H2.
Activity
perf(socket): serve buffered TLS plaintext before calling read_tls
fix(socket): keep a fatal TLS read error sticky
perf(socket): serve buffered TLS plaintext before calling read_tls
fix(socket): keep a fatal TLS read error sticky
perf(socket): serve buffered TLS plaintext before calling read_tls (s…