Benchmark AI Gateway Policy Overhead Without LLM Noise

Yilia Lin

Yilia Lin

November 30, 2026

Technology

An AI gateway performance test should answer one narrow question at a time. If a run includes a real model, a remote network, authentication, rate limits, guardrails, and logging, the result cannot tell you which component changed latency.

Use three matched paths instead: call a fast mock upstream directly, call the same upstream through the gateway with no optional policies, then enable one production policy set at a time. Keep the request body, offered rate, connection behavior, hardware, and measurement window fixed. The difference between matched runs is an estimate for that environment, not a universal product number.

This tutorial gives platform engineers a repeatable acceptance package. It is scoped to AISIX AI Gateway 1.12.1 and ordinary OpenAI-compatible HTTP requests. It does not report a new API7 benchmark, a model-quality result, or a production capacity promise.

What You Will Prove

DecisionEvidence
Can the load generator hold the requested rate?Achieved rate and generator CPU stay within the declared limit
What does the base proxy path add?Gateway-without-policy minus direct-to-mock latency at the same rate
What does the proposed policy set add?Policy run minus base-gateway run at the same rate
Does the complete application still meet its SLO?A separate run through the real model path, without attributing model time to the gateway

The success condition is not “the gateway is fast.” It is a signed-off envelope such as: at 800 requests per second with this payload and four gateway vCPUs, the policy run sustains at least 792 requests per second, produces no unexpected errors, and keeps the pre-agreed p95 delta within the team's limit.

Pin the Test Contract

Record these values before generating traffic:

gateway: product: AISIX OSS version: 1.12.1 image_digest: replace-with-tested-digest hardware: gateway_vcpu: 4 gateway_memory_mib: 4096 traffic: endpoint: /v1/chat/completions offered_rates_rps: [200, 400, 800] duration_seconds: 120 warmup_seconds: 30 connections: 64 request_body_sha256: replace-after-freezing-payload policy_profiles: - base_proxy - caller_auth - caller_auth_and_rate_limit - production_candidate acceptance: minimum_achieved_rate_ratio: 0.99 unexpected_error_rate_max: 0.001 policy_p95_delta_ms_max: 3.0

Replace every placeholder. Pin an image digest or source commit, not a moving tag. Store the exact gateway configuration and secret-free environment description with the result. If hardware, payload, policy, runtime version, or connection settings change, create a new comparison series.

AISIX 1.12.1 documentation publishes a no-policy reference benchmark using four pinned vCPUs, a near-zero-latency mock upstream, and a roughly 1,000-token request. That benchmark is useful for understanding the method and sizing order of magnitude. It is not the baseline for your environment, and its no-policy rows do not establish the cost of authentication, limits, guardrails, caching, or logging.

Build Three Comparable Paths

Use one deterministic mock that returns the same status, headers, and body shape for every request. Run the mock, gateway, and load generator on isolated CPU resources when possible.

Path D: load generator -> mock upstream Path G: load generator -> AISIX base proxy -> mock upstream Path P: load generator -> AISIX production policy -> mock upstream Path M: load generator -> AISIX production policy -> real model

Path D detects network and mock cost. Path G adds the base gateway. Path P adds the proposed policy. Path M validates the user-facing system but is not used to calculate gateway-only overhead because model queueing and generation dominate and vary between calls.

Use the same DNS resolution, HTTP version, TLS choice, connection reuse, request body, response body, duration, and offered rate for D, G, and P. If the direct path uses plain HTTP while the gateway path terminates TLS, label the result as a combined TLS-plus-gateway delta.

Freeze a Representative Request

Use a valid request that resembles production size without containing customer data:

{ "model": "benchmark-alias", "messages": [ {"role": "system", "content": "Classify the synthetic support case. Return JSON only."}, {"role": "user", "content": "Synthetic case 1042: delivery status is unknown."} ], "stream": false, "temperature": 0 }

Hash the final file with shasum -a 256 request.json. Do not silently replace a short request with a much larger prompt between runs. AISIX holds request data while an upstream call is pending, and request size can change CPU and memory behavior.

For streaming, create a separate series. Measure time to response headers, time to first content event, total duration, completion rate, and client-visible truncation. Do not mix a non-streaming p95 with a streaming time-to-first-token percentile.

Run a Rate Sweep, Not One Saturation Point

Start below expected production load and increase the offered rate in steps. A constant-rate tool such as wrk2, vegeta, or k6 can work, but record its version and verify that it actually delivered the requested rate.

For each rate:

  1. Warm the mock and gateway for 30 seconds without recording results.
  2. Run D, G, and P for the same 120-second window.
  3. Record offered requests, completed requests, status classes, connection errors, generator CPU, gateway CPU and memory, and p50/p95/p99 latency.
  4. Repeat the triplet at least three times in alternating order, such as D-G-P, P-G-D, then G-D-P.
  5. Stop increasing load when the achieved-rate ratio fails, errors exceed the limit, or latency rises sharply.

Alternating the order reduces the chance that a noisy host or warming effect always favors one path. Repeats are independent observations; do not merge raw percentile tables and calculate a percentile of percentiles.

Calculate Only Matched Deltas

For a single repeated triplet at one rate:

base_proxy_p95_delta = gateway_base_p95 - direct_mock_p95 policy_p95_delta = gateway_policy_p95 - gateway_base_p95

Subtract only matched runs. If the offered rate was 800 requests per second but one path achieved 610, do not compare its p95 with a path that achieved 798. The slower path was tested at a different effective load.

RunOffered rpsAchieved rpsErrorsp50 msp95 msp99 msGateway CPU
D-1 direct mock800fillfillfillfillfilln/a
G-1 base gateway800fillfillfillfillfillfill
P-1 policy gateway800fillfillfillfillfillfill

Publish the table with blanks until the run happens. A blank is more useful than an invented zero.

Attribute Policies by Controlled Addition

ProfileChange from previous profileExtra validation
Base proxyNoneRoute and response contract
Caller authValidate caller key and model accessValid, missing, and denied key
Rate limitAdd the proposed request/token/concurrency rulesBelow-limit and rejected requests
GuardrailAdd the exact input/output modeAllowed, blocked, detector timeout, fail-open/closed
Logging/exportAdd the production sink and fieldsSink healthy, slow, and unavailable

The latency delta is only half the acceptance result. A fast authentication profile that accepts an invalid key fails. A fast guardrail profile that silently bypasses inspection on the tested endpoint also fails. Record functional assertions beside performance measurements.

Validate the Real Model Path Separately

After the policy profile passes against the mock, run the same application request through the intended provider or private model. This run answers whether the complete system meets its user SLO. It does not isolate gateway overhead.

Capture provider region, model identifier, streaming mode, output-token limit, retry and fallback settings, and time of observation. For private vLLM, SGLang, or Ollama targets, also record replica count, model revision, accelerator type, batching settings, and queue depth.

A fallback success can hide the first target's failure and add another billable attempt. A cache hit can skip the model entirely. Segment those outcomes instead of averaging them into one latency number.

Diagnose Invalid Results

SymptomLikely problemCorrective action
Achieved rate is below 99% of offered rateGenerator, network, mock, or gateway saturatedLower rate; inspect every component before attributing the limit
Direct path slows during gateway runsShared CPU or network interferenceIsolate resources or alternate run order
p99 changes while p50 stays flatQueueing, connection churn, pauses, or a small error classInspect time series and error cohorts
Policy run returns fewer bytesRejections, buffering, truncation, or a different response pathCompare status, body contract, and stream completion
Real model result is much slowerProvider/model work dominatesKeep it in the end-to-end report
Repeated runs driftHost noise, autoscaling, cache state, or changing upstreamFreeze state and report the spread

Reader Acceptance Checklist

  • The gateway version, image digest or commit, configuration hash, and hardware are recorded.
  • Direct, base-gateway, and policy runs use the same frozen payload and effective rate.
  • The mock is faster than the gateway path and does not saturate first.
  • Offered and achieved rates, errors, percentiles, CPU, memory, and response bytes are retained.
  • Every enabled policy has a functional positive and negative assertion.
  • Streaming, cache hits, retries, fallback, and real-model calls are segmented when present.
  • The report distinguishes observed results from published vendor reference data.
  • Capacity and SLO decisions include headroom and are limited to the tested environment.

Turn the Result into a Deployment Decision

Use the mock triplets to locate gateway and policy cost. Use the real-model path to decide whether users meet their latency and reliability SLO. Keep both reports because they answer different questions.

For the current product reference, read the AISIX performance and sizing methodology and the provider compatibility boundaries. Then run the acceptance matrix with your actual policy profile before choosing replica count or approving production traffic.

Tags:
Share article link