GPU capacity is expensive, slow to add, and wasted when idle. Running inference in production means deciding how much to keep warm, what signal adds more, what to do with requests while capacity arrives, and what each million tokens actually costs. This lesson covers autoscaling signals for LLM servers, why cold starts take minutes and how to shorten them, admission control and queueing, and the arithmetic of cost per token that ties all of it to a budget.
- Choose autoscaling signals that reflect LLM load: queue depth, cache use, latency
- Break a cold start into its parts and shorten each
- Design admission control so overload degrades gracefully
- Compute cost per million tokens from GPU price, throughput and utilisation
- Weigh warm capacity, scale-to-zero, reserved and spot GPUs
Scaling on the right signal
CPU and GPU utilisation are poor autoscaling signals for LLM servers: GPU utilisation reads high as soon as any work runs, and CPU is rarely the bottleneck. Scale on signals that measure unmet demand or latency risk.
| Signal | Scale out when | Notes |
|---|---|---|
| Requests waiting (queue depth) | Persistently above a small threshold per replica | Most direct measure of unmet demand |
| KV-cache usage | Sustained above roughly 85-90% | Predicts queueing and preemption |
| p95 TTFT | Approaching the SLO | Lags the cause slightly, but tracks what users feel |
| Requests running | At the configured concurrency ceiling | Replica is full |
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: chat-vllm
spec:
scaleTargetRef:
name: chat-vllm
minReplicaCount: 2
maxReplicaCount: 12
cooldownPeriod: 600
triggers:
- type: prometheus
metadata:
serverAddress: http://prometheus.monitoring.svc:9090
query: sum(vllm:num_requests_waiting{model_name="chat"})
threshold: "5"
activationThreshold: "1"Scale in slowly. A long cooldown and HPA stabilisation window prevent removing a replica that took ten minutes to start just before the next burst.
Cold starts
A new replica is useless until it can serve, and for LLMs that takes minutes. Break it down to fix it:
- Node provisioning if no free GPU node exists: often the longest step on cloud autoscaling groups.
- Image pull: inference images are large; pre-pull them on GPU nodes or use a registry mirror.
- Weight loading: tens to hundreds of GB from storage into VRAM; cache weights on node-local NVMe or stream them from a neighbouring GPU.
- Engine warm-up: compilation, CUDA graph capture and memory profiling; reuse compile caches.
- Readiness: only after the engine answers health checks should traffic arrive.
- Keep warm capacity for the latency-sensitive path: a minimum replica count, and spare GPU nodes so provisioning is not on the critical path.
- Scale-to-zero suits dev, batch and rarely used models where a multi-minute first response is acceptable, not interactive production chat.
- Set readiness and startup probes with generous initial delays so Kubernetes does not kill a replica that is still loading weights.
Admission control and queueing
Capacity always arrives later than demand, so decide what happens in the gap. An unbounded queue turns a short spike into minutes of terrible latency for everyone. Better: cap the queue per replica (or per tenant), reject excess requests quickly with HTTP 429 and a Retry-After header, and let clients back off and retry with jitter.
- Give interactive traffic priority over batch, or run batch on separate capacity entirely.
- Apply per-tenant rate limits and token budgets at the gateway so one customer cannot exhaust shared capacity.
- Set request timeouts end to end so abandoned requests stop consuming GPU time; engines cancel generation when the client disconnects.
- Shed load before the cache fills: once preemption starts, everyone gets slower.
Cost per million tokens
cost per 1M tokens = GPU cost per hour / (tokens per hour / 1,000,000)
GPU at $4.00/hour, sustaining 2,500 output tokens/s at your latency target:
tokens/hour = 2,500 x 3,600 = 9,000,000
at 100% busy: $4.00 / 9 = $0.44 per 1M output tokens
at 40% average utilisation: $0.44 / 0.4 = $1.11 per 1M output tokensTwo levers dominate. Throughput per GPU at your latency target (goodput, not peak), raised by batching, quantization, prefix caching and the right engine. Average utilisation, raised by autoscaling well, sharing GPUs across models, and filling quiet hours with batch work. A deployment that is twice as fast but idle 80% of the time can cost more than a slower, busy one.
- Account for input tokens too: prefill is cheaper per token than decode but not free, and long-prompt workloads spend much of their GPU time there.
- Reserved or committed GPUs lower the hourly price for the always-on floor; on-demand covers peaks; spot or preemptible GPUs suit batch jobs that tolerate interruption.
- Compare against hosted APIs honestly: include engineering time, idle capacity and on-call, not just GPU-hours.