Sub topic 11
Stabilization, Cooldown, and Scaling Limits
Assume you know how a Kubernetes Deployment runs model replicas and how an autoscaler uses metrics such as queue depth or CPU utilization. This chapter focuses on preventing replicas from changing too quickly when inference traffic varies.
Why scaling needs control
An autoscaler repeatedly compares the current metric with a target. If queue depth rises, it requests more replicas. If the queue drains, it requests fewer.
Model services make this decision difficult:
- A new replica may need time to start, load model weights, and warm its accelerator.
- Batching can temporarily increase queue depth while the server waits for a fuller batch.
- A short traffic spike may end before a new replica becomes ready.
- Removing a replica too soon can send traffic back to the remaining replicas.
Without safeguards, the service can oscillate. It scales up, the queue drains, and it immediately scales down. The next burst then causes another scale-up.
Stabilization windows
A stabilization window makes the autoscaler consider recent recommendations instead of only the newest one. For scale-down, a common policy keeps the highest recommendation seen during the window. This prevents a brief quiet period from removing capacity that may soon be needed again.
A five-minute scale-down window is a useful starting point for a model with slow startup. It is not automatically correct. Measure how long traffic bursts last and how long a replica takes to become ready.
Cooldown and scaling limits
A cooldown is a delay before another scaling action is allowed. Some autoscaling systems expose a setting named cooldownPeriod; Kubernetes HPA mainly provides stabilization windows and rate policies instead. These controls solve related but different problems:
| Control | Main purpose | Typical effect |
|---|---|---|
| Stabilization window | Smooth changing recommendations | Delays reacting to recent metric history |
| Cooldown | Wait after an action | Prevents immediate repeated actions |
| Scaling policy | Limit action size or speed | Caps replicas added or removed per period |
Scaling policies are especially useful during sudden load. For example, allow at most four new pods per minute, or at most 100% growth per minute. Set a minimum and maximum replica count so a bad metric or unexpected traffic cannot create unlimited cost.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: model-server
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: model-server
minReplicas: 2
maxReplicas: 20
metrics:
- type: Pods
pods:
metric:
name: inference_queue_depth
target:
type: AverageValue
averageValue: "4"
behavior:
scaleUp:
stabilizationWindowSeconds: 30
policies:
- type: Pods
value: 4
periodSeconds: 60
- type: Percent
value: 100
periodSeconds: 60
selectPolicy: Max
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Pods
value: 1
periodSeconds: 60
selectPolicy: MinThe custom metric requires a metrics adapter. selectPolicy: Max chooses the faster permitted scale-up policy. selectPolicy: Min chooses the slower scale-down policy. Together, these settings add capacity promptly but remove it cautiously.
A practical tuning sequence
- Set
minReplicasto the capacity needed for normal traffic. - Set
maxReplicasfrom accelerator budget and tested throughput. - Start with conservative scale-down behavior.
- Compare queue depth, readiness time, replica count, and p99 latency during bursts.
- Shorten or lengthen windows only after observing several traffic patterns.
Exercise
A model takes four minutes to load, and traffic bursts last two minutes. Which control should be conservative, and why?
Show answer
Keep scale-down stabilization near or above the load and warmup times. Removing replicas during a short quiet period could leave the service under capacity when the next burst arrives.