Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Autoscaling | Adding or removing replicas automatically as load changes. |
| Cold start | Everything a new replica must do before it can serve: get a machine, pull the image, load weights, compile, warm up. Minutes for an LLM. |
| HPA | Kubernetes’ Horizontal Pod Autoscaler: the built-in controller that changes a deployment’s replica count from a metric. |
| KEDA | Kubernetes Event-Driven Autoscaling: an add-on that feeds the HPA from sources such as Prometheus queries, queues and schedules. |
| Headroom | Capacity you run beyond current demand, on purpose, to absorb what arrives before new replicas are ready. |
| Stabilization window | How long the autoscaler waits for a metric to stay high (or low) before acting on it. |
| Draining | Stopping new requests to a replica and letting its in-flight ones finish before it shuts down. |
1. Problem → Why → Optimization#
PROBLEM Standard autoscaling does not work for LLM serving: the usual signal is wrong,
and the reaction is 10–100× too slow.
WHY GPU utilization is high whenever anything runs, so it says nothing about
saturation. And a new replica takes minutes, because tens of gigabytes of
weights must be fetched and loaded, and kernels compiled.
OPTIMIZE Scale on queue time and KV cache use; make cold starts short; and keep
headroom, because no reactive scaler can catch a spike shorter than a
cold start.This lesson is the mechanism. Lesson 23.d turns it into a production policy, and 19.e applies it to vLLM on Kubernetes.
Facts checked on 12 November 2026.
2. Why the standard approach fails#
ORDINARY WEB SERVICE LLM SERVICE
scale on CPU % (meaningful) GPU % is ~100% whenever anything runs (useless)
new replica in 10–30 s new replica in 1–15 minutes
requests are stateless in-flight requests hold KV cache state
drain in seconds drain takes as long as the longest generationBoth halves are broken: the signal and the reaction time. Fixing the signal is easy. The reaction time is partly an engineering problem (make cold starts shorter) and partly a capacity-planning one (pay for headroom).
3. Simple analogy#
Checkout lanes versus aircraft.
A supermarket opens another checkout lane in 30 seconds. If the queue grows, it opens a lane.
An airline cannot add a plane in 30 seconds. It plans aircraft weeks ahead from forecast demand, keeps a few spares for disruption, and when demand exceeds seats it rebooks, reroutes or turns people away.
LLM serving is closer to the airline. Plan capacity, use autoscaling for slow trends, and have a plan for the spike.
4. Tiny example: what autoscaling can catch#
Traffic of 100 requests per second jumps by 50% for D minutes. Each replica serves 10 requests per second. The autoscaler notices after 1 minute and its new replicas arrive after the cold start. How much of the spike finds no capacity?
// spike.go — how much of a traffic spike autoscaling can catch, by cold-start time and headroom.
package main
import (
"fmt"
"math"
)
// shed returns the share of spike-period requests that find no capacity.
func shed(spikeMin, coldMin, headroom float64) float64 {
const (
base = 100.0 // requests/s before the spike
spike = 1.5 // the spike multiplies traffic by this
perReplica = 10.0 // requests/s one replica serves within the SLO
detectMin = 1.0 // the autoscaler needs this long to notice
)
replicas := math.Ceil(base * (1 + headroom) / perReplica)
needed := math.Ceil(base * spike / perReplica)
var offered, lost float64
for t := 0.0; t < spikeMin; t += 1.0 / 60 { // one-second steps, in minutes
demand := base * spike
capacity := replicas * perReplica
if t >= detectMin+coldMin { // the new replicas have started
capacity = math.Max(capacity, needed*perReplica)
}
offered += demand
lost += math.Max(0, demand-capacity)
}
return lost / offered
}
func main() {
fmt.Println("traffic jumps 50% for D minutes; share of spike requests with no capacity")
fmt.Printf("%-10s %-9s %8s %8s %8s\n", "cold start", "headroom", "D=2", "D=10", "D=60")
for _, cold := range []float64{0.5, 3, 10} {
for _, h := range []float64{0, 0.2, 0.5} {
fmt.Printf("%7.1f min %7.0f%% ", cold, h*100)
for _, d := range []float64{2, 10, 60} {
fmt.Printf("%8.0f%%", shed(d, cold, h)*100)
}
fmt.Println()
}
}
}Output:
traffic jumps 50% for D minutes; share of spike requests with no capacity
cold start headroom D=2 D=10 D=60
0.5 min 0% 25% 5% 1%
0.5 min 20% 15% 3% 1%
0.5 min 50% 0% 0% 0%
3.0 min 0% 33% 13% 2%
3.0 min 20% 20% 8% 1%
3.0 min 50% 0% 0% 0%
10.0 min 0% 33% 33% 6%
10.0 min 20% 20% 20% 4%
10.0 min 50% 0% 0% 0%How to read it:
- A 2-minute spike is never caught by scaling, even with 30-second cold starts: the detection minute alone loses a quarter of it. Only headroom helps.
- A 10-minute spike is mostly caught with a 30-second cold start, a third lost with a 10-minute one. Cold-start time decides whether scaling is useful at all.
- An hour-long rise (a daily peak) is caught by any setup. That is autoscaling’s real job.
- Headroom equal to the spike (50%) loses nothing, at the price of paying for it all day.
So: autoscaling handles daily and weekly patterns; headroom handles spikes; shorter cold starts move the line between them.
5. Technical explanation#
The scaling signal#
SIGNAL QUALITY WHY
GPU utilization USELESS ~100% whenever a kernel runs
CPU utilization useless the GPU is the constraint
requests in flight poor costs vary 1,000×
queue depth ok but length is not wait time (20.c)
KV cache use GOOD measures the binding constraint
p95 queue wait BEST measures the SLO you care about directly
tokens/s against capacity good needs a measured capacity per replicaScale on queue wait (or waiting requests), with KV cache use as a second signal. In vLLM
these are vllm:request_queue_time_seconds, vllm:num_requests_waiting and
vllm:kv_cache_usage_perc (19.c). A percentile of a histogram is not a per-pod metric, so for
queue wait you either write a Prometheus recording rule or use KEDA’s Prometheus trigger, which
takes a query directly.
# Kubernetes HPA on per-pod custom metrics (exposed by prometheus-adapter)
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: chat-model
spec:
scaleTargetRef: {apiVersion: apps/v1, kind: Deployment, name: chat-model}
minReplicas: 4 # baseline traffic; do not scale a big model to zero
maxReplicas: 40
metrics:
- type: Pods
pods:
metric: {name: vllm_num_requests_waiting}
target: {type: AverageValue, averageValue: "4"}
- type: Pods
pods:
metric: {name: vllm_kv_cache_usage_perc}
target: {type: AverageValue, averageValue: "0.8"}
behavior:
scaleUp:
stabilizationWindowSeconds: 60 # react fast
policies: [{type: Percent, value: 100, periodSeconds: 60}]
scaleDown:
stabilizationWindowSeconds: 900 # scale down SLOWLY: 15 minutes
policies: [{type: Pods, value: 1, periodSeconds: 300}]Fast up, slow down. Delaying a scale-down costs a few idle GPU-minutes; getting it wrong costs a cold start to undo. Kubernetes 1.37 also made the HPA’s tolerance (the dead band around the target, 10% by default) settable per direction, which helps a slow, expensive workload ignore small wobbles.
Tools in November 2026#
| Tool | What it adds |
|---|---|
| HPA | The built-in loop. Scale to zero on custom or external metrics is beta and on by default in Kubernetes 1.37. |
| KEDA (v2.21) | Prometheus queries, cron schedules and queue lengths as triggers; scale to and from zero. |
| llm-d Workload Variant Autoscaler | Watches KV cache and queue saturation across a pool, adds replicas to the cheapest hardware variant first, and can wake a pool from zero when requests queue in the router. Used by KServe’s LLMInferenceService. |
| NVIDIA Dynamo Planner | Scales prefill and decode pools separately to hold time-to-first-token and inter-token targets (21.j). |
Cold start: the real problem#
Phase Typical Optimized
Get a GPU node (if none is free) 1–10 min 0 (pre-provisioned node pool)
Pod scheduling 5–30 s 5 s
Image pull (if not cached) 30–180 s 0 (pre-pulled, small image)
Container start + Python import 10–30 s 10 s
Weights from object storage 60–600 s 10–60 s (streamed, cached or from a peer)
Weights into GPU memory 10–60 s 5–20 s (parallel, pinned memory)
Quantization at load time 10–120 s 0 (pre-quantized checkpoint)
torch.compile (if not cached) 60–600 s ~5 s (persisted compile cache)
CUDA graph capture 20–60 s 10–60 s
Warmup requests 5–20 s 5–20 s
─────────────────────────────────────────────────────────────
TOTAL 3–25 min 1–3 minLesson 3.g explains the storage side and 20.h the in-process phases. The techniques, ranked by what they usually save:
1. Do not download per pod. Cache weights on node-local NVMe, or stream them:
- Run:ai Model Streamer: many concurrent reads from disk or S3 straight to the GPU
(vLLM --load-format runai_streamer, 3.g);
- NVIDIA ModelExpress: copies weights GPU-to-GPU over RDMA (NIXL) from a replica that
is already serving, and falls back to streaming from storage. llm-d 1.0 integrates it;
- OCI image volumes: package weights as an OCI artifact and mount it read-only
(stable in Kubernetes 1.36), so the node's image cache does the caching.
2. Ship pre-quantized checkpoints.
3. Persist compile and engine caches (vLLM's ~/.cache/vllm, TensorRT-LLM engines).
4. Keep images small (weights NOT in the image) and pre-pulled.
5. Pre-provisioned warm node pool: removes node creation and image pull entirely.
6. Keep loaded processes around: vLLM sleep mode parks weights in host memory and wakes in
seconds; `vllm preload` keeps weights resident across engine restarts (19.e).
7. Fewer CUDA graph sizes, if startup matters more than the last few percent of speed.Once loading is fast, warmup and kernel autotuning become the largest remaining term. NVIDIA reports that for very large MoE models they can take several minutes on their own.
The strategies that work#
1. HEADROOM
Run at 60–75% utilization. The spare capacity absorbs spikes.
This is the baseline, and it is not optional.
2. PREDICTIVE SCALING
Scale ahead of known patterns (time of day, product launches) with a cron trigger or
a schedule that raises minReplicas. Cheap and effective (23.d).
3. WARM POOL
Replicas loaded but idle, or asleep (sleep mode), ready to take traffic in seconds.
Cost: the GPUs they occupy.
4. GRACEFUL DEGRADATION
When over capacity: shed load (503), cap max_tokens, route some traffic to a smaller
model. This is what you do INSTEAD of scaling, in the minutes scaling takes (21.k).
5. OVERFLOW
Send excess to another region or an external API provider. Expensive per token,
far cheaper than an outage.Headroom and degradation are mandatory. Predictive scaling is cheap and worth doing. Warm pools and overflow depend on your economics.
6. Under the hood: scale-down and draining#
Removing an LLM replica is harder than adding one:
1. Take it out of the router's pool (no new requests)
2. Let in-flight generations finish (could be minutes for long answers)
3. Abort whatever is left after a deadline, with a clear error
4. ExitIn Kubernetes, deleting a pod sends SIGTERM and waits terminationGracePeriodSeconds, 30 s
by default, before killing it. vLLM has a drain path that refuses new requests while the
running ones finish (19.e); it needs time to use it:
spec:
terminationGracePeriodSeconds: 600 # at least your p99 generation time
containers:
- name: vllm
lifecycle:
preStop:
sleep: {seconds: 10} # let routers notice the pod is going firstThe sleep action in preStop (stable since Kubernetes 1.34) needs no shell or curl in the
image. With a short grace period, every scale-down truncates answers, and users see half a
response.
7. Performance implications#
- Cold-start time sets how much headroom you need. Section 4: going from 10 minutes to 30 seconds turns a 10-minute spike from “a third lost” into “5% lost”. Every minute removed from startup is idle capacity you no longer pay for.
- Scaling a replica is not free capacity. A new replica starts with an empty prefix cache, so its first minutes are slower than its neighbours’, and affinity routing (20.f) should warm it gradually.
- Scaling down is a capacity event too. Draining a replica moves its future traffic to the others and its cached prefixes are lost.
- Signals lag. Metrics are scraped every 15–30 s and windows add a minute: detection alone costs a minute or two before any cold start begins.
8. Production implications#
- Do not scale a large model to zero unless the first user can wait minutes. Small models, internal tools and batch pools are where it fits; KEDA, the HPA’s beta support or llm-d’s autoscaler do it.
- Set
minReplicasfrom baseline traffic, not from zero. - Fast up, slow down. Asymmetric windows.
- Measure and alert on cold-start duration. It regresses silently when someone adds a step to startup.
- Test the drain. Roll a deployment under load and check no answers are truncated.
- Budget headroom explicitly in the capacity model (23.b), typically 25–40%.
- Write a degradation plan for when you are over capacity and cannot scale in time.
9. Common mistakes#
- Autoscaling on GPU utilization. It is always near 100%.
- Expecting autoscaling to handle spikes. It cannot react faster than a cold start.
- Scaling a large model to zero. The first request waits five minutes.
- The default 30-second grace period. Truncated answers on every deploy and scale-down.
- Aggressive scale-down. Thrashing: scale down, traffic returns, pay a cold start.
- Downloading weights in every new pod. Minutes and egress cost each time.
- No degradation plan. Decide in advance what happens when you are full.
10. Hands-on exercise#
A. Run the spike model. Run spike.go. Change the spike to 3× (a launch) and detection to
3 minutes. How much headroom does a 10-minute spike need now?
B. Measure cold start, phase by phase. Start a real model server from a fresh node and time each phase in section 5 from its logs. Which dominates?
C. Shorten it. Apply the top three techniques for your setup (a weight cache or streamer, a pre-quantized checkpoint, a persisted compile cache). Measure again. How close to the “optimized” column do you get?
D. Test the drain. Roll a deployment while streaming requests are in flight, first with the default grace period and then with yours. Count truncated answers.
E. Write the policy. Write the HPA or KEDA configuration for your service with the right signal and asymmetric windows. Load-test to check it scales when you expect it to.
11. Interview questions#
- Why is GPU utilization a bad autoscaling signal? What would you use instead?
- Break down the cold start of a 70B model. Which phase dominates, and how do you shorten it?
- Why cannot autoscaling handle short traffic spikes for LLM services?
- Why are scale-up and scale-down policies asymmetric?
- What happens if
terminationGracePeriodSecondsis too short? - What is your plan when you are over capacity and cannot scale in time?
- When is scaling to zero acceptable?
- How does loading weights from a peer GPU change cold start, and when does it not help?
12. Further reading#
Checked on 12 November 2026.
- [REFERENCE] Kubernetes Horizontal Pod Autoscaling — behaviour, tolerance, scaling to and from zero
- [REFERENCE] KEDA documentation and v2.21.0 release
- [REFERENCE] llm-d Workload Variant Autoscaler
- [ESTABLISHED] NVIDIA: ModelExpress, distributing model artifacts
- [REFERENCE] NVIDIA Dynamo: fast model loading
- [REFERENCE] vLLM: Run:ai Model Streamer and sleep mode
- [REFERENCE] Kubernetes image volumes