Skip to main content

Gateway overhead benchmarks

Every number on this page was produced by Spanway's internal load driver, on the hardware named below, against a mock provider that answers instantly. The numbers are therefore the gateway's own cost, not the latency of a model call. In production the provider dominates: a real chat completion takes hundreds of milliseconds to many seconds, and the gateway's few milliseconds per request sit on top of that. Measure on your own hardware and configuration before relying on any figure here. The page tells you how.

A real-world scenario​

An architect has to tell a program board how much latency the gateway adds to a chat request. Instead of quoting a vendor number, she reads this page for the method, sends a few requests through the gateway she deployed from the published image and reads the timing headers on each response. She reports the measured pre processing and post processing time for her own hardware next to the provider's own latency, which dominates, and repeats the check after each upgrade.

What was measured​

The load driver starts three processes: a mock provider, a gateway, and the load generator.

The mock provider speaks the OpenAI chat completions and Anthropic Messages wire formats, non streaming and streaming, and replies with a fixed one word answer the moment the request arrives. Streaming responses carry 32 content chunks so the gateway's stream parsing and re-encoding is exercised. The mock runs as its own process so it never competes with the load generator for an event loop.

The gateway runs with one worker, a config file that routes bench-chat to the mock as an openai/ model and bench-messages to it as an anthropic/ model, master key authentication, STORE_MODEL_IN_DB=True and a local PostgreSQL database for spend logging. No guardrails, caching or logging callbacks are configured, so this is the floor for a gateway that tracks spend. Each feature you enable adds to it.

The load generator is a closed loop: for each concurrency level it opens that many connections and each connection sends its next request as soon as the previous one completes, for a fixed duration. Four scenarios are run at concurrency 1, 8, 32 and 128: /v1/chat/completions non streaming and streaming, and /v1/messages non streaming and streaming. Before the first measurement the gateway is warmed for 8 seconds across all four scenarios. Each gateway level runs for 10 seconds, then the same scenario at the same concurrency runs for 5 seconds directly against the mock, bypassing the gateway.

Added latency is the gateway percentile minus the direct percentile at the same concurrency, so the client's and mock's own cost at that concurrency is removed and what remains is what the gateway added. Latency is measured on the client from request start to the last byte, and for streaming also to the first byte (time to first token). Throughput counts successful responses per second. CPU is the gateway process tree's user plus system time over the measurement window, as a percentage of one core, and RSS is sampled at the end of the window, both through psutil. The load generator uses aiohttp. Run directly against the mock in the same run, it completed between about 5,700 and 21,600 non streamed requests per second at concurrency 8 and above, and more than 14,000 in all but one cell. Even the slowest direct cell was more than sixty times what the gateway sustained in the same cell, so the load generator is not the bottleneck for the gateway figures. The one outlier is Python chat completions at concurrency 32, where the direct run reached only 5,673 requests per second with a median of 3.2 ms, about twice its neighbouring cells. That cell's direct baseline was itself slowed by background load, and its gateway throughput of 90 requests per second sits below both neighbouring levels, so read its added latency with that in mind.

The whole grid is run twice, once with the gateway's default Python execution and once with SPANWAY_RUST=1, which routes /v1/messages for Anthropic models through the compiled extension. See Rust execution paths for what that switch covers. The report records whether the gateway actually answered /v1/messages with the x-spanway-rust: true header in that mode.

Hardware and software​

The run behind this page was recorded on 2026-10-17 on a pre-release development build, before 2.0.0. The gateway and the Rust extension have changed since then, so treat the figures as the shape of the overhead rather than a measurement of the 2.0.0 image, and measure your own gateway with the steps below.

MachineApple M4 Max, 14 cores (10 performance, 4 efficiency), 36 GB memory
Operating systemmacOS, Darwin 25.6.0, arm64
Python3.13.7
Gatewayone worker, master key authentication, STORE_MODEL_IN_DB=True, local PostgreSQL 18 on the same machine
Load generatoraiohttp, closed loop, same machine
Grid10 seconds per gateway level, 5 seconds per direct level, 8 seconds warmup, 32 chunks per streamed response
1 minute load averagesampled every 15 seconds during the run, between 8.5 and 41.4 with a median of 20.6, and 10.2 when the run ended

The load generator, the mock and the gateway all ran on this one machine, so they compete for cores. The machine was also busy with unrelated builds and test suites during the run, which is what the load average above shows: on 14 cores a load of 20 means the gateway's single worker was regularly waiting for a core. The two modes ran back to back, but the background load was not the same for both, so differences between them of less than about a factor of two at any one cell are noise. An earlier run on the same day under heavier load, with a load average around 30, produced per request numbers roughly half as good, which gives a sense of how much contention moves these figures. Numbers from a dedicated host with a remote load generator will be better and more stable than the ones below.

Results​

The headline figure is the first row of each table. With one request in flight, on the hardware above and against a mock upstream that answers instantly, the gateway added a median of 6.2 to 6.9 ms to a non streamed chat completion and 8.7 to 14.3 ms to a streamed chat completion or Messages call. The two non streamed /v1/messages cells at concurrency 1 came out at 18.0 and 27.3 ms, but the gateway only got 84 % and 36 % of a core during them, so they show the background load rather than the gateway. The p99 at concurrency 1 was between 23 and 131 ms, and that tail is also mostly the background load.

"Added" columns are the gateway percentile minus the direct-to-mock percentile at the same concurrency. Requests/s counts successful responses. Errors is failed over total requests. CPU is a percentage of one core for the gateway process tree, and RSS is its resident memory at the end of the window.

/v1/chat/completions, non streaming​

ModeConcurrencyRequests/sErrorsAdded p50 msAdded p95 msAdded p99 msCPU %RSS MB
Python11400/14046.212.622.992893
Python81730/173443.069.394.398905
Python32900/912331.8622.5718.764918
Python1281270/1452643.63391.54477.182874
SPANWAY_RUST=111270/12746.913.124.495928
SPANWAY_RUST=181770/177240.470.190.9101941
SPANWAY_RUST=1321770/1789160.2303.1520.098953
SPANWAY_RUST=11281900/2135513.01510.33513.399986

/v1/chat/completions, streaming​

ModeConcurrencyRequests/sErrorsAdded p50 msAdded p95 msAdded p99 msAdded TTFT p50 msCPU %RSS MB
Python1430/42914.354.9130.35.473838
Python8730/730105.9136.0143.156.098866
Python32300/3111061.31915.82361.9631.262894
Python128160/1899273.111211.011239.55295.338898
SPANWAY_RUST=11600/62912.528.233.94.697993
SPANWAY_RUST=18330/330211.8387.8400.2116.574996
SPANWAY_RUST=132390/409790.7950.51126.3461.9871061
SPANWAY_RUST=1128320/3632847.611118.311186.21309.2901066

/v1/messages, non streaming​

ModeConcurrencyRequests/sErrorsAdded p50 msAdded p95 msAdded p99 msCPU %RSS MB
Python1270/27527.389.3130.536900
Python81410/141249.392.9148.693914
Python321340/1377187.7433.9797.690917
Python1281110/1190566.03619.33719.572924
SPANWAY_RUST=11490/49518.031.543.8841070
SPANWAY_RUST=18930/93562.6174.5219.3941082
SPANWAY_RUST=1321720/1737170.7235.4525.21091096
SPANWAY_RUST=11281620/1734558.21942.93963.51081110

/v1/messages, streaming​

ModeConcurrencyRequests/sErrorsAdded p50 msAdded p95 msAdded p99 msAdded TTFT p50 msCPU %RSS MB
Python11010/10078.718.025.56.792924
Python81240/124559.989.8111.945.097931
Python321030/1070250.2496.6537.9188.796950
Python1281190/1216969.81954.83257.1211.0101972
SPANWAY_RUST=11820/81911.021.327.56.3951101
SPANWAY_RUST=181040/104272.6100.0112.432.51111101
SPANWAY_RUST=1321070/1088286.7348.9379.7118.21141110
SPANWAY_RUST=11281020/10861166.81547.01835.3238.41131139

Reading the numbers​

At concurrency 1 the added latency is the gateway's per request processing cost: authentication, routing, request and response translation, spend accounting and response headers. The gateway's own x-spanway-overhead-duration-ms header reported a median of 2.3 to 2.9 ms for most of those cells, so roughly a third of the client-observed added latency is the work the gateway times itself, and the rest is the HTTP hop, the event loop and the client side of the extra connection. The Rust path for /v1/messages does not set that header, so it gives no value for those cells.

From concurrency 8 up, the single worker is saturated, with CPU at or near one full core, and added latency is mostly queueing in front of that worker. Throughput stays between roughly 90 and 190 requests per second for non streamed calls while latency grows with the number of waiting requests. That is the expected shape for one worker. Cells where CPU drops well below 100 % at high concurrency, and where throughput falls instead of staying flat, are where the worker was starved of a core by the background load. To serve more concurrent requests, run more workers or replicas behind a load balancer, as described in production settings. At these request rates the gateway also logs that its in memory spend update queue is full and aggregates the queued entries before writing them, which is the designed behaviour and loses no spend.

The streaming scenarios complete fewer requests per second because every response is 32 chunks and each chunk is parsed, re-encoded and flushed. Streamed chat completions suffered most from the background load in this run, and their cells at concurrency 32 and 128 should not be read as a property of the gateway.

Enabling SPANWAY_RUST changes which code performs the provider call for /v1/messages, not the request pipeline around it, and /v1/chat/completions never uses the extension, so the chat completions rows for the two modes measure the same code. Their differences show the size of the run to run noise on this machine. The /v1/messages rows for the two modes are within that noise of each other. The switch is documented for what it covers, not as a throughput feature.

Each mode ran in a fresh gateway process. Resident memory was between 840 and 970 MB across the Python grid and between 930 MB and 1.14 GB across the SPANWAY_RUST=1 grid, growing slowly as the run went on in both. A single worker with the full proxy, the enterprise package and the database client loaded sits in the 800 to 900 MB range after warmup on this machine.

The overhead budget in CI​

Every pull request that changes the gateway runs the same load driver in CI and fails when the gateway gets slower than an agreed budget. That way a change that puts new work on the request path is caught before it merges, instead of being found by customers.

The CI run uses one request in flight, no database and Python execution, and adds two endpoints to the four above: /v1/responses and /v1/embeddings. For each of the six endpoints the pull request fails when the added median, the added 95th percentile or the gateway's own x-spanway-overhead-duration-ms timing is over the budget in docs/data/benchmarks/overhead_budget.json, or when any request fails. The budget is 15 ms added median, 40 ms added 95th percentile and 8 ms self timed for non streamed endpoints, and 30 ms and 60 ms added for streamed ones. It leaves room for slower shared CI machines while still catching a change that adds a blocking call. A second run repeats the grid with a trace destination that takes two seconds per record and a 500 record logging queue. It must push logging into degraded mode and still stay inside the same budget, see logging under load. The job summary prints every endpoint's measured value next to its budget, and the raw reports are attached to the run.

On the machine above on 2026-11-23, with a 1 minute load average between 3 and 4 and no database, the added median at one request in flight was 3.8 ms for chat completions, 10.0 ms streamed, 3.4 ms for Messages, 5.6 ms streamed, 3.6 ms for Responses and 2.9 ms for embeddings, and the gateway timed its own work at 1.4 to 2.0 ms. These runs skip spend logging to a database, which is why they are lower than the tables above.

To change a budget, edit overhead_budget.json in the same pull request as the change that needs it and say why in the description, so the reviewer agrees to the new cost explicitly.

Measure the overhead on your own gateway​

The tables above are measured by Spanway with an internal load driver against a mock provider. You can see the same split on your own deployment with nothing more than the published image and curl.

Use the x-spanway-timing-* response headers to see how one request's time splits between pre processing, the provider and post processing, and see Redis requirements when rate limiting and caching are on, because their latency is paid on every request.

  1. Start the gateway from the published image as described in Images, with at least one model in model_list and a virtual key in SPANWAY_API_KEY.

  2. Send one request and print the timing headers the gateway adds to every response:

    curl -sD - -o /dev/null http://localhost:4000/v1/chat/completions \
    -H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
    -d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "ping"}]}' | grep -i x-spanway-timing

    Expected result: x-spanway-timing-pre-processing-ms, x-spanway-timing-llm-api-ms and x-spanway-timing-post-processing-ms headers. The LLM API value is the provider's own time, which the gateway cannot change, and the other two are the gateway's overhead.

  3. Repeat the request a few dozen times, for example with for i in $(seq 1 50); do ... ; done, and take the median and p95 of the pre processing and post processing values.

  4. Once the gateway serves production, read p50 and p95 latency per model over real traffic from the spanway_overhead_latency_metric and spanway_request_total_latency_metric histograms on /metrics, see Prometheus metrics. The overhead metric is the number to compare with the tables above.

Errors​

SymptomMeaningFix
No x-spanway-timing-* headers in the outputThe request failed before it reached the provider, or a proxy in front of the gateway strips response headers.Check the status line printed by curl -sD -, then call the gateway directly on port 4000.
Pre processing time is far higher than the tables aboveGuardrails, rate limiting or caching against Redis run on every request, or spend logging writes to a slow Postgres.Compare with a model that has no guardrails, and see Redis requirements.
The overhead check fails on a pull requestThe change made at least one endpoint slower than its budget. The job summary names the endpoint, the metric and the measured value.Move the new work off the request path, or raise that endpoint's budget in the same pull request with the reason.
SPANWAY_RUST=1 shows no differenceExpected, the extension changes the provider call, not the pipeline, see Rust execution paths.Measure your own workload before expecting a change.

Logs​

LevelLineMeaningAction
WARNINGSpend update queue is full. Aggregating all entries in queue to concatenate entries.Under heavy load the in memory queue of spend updates reached MAX_SIZE_IN_MEMORY_QUEUE entries, so the gateway merged the queued updates into one per key before writing them.Normal at high request rates and no spend is lost. If it shows all the time, add workers or replicas, see production settings.
WARNINGBudget window spend update queue is full. Aggregating all entries in queue to concatenate entries.The same merge for the budget window counters.Same as above.