The Production Inference Optimization Loop
By Dmitri Melikyan |

A method for optimizing LLM inference on live traffic: set an objective and an SLO, measure utilization, attribute latency and throughput to their causes, change one thing, and verify it on production traffic.

This post describes a method for optimizing LLM inference on production traffic, and the measurements it depends on.

Contents

  1. Optimization in production
  2. Objective and SLO
  3. Measurement requirements
  4. Utilization
  5. Latency and throughput bottlenecks
  6. SLO violations
  7. Verifying changes
  8. Agents

Optimization in production

The right engine configuration depends on the model, the hardware and the traffic, and each of them changes on its own schedule. A new model arrives with layers that have no tuned kernel yet. Traffic drifts from short chat to long-context sessions, or output lengths grow. A configuration tuned for last month’s combination may no longer be the best one.

An offline benchmark measures one traffic shape. Production has many, and the limiting resource changes between them. Whether a change helps is decided on production traffic.

The method is a loop:

  1. Set an objective and a constraint.
  2. Measure where capacity goes unused.
  3. Attribute latency and throughput to their causes.
  4. Change one thing.
  5. Verify it on traffic as close to production as you can get.
  6. Repeat when traffic, model or hardware changes.

The examples below come from vLLM and SGLang runs on single-GPU and 2-GPU machines.

Objective and SLO

The objective is useful work per GPU, for example GPU-hours per million tokens served within the latency targets.

The constraint is the SLO: a latency target per objective, each with an allowed share of requests above it. For example:

ObjectiveTargetAllowed above
Time to first token (TTFT)1 s1%
Queue time0.5 s1%
Inter-token latency (ITL)0.1 s1%
End-to-end latency10 s1%

Three views follow from these:

  • Utilization: how much of the paid GPU time did useful work.
  • Bottlenecks: what limited latency and throughput.
  • SLO: whether the constraint held.

The loop also needs a check this method doesn’t cover: output quality. Quantization, a new kernel or a batch-dependent code path can change what the model returns. Run accuracy evaluations alongside the loop. The measurement described here records no prompts or outputs, so it can’t tell you that answers got worse.

Measurement requirements

Cross-layer correlation. A saturated host thread doesn’t show up as a host problem in a latency dashboard; it shows up as longer gaps between tokens. Requests, engine state, GPU activity and host threads have to be recorded together to connect a symptom to its cause.

Hardware and host signals. Engine metrics report requests running, KV cache usage and latency. They don’t report a GPU clocked down for power, how long kernels actually ran, or a thread waiting for a CPU. Those come from the GPU driver, a kernel profiler and the host.

Production, outside the request path. Measurement runs beside the engine, not as a proxy in front of it.

Amounts instead of ratios. A utilization percentage can’t be added across GPUs or compared across weeks. “41 GPU-hours unloaded today” can. Each loss should be an amount: GPU-seconds, tokens or requests.

Per-window attribution. A raw time series shows a symptom. The loop needs a result per window: how much capacity went unused, what the bottleneck was, how many requests missed the SLO.

Graphsignal provides this layer. One command in front of the engine launch starts a sidecar that records engine, GPU and host signals together. The platform turns them into the amounts described below, minute by minute, and shows them on the Performance page. The same numbers are available over the API for agents.

The Graphsignal Performance page with utilization, bottleneck and SLO sections, each listing amounts lost, their share and a timeline, shown on synthetic demo data

Utilization

nvidia-smi’s utilization figure is the share of a sample period in which any kernel was running. A GPU decoding one sequence at a time can read close to fully busy.

Load is better defined from the engine: a GPU is loaded when the engine has requests running. Unused capacity then comes in three kinds, counted in GPU-seconds:

  • Unloaded: nothing running.
  • Small batch: loaded, with only one or two requests running.
  • KV cache underused: loaded, the KV cache mostly empty, and no request waiting.

Small batches. At batch size one or two, each decode step streams all the weights to do a small amount of arithmetic. The step is limited by memory bandwidth and the compute units mostly wait, so more sequences per batch cost little extra per step. Persistent small-batch time means each GPU could take more concurrent requests, or the traffic could share fewer GPUs.

Underused KV cache. vLLM and SGLang reserve a fixed share of GPU memory for the KV cache at startup. If it stays mostly empty with nothing waiting, that memory is reserved and unused.

Confirming engine gauges. We saw SGLang’s running-requests gauge stay above zero after traffic stopped, so idle time looked loaded. Checking that tokens were actually being produced fixed it. A conclusion drawn from one engine gauge needs a second signal to confirm it.

Latency and throughput bottlenecks

Utilization says how much capacity went unused. It doesn’t say why requests were slow. For that, latency is broken down:

TTFT = queue wait + tokenization + prefill
ITL = GPU time per step + host time between steps + wait for the slowest GPU
decode TPS ≈ running batch / ITL

Each bottleneck below adds to one of these terms.

KV cache saturation. When the KV cache is nearly full, new requests wait for free blocks, which adds to queue time and TTFT. When the engine runs out of blocks it preempts running sequences and recomputes them later, repeating work it already did. Typical fixes: cap the number of concurrent sequences, give the KV cache more memory, or use a GPU with more of it.

Host thread saturation. Scheduling, sampling, detokenization or the Python loop can take longer than the GPU’s step. The GPU then waits between steps and ITL grows. It shows as requests running while the GPU isn’t executing, with one engine thread using a full core. CPU usage alone is misleading: some schedulers busy-poll and use a full core even when the GPU keeps up. Typical fix: move tokenization and detokenization out of the engine’s main thread or process.

CPU contention. Engine threads that wait for a CPU make step times irregular. Typical fixes: reserved or pinned cores, or fewer processes competing for the host.

GPU imbalance. Under tensor parallelism every step synchronizes, so all GPUs wait for the slowest one. A persistent gap in busy time between the busiest and least busy GPU is the signal. Typical fix: compare placement or parallelism alternatives on the same traffic, by TTFT, throughput per GPU and imbalance.

Throttling. A GPU clocked down for power or heat makes every step slower. Engine flags don’t change this; power limits and cooling do.

Queue saturation. When a meaningful share of requests waits for capacity, the engine is full. A single long wait isn’t saturation; many requests waiting is.

Network saturation. A NIC near its link rate slows everything that crosses it, such as KV transfers between prefill and decode nodes or collectives across nodes.

Bottleneck per minute

For a summary view, each minute is attributed to the first limit that applied, in this order: throttling, KV cache memory, network, host, and finally the GPU itself. The order puts the limits that can be fixed without more hardware ahead of the one that indicates more hardware is needed.

SLO violations

Violations are counted from the engine’s own latency measurements, per objective. Client-side timing includes the network and the client; the engine’s measurements isolate the serving stack.

Goodput loss estimates the tokens served too slowly to count.

Failed requests are counted by kind: rejected, errors and aborted.

Checking against ground truth. On a 2-GPU vLLM run with stepped load, the platform counted 216 failed requests, and the load generator counted 216. In the two runs in the example below, the counts matched again: 39 and 76. A measurement layer has to agree with ground truth like this before anybody changes a production configuration based on it.

Verifying changes

Change one thing at a time, so you can tell which change did what.

Verification has three levels, each stronger and more expensive than the one before:

  1. Offline check. A benchmark, or the production traffic shape replayed against a test deployment. It catches regressions, but proves little about production.
  2. Shadow or A/B. Mirror live traffic onto the candidate, or split traffic between old and new. The strongest evidence, and it needs routing infrastructure.
  3. Production windows. After rollout, compare windows with similar traffic. Every team can do this.

Use the same measurement at every level, so results can be compared across them.

A change counts as an improvement when useful work per GPU increases, the targeted bottleneck shrinks, SLO violations don’t increase, and the quality check passes. Otherwise, roll it back.

Example change: raising the concurrency cap. SGLang serving Qwen2.5-7B-Instruct on 2× H100 with tensor parallelism, on a test deployment. We sent the same load twice: 4 to 64 concurrent users over about 7.5 minutes. The first run capped running requests at 8, a limit set deliberately low for this example so it would cause a clear bottleneck. The second run raised the cap to 128. Both runs are the offline check from the list above: synthetic load on a test deployment, not production traffic. Before rolling the change out, it would still need a shadow or A/B test, or a comparison of production windows.

Cap 8Cap 128
Requests served7,45015,949
Tokens generated538K1.15M
Queue saturated242 s0 s
TTFT over 1 s4,040 (54%)39 (0.2%)
Goodput loss292K tokens2.9K tokens
GPU starved49 s163 s
Host thread saturated0 s180 s
Main bottleneckqueuehost

With a cap of 8, the engine was full by configuration: most requests queued, and over half missed the TTFT target. Raising the cap more than doubled the requests served on the same GPUs and removed nearly all violations. It also moved the bottleneck. With up to 128 requests in flight, one engine thread became saturated and the GPUs waited on the host. That is the next item for the loop. Unloaded time didn’t change, because both runs had the same idle periods between waves.

Agents

Agents can propose and apply configuration and code changes. When their feedback comes from a benchmark, they optimize for that benchmark’s traffic shape. Per-window measurements from production give them feedback on the deployment itself.

  • Engineers set the goal: the objective, the SLO and the quality bar.
  • Agents propose and apply changes, with approval or on their own.
  • The measurement layer reports the results to both.

Graphsignal is the measurement layer. It doesn’t change your stack. It measures every layer on live traffic and reports unused capacity, bottleneck time and SLO violations to the people and agents making changes.

Get started with Graphsignal.