How to work an inference incident: the method and the simulator
A repeatable method for slow or failing LLM serving: split TTFT from inter-token latency, check demand before blaming the engine, read KV cache, queue and preemption metrics, find what changed, test one hypothesis at a time and write an incident record. Practise it on a CPU-only simulator of a vLLM-style replica.
By Sandip Maity, Applied AI Engineer
Key takeaways
- Split the latency first: TTFT is queue wait plus prefill; inter-token latency is the engine's step time. They point at different causes.
- Check demand before blaming the engine: request rate, prompt length and output length explain many incidents on their own.
- GPU utilisation and GPU memory used say almost nothing about an LLM engine. KV cache usage, waiting requests, preemptions and the prefix cache hit rate say a lot.
- Ask what changed, write hypotheses down, and test the cheapest one that can tell two of them apart.
- Mitigate first, confirm the metrics recover, then find the root cause and write the record.
Goal: learn a method for diagnosing slow or failing LLM serving, then practise it on a simulator so the four incident labs that follow feel familiar. By the end you will predict a replica's speed from its settings and check the prediction with the same commands you will use under pressure.
You need: Python 3.10 or newer, nothing else. No GPU. About 30 minutes. Background that helps: prefill, decode and the roofline, scheduling and chunked prefill and incident response.
Honest limits. The simulator is a teaching model, written for this course. It models one replica of a vLLM-style engine with simple formulas (below); its numbers are what those formulas give for one 48 GB GPU, not measurements of vLLM. Its metric names follow vLLM's, but names change between vLLM versions, so check your own /metrics page. Use the labs to practise the method, then confirm anything you learn on a real system before you act on it.
#Why incident labs
Most of an inference engineer's hard days start with a graph that got worse. Senior interviews test the same thing: "TTFT went from 400 ms to 4 seconds, what do you check?" Knowing every optimisation helps less than a calm, ordered way to go from symptom to cause. This track gives you that order and four incidents to practise it on.
#The method
flowchart TD A["1. Scope the symptom<br/>which metric, how much, since when, for whom"] --> B["2. Split the latency<br/>TTFT vs inter-token latency vs errors"] B --> C["3. Check demand<br/>request rate, prompt length, output length"] C --> D["4. Check engine state<br/>waiting, running, KV usage, preemptions, cache hits"] D --> E["5. What changed?<br/>deploys, config, templates, traffic, tenants"] E --> F["6. Write hypotheses<br/>pick the cheapest check that separates them"] F --> G["7. Mitigate and confirm<br/>roll back, shed load, fix a flag; watch recovery"] G --> H["8. Root cause and record<br/>evidence, timeline, actions"]
#Split the latency
The first move is to split one number into parts, because each part has different causes:
| Signal | What it is made of | Typical causes when it rises |
|---|---|---|
| TTFT (time to first token) | Queue wait, then the prefill of the prompt | More prompt tokens to compute (longer prompts, fewer cache hits), a saturated replica, too few sequences allowed, a small KV cache |
| Inter-token latency (ITL, time per output token) | The engine's step time while the request decodes | Bigger batches, long prefill chunks sharing the step, CUDA graphs disabled, slower hardware, KV cache read cost at long context |
| Errors | Rejected (400, 429), timed out or crashed requests | Prompt longer than max_model_len, admission limits, client timeouts, out-of-memory, bad nodes |
If TTFT rose and ITL did not, steps are not slower. The extra time is spent before the first token: queueing or prefill. If ITL rose at every load, something made each step slower.
#Check demand before blaming the engine
Many "the engine got slow" incidents are "the traffic changed". Check three things: requests per second, prompt length (mean and p99) and output length. A new client sending prompts three times longer needs three times the prefill, and no engine flag fixes demand.
#Read the engine, not the GPU
Two of the most watched numbers are nearly useless here. GPU utilisation from nvidia-smi is the share of time any kernel is running; a busy engine keeps one running almost all the time, at low or high load. GPU memory used is fixed at startup: vLLM takes a fixed share of the card at startup (set by gpu_memory_utilization; the default and the sizing method change between releases, so read your startup log) and turns whatever is left after weights and activations into KV cache. Look at these instead:
| Engine metric | What it tells you |
|---|---|
| Requests waiting | Demand above what the engine is running now: queueing |
| Requests running | How many sequences share each step; capped by max_num_seqs and by KV cache space |
| KV cache usage | How full the pool of KV blocks is; near 100% means admissions stall and preemptions start |
| Preemptions | Running requests evicted for lack of KV space; they must recompute later |
| Prefix cache hit rate | Share of prompt tokens found already computed; a drop means more prefill work |
| Prompt tokens computed per second | The prefill work actually done, after cache hits |
On a real vLLM server these come from the /metrics endpoint, for example curl -s localhost:8000/metrics | grep -E "num_requests|kv_cache|preempt|prefix_cache". The GPU inference metrics lesson shows how to put them on a dashboard.
Utilisation 80% · chance of waiting 46% · mean wait 1.14 s
M/M/c queue (Erlang C): random arrivals, c identical servers. Waiting time stays small until utilisation passes about 70 to 85%, then climbs steeply. Real LLM servers batch, but the shape holds.
#What changed, then hypotheses
Ask what changed: deploys, engine arguments, prompt templates, model versions, node images, client SDKs, new tenants. Then write two to four hypotheses on paper. For each, name the one observation that would rule it in or out, and run the cheapest check first. Changing several things at once during an incident makes the evidence useless.
#Mitigate, confirm, then explain
Protect users first: roll back, shed low-priority load, scale out or revert a flag. Confirm the metrics recover. Only then go deep on the root cause, and write it down.
#The simulator
The simulator is one replica of a vLLM-style engine serving a 34-billion-parameter model in FP8 (35 GB of weights) on one 48 GB GPU. It models:
- Memory at startup. Budget =
gpu_memory_utilization× 48 GB. Weights, peak activations, non-PyTorch memory and CUDA graphs come off the top; the rest becomes the KV cache, cut into blocks of 16 tokens. - A paged KV cache with prefix caching. Blocks of a shared system prompt are cached and reused while the cache has room; unused cached blocks are evicted least recently used first.
- A scheduler like vLLM's. Each step has a token budget (
max_num_batched_tokens) and a sequence limit (max_num_seqs). Running requests go first, then new ones are admitted while blocks are free. Long prompts are split into chunks (chunked prefill). When a running request needs a block and none is free, the most recently admitted request is preempted and must recompute later. - Step time from a roofline. A step takes the longer of reading the weights and the KV cache it touches, at 80% of 864 GB/s, or computing its tokens at 40% of 362 TFLOP/s, plus 3 ms of overhead (8 ms more with CUDA graphs disabled).
- Clients. Open-loop arrivals at a fixed rate, or closed-loop clients with optional timeouts and retries, plus an optional admission limit in front.
What it leaves out: attention compute during prefill, multiple GPUs, network time, tokeniser and detokeniser cost, failures. Every lab says when that matters.
Get it from the companion code repository:
git clone https://github.com/maitysandip/inference-academy-code
cd inference-academy-code/incidents
python3 incident_sim.py listThe engine is in incident_sim.py; read it whenever you like. The incidents and their causes are in scenarios.py. Do not open scenarios.py until you have written your diagnosis: it contains the answers.
| Command | What it shows | Real-world equivalent |
|---|---|---|
brief |
The page or ticket | The alert or the message from a colleague |
dashboard |
Golden signals, before and now | Your latency, traffic and GPU dashboard |
metrics |
Engine metrics, before and now | The engine's /metrics endpoint |
changes |
Recent changes | Deploy log, config repo history, change calendar |
config |
Engine arguments, before and now (changes marked *) |
The launch command or Helm values |
startup-log |
How memory was split and how big the KV cache is | The engine's startup log lines |
requests |
A sample of request logs | Access logs with token counts |
sweep |
A closed-loop concurrency sweep | A load test |
reveal |
The cause | (Your postmortem) |
Any command takes --set key=value to change an engine or workload setting in the "now" column (for example --set kv_cache_dtype=fp8), and --seed N for a different random run. That is how you test a fix.
#Warm-up: predict a healthy replica, then check
Read the brief for the warm-up scenario:
$ python3 incident_sim.py healthy brief
WARM-UP. Nothing is wrong. Before you run anything, predict the decode step time, the size of the
KV cache in tokens and the median TTFT from the engine settings (config). Then check your numbers
with dashboard, startup-log, metrics and sweep.Predict three numbers before running anything else. The settings you need: 35 GB of weights, 864 GB/s at 80% efficiency, 362 TFLOP/s at 40%, 3 ms overhead per step, 64 layers, 8 KV heads of dimension 128 in BF16, gpu_memory_utilization=0.90, 1.6 GB activations, 0.5 GB non-PyTorch, 0.6 GB CUDA graphs. Traffic: about 2,400-token prompts, of which 1,536 are one of three shared system prompts, and about 220 output tokens.
Show answers
Decode step. Every step reads the weights once: 35 GB ÷ (864 × 0.8 = 691 GB/s) = 50.6 ms. Add 3 ms of overhead and a few milliseconds of KV reads (five running requests × 2,400 tokens × 262,144 bytes ≈ 3.1 GB, so about 4.5 ms): about 58 ms per token. KV cache. 0.90 × 48 = 43.2 GB; minus 35, 1.6, 0.5 and 0.6 leaves 5.5 GB. One token of KV is 2 (K and V) × 64 × 8 × 128 × 2 bytes = 262,144 bytes, so 5.5 GB holds about 20,980 tokens, rounded down to whole blocks of 16. TTFT. If the system prompt is cached, a request computes about 870 tokens: FLOPs ≈ 0.41 s, plus a little queueing. Median prompts are a bit shorter than the mean, so expect about 400 ms.
#Check your predictions
$ python3 incident_sim.py healthy dashboard
Dashboard: Warm-up: a healthy replica
yesterday 14:00 today 14:00
Requests per second (in) 0.32 0.32
TTFT p50 406 ms 406 ms
TTFT p99 1.35 s 1.35 s
Inter-token latency p50 59 ms 59 ms
Inter-token latency p99 382 ms 382 ms
Output tokens per second 72 72
Unfinished at end of window 6 6
Errors per minute (400/429/timeout) 0.0 0.0
GPU utilisation 99% 99%
GPU memory used 43.2 / 48 GB (90%) 43.2 / 48 GB (90%)$ python3 incident_sim.py healthy startup-log
INFO Model weights took 35.00 GB
INFO Memory budget: gpu_memory_utilization=0.90 x 48 GB = 43.20 GB
INFO Peak activation memory (profiled) 1.60 GB, non-torch memory 0.50 GB, CUDA graphs 0.60 GB
INFO Available KV cache memory: 5.50 GB
INFO KV cache dtype auto: 262,144 bytes per token (2 x 64 layers x 8 KV heads x 128 x 2 bytes)
INFO GPU KV cache size: 20,976 tokens (1,311 blocks of 16)
INFO Maximum concurrency for 8,192 tokens per request: 2.56x
INFO CUDA graphs: capturedThree things to notice:
- GPU utilisation is 99% at 0.32 requests per second with about five requests running. The replica is far from full, yet the GPU looks busy. This is why the method ignores that number.
- ITL p99 is 382 ms, more than six times the median. Those are steps where a prefill chunk shares the step with decodes. Chunked prefill limits how much of a prompt joins each step, but a chunk of several hundred tokens on a 34B model still takes a few hundred milliseconds.
- The KV cache is small. 20,976 tokens is about 2.5 maximum-length requests. With these prompts it fits about 16 requests at once, because the three system prompts are stored once and shared.
Now see where the replica tops out:
$ python3 incident_sim.py healthy sweep
Closed-loop concurrency sweep: Warm-up: a healthy replica
useful = output tokens per second of requests that completed; generated = all tokens the GPU produced
clients useful tok/s generated TTFT p50 running KV used preempt/min timeouts/min 429/s
4 63 63 351 ms 4.0 36% 0.0 0.0 0.0
8 107 108 356 ms 8.0 59% 0.0 0.0 0.0
12 142 143 359 ms 12.0 78% 0.2 0.0 0.0
16 160 160 526 ms 15.2 93% 4.6 0.0 0.0
24 159 158 10.36 s 16.4 98% 12.6 0.0 0.0
32 159 158 21.46 s 16.4 98% 12.8 0.0 0.0
48 156 158 43.19 s 16.3 98% 12.9 0.0 0.0
64 158 158 63.74 s 16.3 98% 12.5 0.0 0.0
128 155 155 147.31 s 16.1 97% 11.3 0.0 0.0Throughput rises until about 16 requests are running, exactly where the KV cache fills, and then stays flat while TTFT grows without limit. Extra clients only wait. Keep this healthy shape in mind; one of the labs shows what it looks like when the curve bends down instead.
#The incident record
Every lab ends with a short written record. Use the same headings each time, so the habit carries over to real incidents:
- Summary: one sentence on what users saw and why.
- Impact: which metric, how much, for how long, for whom.
- Timeline: detection, key findings, mitigation, recovery.
- Diagnosis: each hypothesis, the check you ran and what it showed.
- Root cause: the mechanism, in two or three sentences, with the numbers that prove it.
- Fix and confirmation: what changed and the before-and-after numbers.
- Actions: what prevents it, what detects it sooner (an alert, a test, a review rule).
#What you can now do
- Split a latency problem into queueing, prefill and step time.
- Name the engine metrics that matter and the GPU metrics that mislead.
- Predict a replica's decode step time, KV cache size and TTFT from its settings.
- Drive the simulator: read a brief, compare before and now, test a fix with
--set.
#Common mistakes
- Starting with the GPU dashboard. Utilisation and memory look the same in healthy and broken states.
- Reading only the average. A p50 that barely moves can hide a p99 that went from 1 s to 30 s.
- Changing two things at once. If latency recovers, you will not know which change did it.
- Skipping "what changed". Most incidents follow a change. The change log is the cheapest evidence you have.
- Trusting one random run near saturation. Close to full capacity, small differences in arrivals make large differences in queueing. Try a second seed.
#Exercise
- Predict the decode step time with
--set enforce_eager=true(CUDA graphs off), then check it withhealthy dashboard --set enforce_eager=true. - Predict how large the KV cache becomes with
--set kv_cache_dtype=fp8, then check withstartup-log. - Run the sweep with
--set kv_cache_dtype=fp8. Where is the new knee, and why there?
Show answers
- About 8 ms more per step, so median inter-token latency rises from 59 ms to 68 ms. The CUDA graph memory (0.6 GB) is also freed, so the KV cache grows slightly. 2. FP8 stores one byte per value instead of two, so the same 5.5 GB holds 41,952 tokens, twice as many. 3. The knee moves from about 16 to about 32 running requests, because KV space was the limit, and peak throughput rises from about 160 to about 265 tokens per second. That is less than double: bigger batches read more KV cache per step and include more prefill. Past the new knee, preemptions appear and throughput dips slightly.
#Going deeper
- Incident response, game days and blameless postmortems for roles, severity levels and communication.
- Scheduling, chunked prefill and preemption for the scheduler the simulator imitates.
- vLLM for serving for how vLLM budgets GPU memory and which flags matter.
- The vLLM documentation pages on engine arguments and production metrics, for the exact names in your version.
Quick quiz
+10 XP per correct answer, +25 XP for a perfect score
1. Median TTFT tripled, but median inter-token latency did not move. Where should you look first?
2. An engine shows GPU utilisation at 99% and GPU memory at 90%. What does that tell you on its own?
3. Why write hypotheses down before running more commands?
4. During an incident, when should you look for the root cause?
Up next · 45 min · Pro, first part free
Incident lab: TTFT jumps from 400 ms to 4 s
Median time to first token went from about 400 ms to several seconds with no errors and flat traffic. Work the incident on the simulator: split TTFT from inter-token latency, rule out demand, follow the change log, prove the prefix cache stopped hitting, fix the prompt template and confirm recovery, then write the incident record.
Continue →Found this useful?
Send it to someone who is learning the same thing.