Mental model
High-throughput LLM inference stability depends on two cleanly separated control planes: iteration-level continuous batching inside the GPU engine scheduler packs newly arrived prefills alongside ongoing autoregressive decode steps on every transformer iteration cleanly (~10–35 ms tick) rather than leaving completed slots idle, while upstream admission control governs which waiting requests enter the active worker queue at all based on KV-cache free-block watermarks, caller SLA deadline feasibility, and multi-tenant fair-share limits so sudden bursts shed cleanly (429/503) rather than causing GPU preemption storms.
Learning outcomes
- Contrast static request-level batching cleanly against iteration-level continuous batching and Chunked Prefill (
max_num_batched_tokens). - Explain why upstream admission control (
fairness,deadline shedding,free KV watermarks) protects GPU workers differently from per-step step packing inside the scheduler. - Tune
max_num_batched_tokens, preemption watermarks, and priority queues so heavy32Kprefills never stall interactive streamingTPOTdecodes. - Distinguish graceful
HTTP 429/503backpressure shedding metrics cleanly from GPU runtime OOM failures.
Theory
Traditional static batching forces a crisp 30-token short answer to remain trapped consuming GPU slots and KV VRAM waiting idly until the slowest 2,000-token essay in the same batch finally hits EOS, crashing GPU utilization below 30%. Continuous iteration-level batching (vLLM, SGLang, TensorRT-LLM) runs the scheduler on every single forward iteration: finished sequences release their PagedAttention KV blocks cleanly right after emitting EOS, allowing newly waiting requests to pack straight into the very next forward step alongside surviving decode streams! However, unconstrained continuous batching introduces severe decode stalling and KV-cache thrashing without four tight coordinating guards:
| Control Lever | Owner Layer | Operational Mechanism | Outage Pattern Prevented |
|---|---|---|---|
| Deadline Feasibility Gate | Gateway / Admission | Compare estimated_queue_wait + TTFT against caller SLA timeout before enqueuing work | Burning Tensor Core FLOPs on zombie prompts whose caller already aborted |
Chunked Prefill (max_num_batched_tokens) | Inference Step Scheduler | Slice huge 24K prefills into bounded 512–2048 token slices interleaved alongside decode steps | Multi-second TTFT-induced TPOT hiccups freezing live streaming tokens across active users |
| KV-Cache Free-Block Watermark | Allocator + Admission | Freeze new admissions cleanly once free physical HBM blocks drop below safety reserve (e.g., 15%–20%) | Cascading mid-decode KV preemption/swap storms forcing repeated prompt recomputes |
| Tenant Concurrency & Priority Fair-Share | Admission Queue | Assign interactive chat streams priority classes (HIGH) + strict per-tenant concurrent caps above batch workers | Heavy overnight summarization floods starving real-time copilot UX |
Preventing KV Preemption Thrashing vs. Prefill-Induced Decode Jitter
Without Chunked Prefill, admitting a single 32,000-token RAG request cleanly saturates H100 Tensor Cores for ~600–1,200 ms, stalling every active streaming chat user (20 ms TPOT suddenly freezes over 1 full second!). Slicing long prefills cleanly into bounded max_num_batched_tokens=2048 budgets lets interactive TPOT streams advance smoothly alongside large RAG ingestion! Equally important, reserving free KV watermark capacity avoids letting active decodes expand past physical VRAM cleanly—triggering expensive mid-stream sequence preemption (evicting half-completed KV tensors and paying prefill again later), which collapses cluster goodput rapidly right during peak demand!
pythonfrom dataclasses import dataclass@dataclass(frozen=True)class SchedulerSnapshot:free_kv_blocks: intmin_watermark_blocks: intestimated_wait_ms: floatactive_tenant_streams: dict[str, int]def admit_request(snap: SchedulerSnapshot,tenant_id: str,estimated_prompt_blocks: int,caller_deadline_ms: float,max_tenant_concurrency: int = 8,) -> tuple[bool, str]:"""Admission gate isolating GPUs from tenant floods, zombie timeouts, and KV cliffs."""if snap.active_tenant_streams.get(tenant_id, 0) >= max_tenant_concurrency:return False, "http_429_tenant_fairshare_exceeded"if snap.estimated_wait_ms > 0.75 * caller_deadline_ms:return False, "http_503_deadline_shed_before_work"if (snap.free_kv_blocks - estimated_prompt_blocks) < snap.min_watermark_blocks:return False, "http_503_kv_watermark_backpressure"return True, "admitted_to_priority_queue"
Alternatives and trade-offs
- Continuous Batching + Chunked Prefill + Priority Admission Control: Maximizes single-cluster throughput (
tokens/s/USD) while maintaining consistent low-jitter interactiveTPOTand blocking preemption spirals during spikes; demands explicit instrumentation ofqueue_wait_ms,num_preemptions, and tenant concurrency quotas alongside clean client429/503backoff handlers. - Separate Physically Disaggregated Interactive vs. Batch Clusters (or Prefill vs. Decode Nodes): Guarantees
100%isolation between latency-sensitive customer streams and giant batch jobs without subtle watermark races, though lowers baseline off-peak hardware consolidation compared to hybrid priority scheduling on one shared cluster cleanly. - Unbounded FCFS Continuous Batching: Delivers great throughput metrics in homogeneous single-user microbenchmarks cleanly, while collapsing unpredictably in production whenever long prompts and bursty tenants mix.
Failure modes and misconceptions
- Running Unbounded First-Come First-Served Queues Across Mixed Traffic Classes: Mixing heavy background document pipelines directly into one un-prioritized queue lets batch floods degrade live UI
TTFTinto tens of seconds cleanly. - Omitting
Chunked Prefillon Long-Context RAG Workloads: Allowing massive incoming prefills cleanly to monopolize a forward iteration stalls active streaming decodes noticeably whenever enterprise users paste large documents. - Admitting Requests Right Until Zero Free KV Blocks Remain: Omitting a free-block admission watermark forces mid-decode sequence evictions (
preemptions), doubling compute wasted on repeated prompt re-prefilling right at traffic peak! - Computing Expensively on Already-Timed-Out Waiting Requests: Neglecting deadline checks and client disconnect checks on queued prompts processes expired HTTP/RPC requests completely only to throw answers onto closed sockets.
Decision scenario
Your production vLLM inference cluster serves both live streaming IDE completions (TTFT < 1.0 s, TPOT < 25 ms) and overnight enterprise contract classification bursts (32K documents). Configure dedicated priority lanes cleanly at the gateway protecting interactive tenant fairness (max_tenant_concurrency), enable Chunked Prefill (max_num_batched_tokens = 2048) so large prefills never stall interactive decode ticks, set free-block admission watermarks reserving 20% KV capacity against mid-stream preemptions, drop requests whose estimated_wait_ms breaches 75% of caller SLA cleanly upfront (503 + Retry-After), and track intentional shedding separately from GPU crashes cleanly in Prometheus alerts.
Trade-offs
Coordinating upstream priority/deadline/watermark admission control with continuous iteration-level chunked batching keeps GPU Tensor Cores saturated near optimal throughput without sacrificing smooth user streaming latency or sliding into metastable preemption collapse during unexpected surges.