Sub topic 15
Instance warmup and cooldown
This chapter assumes you have an Auto Scaling group attached to a target group and a target tracking or step scaling policy, as in the earlier chapters. You should also know what a CloudWatch alarm is.
The problem: new instances look idle
A new instance takes time to boot, run user data, and warm its caches. While it does that, it reports low CPU and handles few requests. If Auto Scaling averaged those numbers into the group metric, the average would drop and the group might think it had enough capacity. Or it might keep adding instances because the alarm still fires. Warmup and cooldown are the two controls that prevent this.
Instance warmup
Instance warmup is the time after an instance enters InService during which Auto Scaling does not count its metrics toward the group's aggregated metrics. This applies to target tracking and step scaling policies.
- While instances are warming, they count toward the group's capacity, so the policy does not launch duplicates for the same demand.
- Scale-in is held back for target tracking while a scale-out is still warming up.
- After the warmup time ends, the instance's metrics join the aggregate.
Set a group-wide default so every policy uses it:
aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name web-asg \
--default-instance-warmup 120A single target tracking policy can override the default with EstimatedInstanceWarmup:
{
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ALBRequestCountPerTarget",
"ResourceLabel": "app/web-alb/50dc6c495c0c9188/targetgroup/web-tg/943f017f100becff"
},
"TargetValue": 1000.0,
"EstimatedInstanceWarmup": 120
}Choose a value close to the real time from launch until the instance serves normal traffic. Too short, and you over-scale. Too long, and scaling reacts slowly.
Cooldown
A cooldown is a pause after a scaling activity, during which a simple scaling policy ignores further alarms. The default is 300 seconds. Target tracking and step scaling do not use the cooldown. They use warmup instead. Scheduled actions ignore cooldown too.
aws autoscaling put-scaling-policy \
--auto-scaling-group-name web-asg \
--policy-name add-one-instance \
--policy-type SimpleScaling \
--adjustment-type ChangeInCapacity \
--scaling-adjustment 1 \
--cooldown 300Do not confuse these with the health check grace period
| Setting | What it delays | Applies to |
|---|---|---|
| Instance warmup | Counting the instance's metrics | Target tracking, step scaling |
| Cooldown | The next simple scaling action | Simple scaling |
| Health check grace period | Replacing an instance that fails health checks | Health checks |
Common errors
- Scaling out in repeated bursts: the warmup is shorter than the real startup time.
- A policy that seems to ignore alarms: it is a simple scaling policy still inside its cooldown.
- Setting a cooldown on a target tracking policy and expecting an effect. It has none.
Exercise
A step scaling policy adds two instances each time CPU passes 70 percent. Instances need about 4 minutes to serve traffic normally, but the group keeps overshooting its needed size. Which setting should you change, and why?
Show answer
Raise the instance warmup (the default instance warmup or the policy's estimated warmup) to about 240 seconds or a little more. Until then the new instances' low CPU is counted, so the aggregate stays misleading and the group keeps adding capacity. A cooldown does not apply to step scaling.