Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Queue | Where a request waits after it has arrived and before the engine starts working on it. |
| Admission control | The decision to accept a request at all, or to refuse it straight away. |
| Utilization (ρ, “rho”) | The fraction of capacity in use. ρ = 0.9 means the system is busy 90% of the time. |
| Tail latency | The latency of the slowest requests, usually quoted as p95 or p99: the time that 95% or 99% of requests beat. |
| Metastable failure | An overload that keeps going after the load that caused it has gone, because the system is busy with work nobody wants any more. |
| Head-of-line blocking | One big job at the front of a line delaying everyone behind it. |
| SLO | Service level objective: the latency or error target you promise, such as “p95 time to first token under 1 second” (23.a). |
1. What is it?#
Three related decisions, made for every request:
QUEUEING where do requests wait, and for how long?
SCHEDULING which waiting request runs next?
ADMISSION which requests do we accept at all?This lesson is about the first and the third, and about the queue as a whole. Lesson 20.k goes deep on the second: priority, fairness and preemption policy.
Admission is the one teams leave out, and leaving it out is the direct cause of many LLM serving outages.
flowchart LR
R["Request"] --> V{"Valid and within<br/>context limit?"}
V -->|"no"| E400["400"]
V -->|"yes"| QF{"Queue full, or<br/>deadline unreachable?"}
QF -->|"yes"| E503["503 + Retry-After<br/>fail fast"]
QF -->|"no"| Q["Bounded queue<br/>priority / fair ordering"]
Q --> ADM{"Slot and KV memory<br/>free?"}
ADM -->|"not yet"| Q
ADM -->|"yes"| RUN["Running batch"]
class V,QF,ADM,Q queue
class E400,E503 warn
class RUN compute
class R neutral2. Why does it matter?#
PROBLEM Under load, latency grows without limit, and the system can stay broken
even after the load goes back to normal.
WHY Unbounded queues + client retries + no cancellation = the system spends
its capacity on work nobody will read.
OPTIMIZE Bound the queue, reject early, order deliberately, and propagate
cancellation.More production incidents come from bad queueing than from slow kernels. Tail latency lives here. A kernel that is 10% slower makes every request 10% slower; a queue with no bound makes some requests minutes slower and then takes the service down.
3. Simple analogy#
A restaurant with no limit on its waiting list.
At 8 pm, 200 people are waiting. The kitchen serves 40 an hour. The 200th person will be seated at 1 am and left hours ago, but the kitchen still cooks their meal.
The fix is not a faster kitchen. It is a door policy: “we are full, come back at 9”, said at the door, at once, instead of after a three-hour wait.
Refusing a request in 5 ms is a better experience than serving it in 90 seconds.
4. Tiny example: the collapse#
A server with 64 slots, requests arriving at random (a Poisson process), and service times that vary a lot (log-normal, mean about 1.65 s). It can finish about 64 / 1.65 ≈ 39 requests per second. We raise the arrival rate λ (“lambda”) towards that, first with an unbounded queue, then with a queue capped at 100 waiting requests.
// queue.go — what happens to latency as arrival rate approaches capacity.
package main
import (
"container/heap"
"fmt"
"math"
"math/rand"
"slices"
)
type minHeap []float64
func (h minHeap) Len() int { return len(h) }
func (h minHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h minHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
func (h *minHeap) Push(x any) { *h = append(*h, x.(float64)) }
func (h *minHeap) Pop() any { old := *h; x := old[len(old)-1]; *h = old[:len(old)-1]; return x }
// simulate: Poisson arrivals, 64 concurrent slots, log-normal service time (mean ≈ 1.65 s),
// so the system can complete about 64 / 1.65 ≈ 39 requests per second.
// maxQueue < 0 means an unbounded queue.
func simulate(arrivalRate float64, maxQueue int, simTime float64) (p50, p99 float64, rejected, completed int) {
rng := rand.New(rand.NewSource(1))
slots := make(minHeap, 64) // the time each slot becomes free
var latencies, starts []float64
queued := 0 // index of the first accepted request that has not started by "now"
for t := rng.ExpFloat64() / arrivalRate; t < simTime; t += rng.ExpFloat64() / arrivalRate {
for queued < len(starts) && starts[queued] <= t {
queued++
}
if maxQueue >= 0 && len(starts)-queued >= maxQueue {
rejected++ // queue full: fail fast instead of waiting
continue
}
start := math.Max(t, slots[0]) // FIFO: take the slot that frees first
done := start + math.Exp(rng.NormFloat64())
slots[0] = done
heap.Fix(&slots, 0)
starts = append(starts, start)
if done <= simTime {
latencies = append(latencies, done-t)
}
}
slices.Sort(latencies)
n := len(latencies)
return latencies[n/2], latencies[n*99/100], rejected, n
}
func main() {
for _, rate := range []float64{20, 30, 35, 38, 40, 45} {
p50, p99, _, done := simulate(rate, -1, 600)
fmt.Printf("λ=%3.0f unbounded: p50=%6.1fs p99=%7.1fs completed=%d\n", rate, p50, p99, done)
}
for _, rate := range []float64{40, 45} {
p50, p99, rej, done := simulate(rate, 100, 600)
fmt.Printf("λ=%3.0f bounded: p50=%6.1fs p99=%7.1fs completed=%d rejected=%d\n", rate, p50, p99, done, rej)
}
}Output (10 simulated minutes; capacity is about 39 requests per second):
λ= 20 unbounded: p50= 1.0s p99= 10.8s completed=11922
λ= 30 unbounded: p50= 1.0s p99= 10.7s completed=17955
λ= 35 unbounded: p50= 1.1s p99= 10.4s completed=20964
λ= 38 unbounded: p50= 3.2s p99= 12.6s completed=22732
λ= 40 unbounded: p50= 18.2s p99= 30.7s completed=22973
λ= 45 unbounded: p50= 49.2s p99= 88.2s completed=23000
λ= 40 bounded: p50= 3.2s p99= 12.6s completed=22777 rejected=1198
λ= 45 bounded: p50= 3.5s p99= 12.8s completed=22965 rejected=3920How to read it:
- Up to λ = 35 the queue barely exists. The p99 of about 10 s is just the slowest service times in the log-normal distribution.
- At λ = 40 and 45 the unbounded queue grows for the whole run: the median request waits 18 s and then 49 s, and it keeps getting worse the longer the run lasts.
- With a bound, the server finishes almost exactly as many requests, but the ones it accepts keep a 3 s median. The rest (about 5% at λ = 40, about 15% at λ = 45) get a fast refusal they can act on.
Bounding the queue does not reduce throughput. It turns unusable latency into an honest rejection.
5. Technical explanation#
Where LLM requests queue#
1. Gateway or router queue (flow control in front of the replicas, 21.i)
2. TCP accept backlog (the kernel)
3. API server (asyncio tasks waiting on the engine)
4. Engine waiting queue (the scheduler) ← where time to first token is decided
5. Inside a step (prefills competing for the token budget, 17.b)The engine’s waiting queue (4) is where requests sit when all slots or all KV cache blocks are taken. By default vLLM’s queue is unbounded. Since v0.29 it has two opt-in valves, both checked in the API server and both answering with HTTP 503:
| Flag | Bounds | Use it as |
|---|---|---|
--max-num-queued-reqs | Requests in flight (waiting + running) | A coarse cap: about max_num_seqs × data-parallel size, plus the queue depth you accept |
--max-num-queued-tokens | Prompt tokens still waiting for prefill | A time-to-first-token guard: target TTFT × prefill throughput |
The second is mechanism B below, built in. Its count is conservative (it does not know about prefix-cache hits until prefill ends), so it rejects slightly early, which is the safe side.
A fleet also needs a bound in front of the replicas (1), so that a request waits centrally and goes to whichever replica frees first, instead of piling up inside one. llm-d 1.0 (October 2026) added flow control to its router: priority- and fairness-aware queues with controlled load shedding.
Bounding: three mechanisms#
A. QUEUE LENGTH LIMIT
if waiting > max_waiting: reject with 503
Simple, but length is a poor stand-in for wait time when request costs vary.
B. ESTIMATED WAIT TIME (better)
estimated_wait = queued_work_tokens / current_token_throughput
if estimated_wait > SLO: reject
Needs a guess at output length. Even a crude one (max_tokens, or the tenant's
usual length) beats a length limit.
C. DEADLINE PROPAGATION (best, when clients cooperate)
The client sends a deadline. The server refuses if it cannot meet it, and drops
queued requests whose deadline has passed.
gRPC carries deadlines natively; over HTTP, use a header.Use B at least. A queue of 50 short chat turns and a queue of 50 requests with 100,000-token prompts are completely different situations, and A cannot tell them apart.
Admission needs a cost model#
estimated_cost(request) =
prompt_tokens_not_cached × prefill_cost_per_token
+ expected_output_tokens × decode_cost_per_token
+ kv_blocks_needed × how long they will be held
expected_output_tokens ≈ min(max_tokens, this tenant's usual p80 output length)You do not need precision. You need to tell “cheap” from “will hold a slot for four minutes”. The prefix cache matters here: a 20,000-token prompt that is 95% cached costs about as much prefill as a 1,000-token one (12.m).
Ordering the queue#
Once requests wait, something chooses which goes next. The policies (first come first served, priority classes with aging, weighted fair queueing between tenants, shortest-job-first, earliest deadline first) and the trade-offs between them are lesson 20.k. The short version: first come first served inside two or three priority classes, aging so nobody starves, and fair shares between tenants (21.f).
Head-of-line blocking and chunked prefill#
One 32,000-token prefill would hold the GPU for about half a second, and every streaming user would see a half-second freeze. Chunked prefill (12.k) splits it into pieces that share each step with the decodes, so the freeze becomes a small, steady slowdown. It is always on in current vLLM; its size is set by the token budget (17.b, 20.d).
When memory runs out mid-flight#
Admission is optimistic: the engine cannot know how long an answer will be. If running requests grow until the KV cache is full, one of them is preempted: its blocks are freed and it is recomputed later. vLLM always recomputes; it no longer swaps KV to CPU memory (17.c). Who is chosen, and what it costs, is in 20.k. For admission the lesson is simple: a high preemption rate means you admitted too much.
6. Under the hood: the metrics that matter#
queue depth requests waiting
queue wait time (histogram) THE tail-latency signal
admission rejections by reason: queue full, over quota, too long
preemptions how often admission was too optimistic
running batch size actual concurrency
KV cache usage the capacity signal
time to first token (histogram) split by prompt lengthIn vLLM these are vllm:num_requests_waiting, vllm:request_queue_time_seconds,
vllm:num_preemptions, vllm:num_requests_running, vllm:kv_cache_usage_perc and
vllm:time_to_first_token_seconds (19.c). vllm:num_requests_waiting_by_reason separates
requests waiting for capacity from those deferred (waiting for a grammar, remote KV or a
LoRA slot).
Queue time separated from prefill time is the most useful pair of numbers in LLM serving. With both, “time to first token is bad” becomes either “we are overloaded” (queue time) or “prefill got slower” (prefill time). Those have completely different fixes.
7. Performance implications#
The queueing rule of thumb from 2.c:
W_queue ≈ W_service × ρ / (1 − ρ)
ρ = 0.70 → wait ≈ 2.3 × the service time
ρ = 0.90 → wait ≈ 9 ×
ρ = 0.95 → wait ≈ 19 ×The table in section 4 shows the same curve: flat until about 90% of capacity, then a wall.
- Aim for 60–75% utilization for latency-sensitive services. Batch services can run hotter.
- Variance makes it worse. The formula assumes fairly regular jobs; LLM requests vary by a factor of 1,000, so the knee comes earlier.
- Find your knee by load testing, not by formula: raise the arrival rate and watch where p99 time to first token turns upwards (22.g).
8. Production implications#
- Always bound the queue, by estimated wait, not just length.
- Reject fast with 503 and
Retry-After. Use 429 only for “this tenant is over quota”. - Put the bound in front of the engine, in the router or API layer.
- Separate priority classes for interactive and batch traffic (20.k).
- Propagate cancellation when a client disconnects (12.p, 20.e).
- Alert on p95 queue wait, not on queue depth.
- Load-test past capacity to find the knee and to check that rejection happens cleanly.
9. Common mistakes#
- Unbounded queues. The root cause of metastable collapse.
- Rejecting late instead of early. A refusal after 60 seconds of waiting is worse than an answer and worse than a quick refusal.
- Queue length as the admission signal when request costs differ by 1,000×.
- No priority classes. A batch job starves interactive users.
- No cancellation. The server keeps serving abandoned work.
- Targeting 95% utilization while promising a latency SLO.
- Alerting on queue depth rather than wait time.
10. Hands-on exercise#
A. Reproduce the collapse. Run queue.go. Lengthen the run to 1,200 s and watch the
unbounded p50 at λ = 45 grow. Try a bound of 20 instead of 100: what happens to rejections and
to p99?
B. Estimated-wait admission. Change the simulator so each request has a known cost, and reject when the estimated wait exceeds 5 s instead of when the queue holds 100. Compare rejection rate and p99 on a heavy-tailed workload.
C. Head-of-line blocking. On a real server, start 8 streaming requests, then send one with a
32,000-token prompt. Plot the streams’ inter-token latency over time. Repeat with
--max-num-batched-tokens 1024, then 16384.
D. Find your knee. Load-test a real server at rising arrival rates. Plot p50 and p99 time to first token against arrival rate. Where does p99 turn up? That is your operating limit.
E. The built-in valve. Restart the same server with --max-num-queued-tokens set to your
TTFT target × measured prefill throughput. Repeat D past the knee. Count the 503s, and compare
p99 time to first token of the requests that were accepted.
11. Interview questions#
- Why does bounding the queue not reduce throughput?
- What is wrong with queue length as an admission signal for LLM serving?
- Explain head-of-line blocking in LLM serving and its fix.
- What is a metastable failure, and how does queueing cause one?
- Which two metrics tell “overloaded” apart from “prefill got slower”?
- Why target 70% utilization rather than 95%?
- Design admission control for a multi-tenant LLM service.
- Your engine has no queue limit. Where would you put one, and why there?
12. Further reading#
Checked on 12 November 2026.
- [FUNDAMENTAL] Google SRE Book: Handling Overload and Addressing Cascading Failures
- [FUNDAMENTAL] Bronson et al., “Metastable Failures in Distributed Systems” (HotOS 2021)
- [ESTABLISHED] Agrawal et al., “Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Serve” (OSDI 2024) — chunked prefill as a scheduling tool
- [REFERENCE] llm-d v1.0.0 release notes — flow control with priority, fairness and load shedding
- [REFERENCE] vLLM engine arguments —
--max-num-queued-reqs,--max-num-queued-tokens,--scheduling-policy - [REFERENCE] gRPC deadlines