Sub topic 12
Cold Start and Warmup
Assume you know how an HTTP or gRPC model endpoint works, can read Kubernetes YAML, and understand latency percentiles such as p50 and p99. This chapter focuses on the delay before a new model replica can serve reliable traffic.
What happens during a cold start
A cold start occurs when a new replica must become ready before handling requests. The delay can include:
- Starting a container and loading its image.
- Starting the model server and runtime.
- Loading model weights from storage into memory.
- Allocating accelerator memory.
- Compiling kernels or selecting optimized execution plans.
- Creating connection pools and caches.
- Running warmup inference requests.
A replica should receive production traffic only after these steps finish. A readiness check tells the router whether traffic is safe. A liveness check answers a different question: whether the process should be restarted.
flowchart TD
A[Autoscaler creates replica] --> B[Start container]
B --> C[Load model weights]
C --> D[Initialize runtime and accelerator]
D --> E[Run warmup requests]
E --> F[Readiness becomes true]
F --> G[Router sends production traffic]
G --> H[Replica serves requests]caption: Replica lifecycle from creation to serving traffic alt: A flowchart showing a new replica starting, loading the model, warming up, becoming ready, and then receiving requests.
Readiness, liveness, and startup probes
Kubernetes probes help separate startup failure from temporary startup delay.
- A startup probe gives a slow application time to initialize.
- A readiness probe removes an unready replica from service endpoints.
- A liveness probe restarts a process that has become unhealthy after startup.
Do not use a liveness probe that fails while the model is still loading. Kubernetes may repeatedly kill a healthy process before it becomes ready.
apiVersion: v1
kind: Pod
metadata:
name: model-server
spec:
containers:
- name: inference
image: example/model-server:1.0
ports:
- containerPort: 8080
startupProbe:
httpGet:
path: /health/live
port: 8080
periodSeconds: 5
failureThreshold: 60
readinessProbe:
httpGet:
path: /health/ready
port: 8080
periodSeconds: 2
failureThreshold: 3
livenessProbe:
httpGet:
path: /health/live
port: 8080
periodSeconds: 10
failureThreshold: 3The startup budget here is about five minutes: 60 * 5 seconds. Set it from measured worst-case startup time, not guesswork.
Warmup and traffic protection
Warmup requests should resemble real requests. They can populate compiled kernels, memory allocators, tokenizer paths, and inference caches. A single tiny request may not exercise the slow path.
Warmup consumes accelerator time, so it can temporarily reduce capacity while a replica starts. During a rollout or scale-out event, monitor both the new replica's readiness time and the remaining replicas' queue depth.
A useful readiness design has these properties:
- It stays false until model loading and warmup succeed.
- It becomes false when the replica cannot accept more work.
- It does not depend on a request that needs production authentication or customer data.
- It exposes startup duration as a metric.
Planning for cold-start delay
If startup takes 90 seconds, an autoscaler cannot immediately repair a traffic spike by adding replicas. Keep enough warm capacity for normal bursts, and scale before the queue becomes large enough to violate the latency objective.
Use scale-to-zero only when occasional startup delay is acceptable or another layer can queue requests. Interactive services commonly keep a minimum number of warm replicas. Batch workloads can tolerate longer startup delays when cost matters more than immediate response time.
Exercise
A new replica loads its model successfully, but its first real request takes 800 ms while later requests take 100 ms. Should readiness become true immediately after model loading?
Show answer
No. Run representative warmup requests first, then mark the replica ready only when its initialization and measured serving path meet the service objective.