FullStack AI Hub
Studio
lesson depth
Mastery
not started · 0%

Continuous Batching and Admission Control

Coordinate dynamic batches and admission limits to protect latency, memory, fairness, and throughput.

Freshness: current•15 min read•Production Infrastructure and AI Economics

Key Learning Outcomes

  • ✓Explain the operating model behind Continuous Batching and Admission Control.
  • ✓Evaluate trade-offs and failure modes for Continuous Batching and Admission Control.
  • ✓Apply Continuous Batching and Admission Control to a production decision.
Full Technical Reference Document

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.

Priority & Tenant Fairness Gate
Deadline Feasibility Check (Wait + TTFT)
Free KV-Block Watermark Guard
Pack Chunked Prefill + Active Decode Steps
Preempt Tail or Shed Load Before Collapse
Conceptual teaching model synthesized from:vllm-v0102-scheduler,sre-book

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 heavy 32K prefills never stall interactive streaming TPOT decodes.
  • Distinguish graceful HTTP 429/503 backpressure 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 LeverOwner LayerOperational MechanismOutage Pattern Prevented
Deadline Feasibility GateGateway / AdmissionCompare estimated_queue_wait + TTFT against caller SLA timeout before enqueuing workBurning Tensor Core FLOPs on zombie prompts whose caller already aborted
Chunked Prefill (max_num_batched_tokens)Inference Step SchedulerSlice huge 24K prefills into bounded 512–2048 token slices interleaved alongside decode stepsMulti-second TTFT-induced TPOT hiccups freezing live streaming tokens across active users
KV-Cache Free-Block WatermarkAllocator + AdmissionFreeze 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-ShareAdmission QueueAssign interactive chat streams priority classes (HIGH) + strict per-tenant concurrent caps above batch workersHeavy 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!

python
from dataclasses import dataclass
​
@dataclass(frozen=True)
class SchedulerSnapshot:
free_kv_blocks: int
min_watermark_blocks: int
estimated_wait_ms: float
active_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 interactive TPOT and blocking preemption spirals during spikes; demands explicit instrumentation of queue_wait_ms, num_preemptions, and tenant concurrency quotas alongside clean client 429/503 backoff 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

  1. 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 TTFT into tens of seconds cleanly.
  2. Omitting Chunked Prefill on 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.
  3. 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!
  4. 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.
Reflect before revealing the guide

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.

Prerequisites & Related Concepts (4)

Private notes

0 words
Included In Free Course
Free · Verifiable Credential

FS-201Production LLM Engineer

Design an observable full-stack LLM product from capability validation through interfaces retrieval evaluation security and operations.

37 concepts~35h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.

Next