Batching is the reason one GPU can serve fifty people at once, and also the reason your p99 sometimes looks like it belongs to a different product. The short version of LLM batching latency: every request you add to a batch makes the whole system more efficient and each individual request a little slower, and the curve is not linear. Past a knee you buy almost no extra throughput and pay for it in tail latency.
If you run a hosted API you never touch the batch size, but the same physics shows up as rate limits, slow first tokens at peak hours, and priority tiers. If you self-host, as in the vLLM serving guide, you set the knobs yourself. Either way the job is the same: choose the latency you promise, then pick the batching behavior that delivers it.
Two clocks run inside every request
A generation has a prefill phase and a decode phase, and they stress hardware differently. Prefill processes the entire prompt in parallel; it is compute-bound and its duration grows with prompt length. Decode produces one token at a time, each step reading the model weights and the KV cache from memory; it is bandwidth-bound and its per-step time barely changes with prompt length but does change with batch size.
That split gives you the vocabulary for honest SLOs:
- TTFT (time to first token) is queue wait + prefill + the first decode step. Users feel this as “is it thinking or dead?”
- ITL (inter-token latency) is the gap between streamed tokens. At 50 ms it reads like fast typing; at 200 ms it feels sluggish.
- End-to-end latency is TTFT + ITL × output tokens. For a 300-token answer at 40 ms ITL and 600 ms TTFT, that is 12.6 seconds, which is why streaming matters more than shaving 100 ms off TTFT.
Static, dynamic, and continuous batching
Early serving stacks used static batching: collect N requests, run them together, return all results when the slowest finishes. A 20-token reply sat waiting behind a 900-token one. Dynamic batching improved the collection step with a short timeout, but still ran a fixed group to completion.
Modern engines use continuous (iteration-level) batching: after every decode step, finished sequences leave and queued ones join. The scheduler re-forms the batch hundreds of times per second. The vLLM project describes this in its engine anatomy write-up, and it is the default behavior in current open-source servers. The practical effect is that short requests no longer pay for long neighbors, but every request still shares per-step time with whoever else is in the batch.
The throughput–latency curve with real shapes
The numbers below are an illustrative profile for an 8B-class model on one 80 GB GPU, not a benchmark. The shape is what matters: aggregate throughput climbs fast, flattens, and per-user speed erodes steadily.
| Concurrent requests | Per-user speed (tokens/s) | Aggregate throughput (tokens/s) | Reading |
|---|---|---|---|
| 1 | ≈ 95 | ≈ 95 | Great latency, wasted GPU |
| 8 | ≈ 80 | ≈ 640 | Sweet spot for strict interactive SLOs |
| 32 | ≈ 48 | ≈ 1,540 | Still fine for chat; ITL ≈ 21 ms |
| 64 | ≈ 28 | ≈ 1,790 | Throughput gains nearly gone; ITL ≈ 36 ms |
| 128 | ≈ 14 | ≈ 1,800 | Same throughput, double the waiting |
In this profile, going from 64 to 128 concurrent requests adds under 1% throughput while halving per-user speed. The knee near 64 is where you should set the concurrency ceiling, not the point where the GPU first reports full utilization. Find your own knee with a replayed traffic distribution rather than uniform synthetic prompts.
The long-prompt bully and chunked prefill
A single 32k-token prompt can occupy the GPU for seconds of prefill. Every decoding user in the batch stalls for that step, and ITL spikes appear in streams that had nothing to do with the big request. This is the most common cause of a “random” p99.
Chunked prefill splits a long prompt into pieces and interleaves them with decode work, trading a slightly later TTFT for the long request against steady ITL for everyone else. The vLLM tuning documentation explains how the per-step token budget controls this. Pair it with routing: send prompts above, say, 8k tokens to a replica pool of their own so interactive chat never shares a scheduler step with a book-length summarization. How long prompts form in the first place is covered in LLM context windows explained.
Write SLOs that respect batching
One latency number per endpoint hides the trade. Set objectives per route and per phase:
| Route | TTFT objective | ITL objective | Why |
|---|---|---|---|
| Interactive chat | p95 ≤ 1.0 s | p95 ≤ 50 ms | A human is watching tokens arrive |
| Autocomplete / inline suggest | p95 ≤ 300 ms | p95 ≤ 30 ms | Dies if slower than typing |
| Structured extraction (non-streamed) | n/a | n/a | End-to-end p95 ≤ 8 s for 400 output tokens |
| Nightly batch enrichment | n/a | n/a | Finish within the window; cost per 1k docs is the metric |
Notice that the last two rows ignore TTFT altogether. Offline work should be pushed into big batches at off-peak times because nobody is waiting; that is where the cheap throughput lives. Interactive work should run well below the knee. Mixing both on one replica without priorities is how a nightly job ruins Tuesday-morning chat. Convert these objectives into error budgets using the pattern in agent SLAs.
Admission control: say no early
An unbounded queue turns an overload into a latency incident for everyone. A bounded queue turns it into a clean error for a few. Put three rules in front of the engine:
- Max queue wait. If a request has waited more than 2 seconds for an interactive route, reject with HTTP 429 and
Retry-Afterrather than start it late. - Priority classes. Paid interactive traffic outranks free-tier traffic, which outranks batch. Preempt downward, never upward.
- Per-tenant concurrency caps. One customer’s script that opens 200 streams should not consume the pool; this also feeds the tenant tagging you need for cost attribution.
On hosted APIs the equivalent is client-side: respect rate-limit headers, add jittered backoff, and never retry a timeout without checking whether the original request is still running and still billing you.
Client-side habits that change perceived latency
- Stream everything a human reads. A 12-second answer that starts in 700 ms feels faster than a 6-second answer delivered whole.
- Set timeouts per phase: for example 3 s to first token, then 20 s of allowed silence between tokens, instead of one 60-second socket timeout.
- Cache what you can before the model runs. A repeated long prefix is a prompt caching candidate and cuts prefill directly.
- Limit
max_tokensto what the UI can show. Unused headroom does not cost output tokens, but a runaway answer does, and it lengthens batches for everyone.
A five-step tuning loop
- Record the real distribution of input and output token counts for one week.
- Replay it at stepped concurrency and plot aggregate throughput against p95 ITL; mark the knee.
- Set the concurrency ceiling 10–15% below the knee and the queue wait limit at about twice your TTFT objective.
- Split long-prompt and batch traffic onto their own pools or priorities.
- Re-run after every model, quantization, or prompt-length change, and alert when production p95 ITL drifts more than 20% from the load-test value. If it does, follow the diagnosis path in incident response for LLM apps.
Mistakes that look like bugs
- Judging a batch size from average latency. Means hide the 1% of requests that sit behind a prefill spike.
- Benchmarking with identical prompts, which accidentally turns on prefix cache hits and flatters TTFT.
- Raising concurrency to improve cost per token without checking whether the SLO still holds at peak.
- Treating a provider’s “fast” tier as a batching exemption. It usually means smaller effective batches and higher prices, not zero queueing.
FAQ
What is the difference between TTFT and inter-token latency?
TTFT is the delay until the first output token appears and includes queue wait and prompt prefill. Inter-token latency is the time between subsequent tokens during decoding. Chat experience depends on both, and they respond to different tuning.
Does batching increase latency?
Yes, per request, because each decode step is shared. But it increases total throughput so much that cost per token falls. The skill is stopping at the batch size where throughput gains flatten and tail latency starts climbing.
What is continuous batching in LLM inference?
Continuous batching re-forms the running batch after every decode step: finished sequences exit immediately and waiting requests join. It avoids static batching’s problem where short requests wait for the longest one in the group.
Why does one long prompt slow other users down?
Prefill for a very long prompt is compute-heavy and can occupy whole scheduler steps, delaying decode for everyone in the batch. Chunked prefill and routing long prompts to a separate pool reduce the effect.
What latency SLO should an LLM chat endpoint have?
A common starting point is p95 TTFT under about one second and p95 inter-token latency under about 50 ms, measured at the client. Adjust to your users, and set separate targets for non-streamed and batch routes.
AI Generated Apps AI Code Learning Technology
