On this page
At 8:59, one warm GPU handles traffic with zero queue. At 9:00, a morning traffic wave sends 100 requests in a single burst: queue age spikes, first-token latency blows past interactive budgets, and reactive autoscaling finishes booting replacement GPU pods minutes after callers time out. Meanwhile, every finished request returned 200 OK, hiding silent generation defects unless request telemetry records what actually reached the caller.
Unlike stateless HTTP services whose containers boot in seconds, GPU inference engines pin tens of gigabytes of weights in HBM and hold growing KV cache state across every active token stream (plus fixed recurrent state on hybrid models). Reliable fleets pair latency-aware serving and autoscaling with structured LLM telemetry and SLO alerting.
Latency SLIs: TTFT, ITL, and TPOT
Production inference tracks three complementary latency SLIs against explicit SLOs:
- Time To First Token (TTFT): arrival to first emitted token (queue wait + cold startup + prefill).
- Inter-Token Latency (ITL / TBT): individual gaps between consecutive emitted tokens, exposing tail stalls hidden by averages.
- Time Per Output Token (TPOT): for .
Measure server and client streams separately. Network buffering and speculative decoding routinely bundle multiple tokens into one Server-Sent Event (SSE): emitting 1 token at 300 ms and 3 bundled tokens at 340 ms exposes one 40 ms inter-event gap while leaving internal token gaps unknown and putting request TPOT at 40 / 3 = 13.33 ms. Align collector definitions too: vLLM Prometheus histograms log 0 s TPOT for single-token replies whereas vllm bench serve excludes them.[1]
import numpy as np
times = np.array([300.0, 340.0, 380.0, 500.0])
gaps = np.diff(times)
tpot = (times[-1] - times[0]) / (times.size - 1)
print(f"TTFT={times[0]:.1f}ms TPOT={tpot:.1f}ms p95_gap={np.percentile(gaps, 95):.1f}ms max_gap={gaps.max():.1f}ms")
# Bundled SSE events: (timestamp_ms, token_count)
events = [(300.0, 1), (340.0, 3)]
tot_toks = sum(c for _, c in events)
print(f"bundled events: event_gap={events[1][0]-events[0][0]:.1f}ms vs request_tpot={(events[-1][0]-events[0][0])/(tot_toks-1):.2f}ms")TTFT=300.0ms TPOT=66.7ms p95_gap=112.0ms max_gap=120.0ms
bundled events: event_gap=40.0ms vs request_tpot=13.33msThe GPU serving stack and worker lifecycle
Reliable serving separates two loops on incompatible clocks: a sub-second data path (gateway, concurrency cap, waiting queue, engine scheduler, GPU decode) that protects active streams by shedding excess load with 429 Retry-After, and a multi-minute control loop (Prometheus + KEDA for pods + Karpenter for GPU nodes) that provisions and warms future replicas.[2][3]
Scheduled, started, and ready are different states
Pod scheduling, image pull, weight load, kernel warmup, and readiness span minutes.[4] Misconfigured probes turn bursts into crash loops: a short startup probe kills loading pods, a premature readiness probe leaks traffic before weights load, and a liveness probe that fails when slots fill restarts healthy saturated workers (killing active streams and warm prefix caches). Return 503 while booting or draining (while letting active streams finish), 409 on duplicate request IDs, 429 when full (keeping liveness green), and 200 when admitted:
from dataclasses import dataclass, field
@dataclass
class Worker:
max_slots: int = 2
loaded: bool = False
warmed: bool = False
healthy: bool = True
draining: bool = False
active: set[str] = field(default_factory=set)
def enqueue(self, req_id: str) -> int:
if not (self.loaded and self.warmed and self.healthy) or self.draining:
return 503
if req_id in self.active:
return 409
if len(self.active) >= self.max_slots:
return 429
self.active.add(req_id)
return 200
w = Worker()
assert w.enqueue("a") == 503
w.loaded = w.warmed = True
assert (w.enqueue("a"), w.enqueue("b"), w.enqueue("b"), w.enqueue("c")) == (200, 200, 409, 429)
w.draining = True
assert w.enqueue("d") == 503
print("lifecycle verified: load/warm=503, ready=200, dup=409, full=429, drain=503")lifecycle verified: load/warm=503, ready=200, dup=409, full=429, drain=503Serving engine fundamentals
Modern engines stack three scheduling optimizations covered in earlier chapters:
- Continuous batching refills freed decode slots every iteration (lifting two-slot occupancy on replies
[8, 2, 5, 3]from69%to90%).[5] - PagedAttention and prefix caching map logical blocks onto non-contiguous physical HBM pages (bounding slack to at most
15tokens atblock_size=16, reclaiming81%of worst-case fixed buffers) and share cached prefixes across requests.[6][7] - Chunked prefill caps prompt tokens per iteration (
max_num_batched_tokens) so long prompts do not stall active decode steps; decomposing queue wait (180 ms), prefill (120 ms), and per-step decode (40, 40, 120 ms) pinpoints where tail latency grew.

| Engine | Best fit | Operational watchpoints |
|---|---|---|
| vLLM | General high-throughput serving with PagedAttention and LoRA | Align Prometheus histogram rules with client SLIs[1][8] |
| SGLang[9] | Tree-structured prefix caching (RadixAttention), multi-turn agents | Track radix pool eviction under multi-tenant traffic |
| TensorRT-LLM[10] | Maximum NVIDIA throughput (migrating to PyTorch backend) | Pin release versions across backend transitions |
| TGI[11] / llama.cpp[12] | Legacy HF stacks (maintenance mode) / edge GGUF serving | Plan TGI migration to vLLM/SGLang; validate edge batch limits |
GPU sizing, decode ceilings, and parallelism
Total VRAM sums weights, growing full-attention KV cache (), fixed recurrent state on hybrid models (e.g., Qwen3.6-27B's 48 linear-attention + 16 full-attention layers[13]), and ~15% runtime/CUDA-graph headroom. Pair VRAM sizing with Erlang-C (M/M/k) queueing math to pick replica counts for low wait probabilities:
import math, numpy as np
from scipy.special import gammaln
def budget_gb(params_b, kv_layers, kv_heads, head_dim, ctx, conc, fixed_b=0.0):
w = params_b * 2e9
kv = conc * ctx * (2 * kv_layers * kv_heads * head_dim * 2)
hyb = conc * fixed_b
return w / 1e9, kv / 1e9, hyb / 1e9, (w + kv + hyb) * 1.15 / 1e9
def erlang_c(rps, svc_s, reps, slots):
k, rho = reps * slots, rps * svc_s
u = rho / k
if u >= 1.0: return 1.0
lt = np.array([n * math.log(rho) - gammaln(n + 1) for n in range(k)])
lpk = k * math.log(rho) - gammaln(k + 1) - math.log(1.0 - u)
m = max(float(lt.max()), lpk)
return float(math.exp(lpk - m) / (np.exp(lt - m).sum() + math.exp(lpk - m)))
qwen_lin = 48 * 16 * 128 * 3 * 128 * 4
for name, res in [("8B BF16 (4k, c=8)", budget_gb(8, 32, 8, 128, 4096, 8)),
("Qwen3.6-27B (8k, c=4)", budget_gb(27, 16, 4, 256, 8192, 4, qwen_lin))]:
print(f"{name}: w={res[0]:.1f} kv={res[1]:.1f} hyb={res[2]:.1f} total={res[3]:.1f} GB -> {math.ceil(res[3]/76)} H100")
for r in (4, 5, 6):
print(f"replicas={r} (slots={r*4}): P(queue_wait)={erlang_c(1.8, 8.0, r, 4):.3f}")8B BF16 (4k, c=8): w=16.0 kv=4.3 hyb=0.0 total=23.3 GB -> 1 H100
Qwen3.6-27B (8k, c=4): w=54.0 kv=2.1 hyb=0.6 total=65.3 GB -> 1 H100
replicas=4 (slots=16): P(queue_wait)=0.591
replicas=5 (slots=20): P(queue_wait)=0.117
replicas=6 (slots=24): P(queue_wait)=0.014
For 1B to 8B models, NVIDIA MIG slices one GPU into isolated SM and memory partitions (dividing HBM bandwidth too).[14] At batch size 1, decode is weight-bandwidth bound (): on a 3,350 GB/s H100 SXM,[15] quantizing 27B weights from BF16 (54 GB) to FP8/INT8 (27 GB) doubles the ceiling from 62.0 to 124.1 tok/s. When models span GPUs, keep Tensor Parallelism (TP) inside fast NVLink nodes (two all-reduces per layer) and use Pipeline Parallelism (PP) across slower inter-node links.[16][17]

Autoscaling, warm pools, and cold-start math
Scale on queue depth, oldest queue age, and active KV pressure (vllm:num_requests_waiting, vllm:num_requests_running, vllm:kv_cache_usage_perc on 0.0..1.0) plus NVIDIA DCGM hardware health, not raw GPU utilization alone.[1] Exclude evictable unreferenced prefix-cache blocks from live KV pressure.
Compute an absolute desired target ceil((waiting + running) / slots_per_replica) that includes pending pods so repeated polls never double-count the same queue, hold desired steady if telemetry goes stale, and guard scale-down with HPA stabilizationWindowSeconds (300 s) and KEDA cooldownPeriod so warm caches are not thrashed.[18][19]
import math, numpy as npfrom scipy.stats import poisson
def step_replicas(waiting, running, ready, pending, slots, low_age_s, cooldown_s=300, fresh=True):
cur = ready + pending
if not fresh: return cur
need = max(1, math.ceil((waiting + running) / slots))
if need > cur: return need
return (cur - 1) if (need < cur and low_age_s >= cooldown_s) else cur
print("polls 0/1/2:", step_replicas(30, 20, 4, 0, 5, 0), step_replicas(30, 20, 4, 6, 5, 0), step_replicas(36, 20, 4, 6, 5, 0))
print("cooldown 299s vs 300s:", step_replicas(0, 4, 7, 0, 5, 299), step_replicas(0, 4, 7, 0, 5, 300))
# 100-req burst, 30s wait limit, 10s service, 5 slots/rep -> 4 waves (20 reqs/warm rep)
for w in (0, 1, 3, 20):
served = min(100, w * 5 * (30 // 10 + 1))
print(f"warm={w:2d}: served={served:3d} expired={100 - served:3d}")
burst_99 = int(poisson.ppf(0.99, mu=1.2 * 30))
print(f"99th-pct 30s burst={burst_99} -> min warm replicas={int(np.ceil(burst_99 / 20))}")polls 0/1/2: 10 10 12
cooldown 299s vs 300s: 7 6
warm= 0: served= 0 expired=100
warm= 1: served= 20 expired= 80
warm= 3: served= 60 expired= 40
warm=20: served=100 expired= 0
99th-pct 30s burst=51 -> min warm replicas=3
Cold GPU readiness chains four serial stages (95 s node provision + 22 s image pull + 78 s weight load + 12 s warmup = 207 s). Reactive scaling cannot rescue requests with a 30 s wait deadline: pre-warmed headroom (sized from Poisson burst quantiles and wave capacity floor(deadline / service_s) + 1), NVMe weight staging, and scheduled pre-warming ahead of known peaks (8:56 finishes 33 s early vs. 8:58 finishing 87 s late) bridge that gap.


Structured LLM telemetry, tracing, drift, and SLO alerts
Green infrastructure dashboards routinely mask broken LLM outputs: requests can return 200 OK under 500 ms TTFT while emitting hallucinated or unsafe answers.[20] Production observability layers serving-gate verdicts, OpenTelemetry GenAI traces, independent SLO alerts, and unbiased drift/sampling math over GPU metrics.
Serving-gate denominators and versioned cost attribution
Track whether substantive text reached the user (substantive_output_served) separately from a tri-state verdict (unsafe_claim_served: True, False, or None pending; never default None to safe). Across six reviewed calls where three abstained, one answered safely, and two leaked unsafe claims, request-level rate is 2/6 (33.3%) while delivered-answer risk is 2/3 (66.7%). Pair zero-violation windows with sample size and a 95% Wilson bound ((0.0000, 0.0713) for 0/50). Log raw token counters (input_tokens, cached_input_tokens, output_tokens) separately from versioned rate cards, normalizing nested versus disjoint provider schemas and rejecting impossible counts (such as negative values, or cached_input_tokens > total_input_tokens under nested schemas) loudly.
OpenTelemetry GenAI spans, data minimization, and agent loop budgets
Under W3C Trace Context and OpenTelemetry GenAI conventions,[21][22] one trace_id links spans across retrieval, model generation (gen_ai.operation.name, gen_ai.request.model), tool calls, and guardrails, tagging first_failed_stage separately from escape_stage. Keep Prometheus labels low-cardinality (putting request_id on trace spans and exemplars),[23] stamp a content-addressed SHA-256 release_id hashing weights, prompts, tool schemas, retrieval index, and container digest on every span,[24] keep raw prompt/completion capture opt-in with tight TTL,[25] and guard agent loops (whose cumulative input tokens grow quadratically as ) with repeat caps, wall-clock deadlines, and spend checks.
Independent SLO alerts, drift detection, and count-before-sampling
Attach exemplar trace_ids and release digests to alerts, and evaluate channels independently so broken latency metrics never silence confirmed safety/SLO pages; reconcile terminal events against ingress counters to catch dropped telemetry.
Track unlabeled shift with Population Stability Index (PSI) (< 0.10 stable, 0.10 to 0.25 watch, > 0.25 major shift), two-sample KS tests, and RBF-kernel on query embeddings.[26][27] Crucially, when tail sampling keeps 100% of flagged traces and probability of routine traces, raw trace percentages grossly inflate failure rates.[28] Always count total ingress and flagged events before sampling, and apply inverse-probability weighting (IPW) ( per routine trace) when estimating rates from sampled traces:
import numpy as npfrom scipy.stats import binomtest, ks_2samp
# 1. Denominator separation + 95% Wilson bound + IPW tail-sampling recovery
reviewed_unsafe, reviewed_total, served_total = 2, 6, 3
ci = binomtest(0, 50).proportion_ci(0.95, method="wilson")
kept_flagged, kept_routine, p_routine = 3, 12, 0.20
ipw_rate = kept_flagged / (kept_flagged + kept_routine / p_routine)
print(f"unsafe: {reviewed_unsafe}/{reviewed_total} reviewed ({reviewed_unsafe/reviewed_total:.1%}) vs {reviewed_unsafe}/{served_total} served ({reviewed_unsafe/served_total:.1%})")
print(f"wilson(0/50)=({ci.low:.4f}, {ci.high:.4f}) | tail-sampled naive={kept_flagged/(kept_flagged+kept_routine):.1%} vs IPW={ipw_rate:.2%}")
# 2. PSI & KS latency drift check + agent loop quadratic token growth
rng = np.random.default_rng(42)
ref_t = rng.lognormal(np.log(190.0), 0.18, 250)
cur_t = rng.lognormal(np.log(265.0), 0.25, 250)
edges = np.quantile(ref_t, np.linspace(0, 1, 11)); edges[0], edges[-1] = -np.inf, np.inf
p = np.clip(np.histogram(ref_t, bins=edges)[0] / len(ref_t), 1e-6, None)
q = np.clip(np.histogram(cur_t, bins=edges)[0] / len(cur_t), 1e-6, None)
psi = float(np.sum((q - p) * np.log(q / p)))
ks = ks_2samp(ref_t, cur_t)
loop_toks = [n * 100 + 20 * n * (n - 1) // 2 for n in (4, 8, 16)]
print(f"drift: PSI={psi:.3f}, KS={ks.statistic:.3f} | agent loop tokens (4/8/16 calls)={loop_toks}")unsafe: 2/6 reviewed (33.3%) vs 2/3 served (66.7%)
wilson(0/50)=(0.0000, 0.0713) | tail-sampled naive=20.0% vs IPW=4.76%
drift: PSI=2.218, KS=0.644 | agent loop tokens (4/8/16 calls)=[520, 1360, 4000]Spot draining, disaggregation, and multi-tenant LoRA
Layer reserved on-demand GPUs for steady baseline and warm headroom with spot instances for burst overflow. Cloud preemption windows vary sharply (AWS 120 s, Azure up to 30 s, GCP none by default with optional 120 s notice).[29][30][31] On notice, flip intake to 503, subtract cleanup reserve (20 s out of 120 s leaves 100 s), finish short streams inside budget, retry unstarted prompts, and emit an explicit interruption event for overrun streams rather than splicing text across workers.
When long-prompt bursts push unified chunked-prefill pools past TTFT (1,500 ms) or TPOT (60 ms) SLOs, evaluate prefill-decode disaggregation (Splitwise, NVIDIA Dynamo), shipping KV blocks over NVLink/RDMA.[32][33][34] Keep regional failover at request boundaries (never mid-stream). For multi-tenant customization, multi-tenant LoRA shares one resident base model across hot-swapped adapters;[35][36][37] derive tenant identity strictly from verified auth credentials (ignoring raw X-Tenant-ID headers), return 403 on revoked accounts or base mismatches, and isolate prefix caches with a per-tenant cache_salt.

def classify_spot(notice_s, cleanup_s, rem_s, streamed):
return "finish" if rem_s <= notice_s - cleanup_s else ("interrupt" if streamed else "retry")
MEMBERSHIP = {"user-eng-1": {"org-alpha"}, "user-ops-2": {"org-beta"}}
REGISTRY = {"org-alpha": ("adapter_A_v3#101", "base-v7"), "org-beta": ("adapter_B_v2#102", "base-v7")}
def resolve_lora(principal, tenant, base):
if tenant not in MEMBERSHIP.get(principal, set()) or REGISTRY.get(tenant, (None, None))[1] != base:
return 403, "", ""
adp = REGISTRY[tenant][0]
return 200, adp, f"salt:{tenant}:{adp.split('#')[1]}"
print("spot (84s/170s unstarted/170s streamed):", classify_spot(120, 20, 84, True), classify_spot(120, 20, 170, False), classify_spot(120, 20, 170, True))
print("lora (valid / spoof / wrong base):", resolve_lora("user-eng-1", "org-alpha", "base-v7")[0], resolve_lora("user-eng-1", "org-beta", "base-v7")[0], resolve_lora("user-ops-2", "org-beta", "base-v6")[0])spot (84s/170s unstarted/170s streamed): finish retry interrupt
lora (valid / spoof / wrong base): 200 403 403Three spike signatures tie these controls together:
- Queue climbs while ready replicas stay flat: Cold startup exceeds the wait deadline; hold warm headroom or pre-warm ahead of surges.
- Healthy mean TPOT with visible stalls: Inspect tail ITL and separate bundled SSE chunks from per-token decode steps.
- Retries flood full workers: Cap queue depth, propagate original request deadlines, and pace retries with
429 Retry-After.