Skip to content

Benchmark sandboxed vs trusted function dispatch, document real numbers - #136

Merged
jimhoyd merged 1 commit into
mainfrom
claude/perf-benchmark-trusted-vs-sandboxed
Sep 19, 2026
Merged

jimhoyd merged 1 commit into
mainfrom
claude/perf-benchmark-trusted-vs-sandboxed

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Why

docs/CAPACITY.md described the trusted-by-default path's concurrency model
("ordinary Node concurrency... no fixed worker-slot ceiling... bounded by
--max-in-flight") as architectural reasoning written when the trust model
shipped (PR #127), never backed by an actual benchmark run. That's a gap
against this project's own stated ethos ("report actual evidence... CI
passing is not... deployment/soak proof").

What this does

  • Adds benchmarks/sandbox-vs-trusted.ts (npm run benchmark:sandbox-vs-trusted),
    following the same conventions as benchmarks/routing.ts: a private
    in-process server, a keep-alive HTTP agent, a warmup phase excluded from
    every statistic, then a measured burst. It runs the same handler source
    (a 20 ms guest/host timer, chosen to make both ceilings visible) on a
    sandbox: true route and a trusted route in the same server, at default
    settings (workers: 2, maxInFlightRequests: 64), across concurrency
    1/2/8/32/128, and records throughput (successful req/s), shed count and
    p50/p95/p99 latency at each level.
  • Runs it for real on this machine and stores the raw output at
    benchmarks/results/2026-09-19-sandbox-vs-trusted.json (new location —
    benchmarks/agent/runs/ is specifically for the agent code-generation
    benchmark per its own README, not runtime perf, so this adds a small
    sibling benchmarks/results/ with a README explaining the distinction).
  • Replaces the architecture-only assertion in docs/CAPACITY.md with a new
    "Measured: sandboxed vs trusted dispatch" section: a real comparison table
    plus prose stating plainly where each ceiling becomes visible, with
    hardware/environment caveats (CPU count, Node version, one machine's
    numbers, handler-shape caveat).

The actual run

$ npm run benchmark:sandbox-vs-trusted

Environment: Intel Xeon @ 2.10 GHz, 4 vCPUs, 16 GiB RAM, Linux x64, Node
v22.22.2, 2026-09-19.

Concurrency Sandboxed req/s (successful) Sandboxed shed Sandboxed p95 Trusted req/s (successful) Trusted shed Trusted p95
1 39 0 / 2000 26.9 ms 47 0 / 2000 21.5 ms
2 80 0 / 2000 26.5 ms 95 0 / 2000 21.7 ms
8 80 1,912 / 2000 30.2 ms 379 0 / 2000 22.1 ms
32 80 1,936 / 2000 43.5 ms 1,465 0 / 2000 23.5 ms
128 80 1,950 / 2000 70.0 ms 2,615 521 / 2000 80.6 ms

Full JSON output is in the stored run file linked above (also
docs/CAPACITY.md's new section).

What this confirms and what it doesn't

  • The sandboxed path's 2-worker ceiling is real and visible starting at
    concurrency 8 in this run (already >95% shed), flat at ~80 req/s
    regardless of how much more concurrency is offered — matches the
    documented "2 workers, no queue" model exactly.
  • The trusted path scales cleanly with no shedding up through concurrency
    32 (1,465 req/s), and only starts shedding at concurrency 128 when
    offered load exceeds the --max-in-flight admission cap (default 64,
    521/2000 shed at that level) — also matches the documented model.
  • Nothing here contradicted the existing architectural reasoning; the
    trusted path's advantage over the sandboxed 2-worker ceiling is real and
    large in this run, not smaller than predicted. I looked for evidence of
    event-loop contention limiting the trusted path more than expected and
    did not find it at these concurrency levels on this handler shape — worth
    another look with a CPU-heavier handler, which this run doesn't cover
    (its 20 ms cost is a timer, not CPU work).
  • Caveats stated in the doc: one handler shape, one 4-vCPU machine, both
    routes served from one process (so the trusted numbers include whatever
    contention comes from the sandboxed route also running), no TLS/proxy/
    production logging. Re-run on deployment hardware with a representative
    handler before sizing anything.

Verification

  • npm run typecheck — green
  • npm run lint — green
  • npm run check — green
  • npm test — 485 passed, 2 skipped (pre-existing TLS skip), 0 failed
  • npm run build — green (dist/ not committed)

🤖 Generated with Claude Code

https://claude.ai/code/session_018neC2tYKPxMPbzZf1wNctr


Generated by Claude Code

docs/CAPACITY.md asserted the trusted default's concurrency ceiling
("ordinary Node concurrency... no fixed worker-slot ceiling") as
architectural reasoning from the trust-model change (PR #127), never
backed by a measurement. Add benchmarks/sandbox-vs-trusted.ts, which
runs the same 20ms handler source on a sandbox:true route and a
trusted route in one server at concurrency 1/2/8/32/128, and use its
real output (benchmarks/results/2026-09-19-sandbox-vs-trusted.json) to
replace the assertion in docs/CAPACITY.md with a measured comparison
table.

The measurement confirms the architectural prediction: the sandboxed
path's 2-worker ceiling is already visible at concurrency 8 (>95%
shed, flat ~80 req/s regardless of further concurrency), while the
trusted path scales cleanly to 1,465 req/s at concurrency 32 with zero
shedding, only hitting its own ceiling (the --max-in-flight admission
cap, default 64) at concurrency 128.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018neC2tYKPxMPbzZf1wNctr
@jimhoyd
jimhoyd merged commit d5e8601 into main Sep 19, 2026
10 checks passed
@jimhoyd
jimhoyd deleted the claude/perf-benchmark-trusted-vs-sandboxed branch September 19, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants