Skip to content

Bring the gateway benchmarks back into the build - #17

Merged
juicycleff merged 1 commit into
mainfrom
fix/gateway-benchmarks
Nov 10, 2026
Merged

juicycleff merged 1 commit into
mainfrom
fix/gateway-benchmarks

Conversation

@juicycleff

Copy link
Copy Markdown
Contributor

benches/gateway_benchmarks.rs has never run. It sat at the workspace root, and the root Cargo.toml is a virtual manifest with no package to own it, so cargo never saw it. It had also drifted from the middleware API and wouldn't have compiled.

It now lives in crates/octopus-middleware/benches/ with a [[bench]] entry and criterion as a dev-dependency. make bench-criterion (what the CI Benchmarks job runs) picks it up next to the farp bench, since that target already builds every benches/ target. You can run it on its own with:

cargo bench -p octopus-middleware --bench gateway_benchmarks

What changed in the bench

The groups are the same ones (JWT, rate limiting, compression at three sizes, the full stack), plus a handler-only baseline. Three of the originals would have timed the wrong thing even once they compiled:

  • The rate limit quota was 10,000/s. Criterion runs millions of iterations a second, so the quota ran dry almost immediately and the rest would have timed 429s. The quota is now out of reach so every check stays on the allow path.
  • Compression put the payload in the request body. The middleware compresses responses, and only text-like ones over 1 KB, so it measured nothing. The handler now returns the payload as text/plain.
  • The full stack signed its token with one secret and validated with another, which means 401s.

Each group now sends one request before timing and asserts a 200 (and Content-Encoding: gzip for the compression sizes), so a broken setup fails loudly.

Numbers

From make bench-criterion on an Apple Silicon Mac, fat LTO:

Group Time per request
Handler only 217 ns
Rate limit check 320 ns
JWT validation 1.71 µs
Gzip 1 KB / 10 KB / 100 KB 7.4 µs / 14.9 µs / 91.7 µs
JWT + rate limit + gzip 4 KB 11.6 µs

The whole make target took about four minutes there, and the biggest process peaked at 4.5 GB, so the Benchmarks job stays well inside the runner after #16.

Checked locally

  • cargo fmt --all -- --check
  • cargo clippy -p octopus-middleware --all-targets --all-features -- -D warnings on 1.99.1 and 1.88
  • cargo test -p octopus-middleware --bench gateway_benchmarks (runs every group once)
  • make bench-criterion

benches/gateway_benchmarks.rs sat at the workspace root, and the root
Cargo.toml is a virtual manifest, so no package ever built it. It had
drifted from the middleware API too, so it wouldn't have compiled.

It now lives in octopus-middleware with a [[bench]] entry, and the
make bench-criterion target picks it up next to the farp bench.

The port also fixes what it measured. The rate limit quota ran dry in
the first few milliseconds, so most iterations would have timed 429s.
Compression put the payload in the request, but the middleware
compresses responses, so it measured nothing. The full stack signed its
token with a different secret than it checked. Every group now sends
one request first and asserts a 200 (and gzip where it should be), so
a broken setup fails instead of quietly benchmarking an error path. A
handler-only baseline gives you a floor to read the rest against.
@juicycleff
juicycleff merged commit c9c80cb into main Nov 10, 2026
28 checks passed
@juicycleff
juicycleff deleted the fix/gateway-benchmarks branch November 10, 2026 18:30
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.

1 participant