Repository navigation
Commit cc116bb
committed
perf(stream): one tokio task per lane, and one decoder for both transports
The concurrent-stream searches were capped far below the throughput searches
because `stream_window` spawned an OS thread per lane. That cap was ours and it
reached the board as the gateway's: 15 cells of the 2026-07-28 run published no
cpu_fps because the search "was still climbing" at the point the harness gave
up. If the generator is the limit then the engine is the limit and the published
gateway number is false.
Porting was risky for one reason, so that reason is what got fixed. The intricate
part is not the transport, it is the framing - HTTP head, chunked transfer
(hex sizes, extensions, the CRLF after each chunk, the terminal chunk and its
trailers), and WHATWG SSE assembly where consecutive data lines join and a blank
line dispatches. Writing that a second time against an async socket would have
left two copies of the same rules, and the copy that drifted would produce a
plausible frame count with corrupted timings rather than an error. Nothing would
fail loudly.
So it is written ONCE, as `SseReader`: a pure state machine fed bytes, with no
socket in it. It cannot block, so the async lane drives it; it cannot await, so
the blocking lane drives it. Both lanes send identical bytes through one
`build_sse_request`. The arrival timestamp is passed in rather than read from a
clock, because every published streaming number is a timing and a test has to be
able to control when a frame is credited.
What that buys is testability where the risk actually lives. The decoder is
driven with hand-written byte sequences a live socket produces only by luck: a
chunk header split across reads, a `data:` line split across chunks, a frame
completed by the last byte before EOF. The strongest of them asserts that
fragmenting the same response at 1, 2, 3, 5, 7, 13, 64 and 500 bytes decodes
identically - the exact class of bug that would otherwise ship silently. A
differential test then drives the blocking lane and the tokio lane against one
peer that streams in awkward pieces and asserts identical status, frames, end
reason and frame count.
Measured after: 8192 lanes, zero errored streams, all 524288 frames delivered.
The old superseded framing (ChunkedLineSource, SseSource) and the thread-era
STREAM_LANE_STACK are deleted rather than left beside their replacement, and the
stream clamp and its "this ceiling is ours" relabelling go with them - honest
labelling was right while the ceiling was real; removing the ceiling is better.
400 tests pass.1 parent 61fa73c commit cc116bb
3 files changed
Lines changed: 654 additions & 367 deletions
0 commit comments