Bench: Std.Http.Server reference — reactor is 44x faster#4
Merged
Conversation
examples/BenchStdHttp/Main.lean serves the same three routes (/health, /json, /echo) through Lean 4.31's stock Std.Http.Server so docs/BENCHMARKS.md can show a like-for-like comparison against the reactor and nginx. Result on the M-series box, wrk t=8 c=128 15s: Std.Http.Server (stock) 1 652 RPS p99 178 ms lean-tea reactor 73 533 RPS p99 2.1 ms nginx 72 183 RPS p99 2.0 ms The 44x gap is not the codec: it's the same Std.Async.TCP hop per-syscall that capped our own libuv Server at 6 k, plus extra per-connection bookkeeping (Semaphore + Mutex + CancellationContext + full RFC-9112 streaming H1 codec). The 178 ms p99 is characteristic of semaphore/mutex contention under keep-alive load. Std.Http.Server is the *correct* implementation — full HTTP/1.1 pipelining, Expect: 100-continue, chunked streaming bodies, graceful shutdown across in-flight requests, cancellation. The reactor gives up all of that for the 44x. Both belong; pick by workload.
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.
Follow-up measurement on PR #3.
What this adds
examples/BenchStdHttp/Main.lean— same three routes (`/health`, `/json`, `/echo`) but implemented on top of Lean 4.31's stock `Std.Http.Server` (Sofia Rodrigues, 2025). Compiled as `lean_exe bench_std_http`.Result
Same wrk load, same box (M-series, 16 core), same run:
Reactor is ~44 × the throughput of the stock Std server at ~1/80 the p99 latency.
Why
Two overlapping causes:
That said: `Std.Http.Server` is the correct implementation — HTTP/1.1 pipelining, `Expect: 100-continue`, chunked streaming request bodies, graceful shutdown across in-flight requests, proper cancellation. The reactor gives up all of that for the 44×. Both belong in the framework; pick by workload. The BENCHMARKS.md prose says this.
Test plan