Sub topic 16
Instance warmup and cooldown
This chapter assumes you can read an Auto Scaling group definition, know what a CloudWatch alarm is, and have seen a target tracking policy like the one earlier in this tutorial. It covers the two timers that stop scaling from overreacting: instance warmup and cooldown.
The problem both timers solve
A new instance is not useful the moment it launches. It boots, runs user data, starts the application, and passes load balancer health checks. During that time it contributes little traffic handling, and its metrics look odd (often a CPU spike during boot).
Without a delay, the Auto Scaling group sees high load, launches instances, sees that load is still high because the new instances are not working yet, and launches more. The group overshoots and later scales back in, which costs money and churns instances.
AWS gives you two mechanisms. They apply to different policy types, so mixing them up is a common source of confusion.
| Mechanism | Applies to | What it does |
|---|---|---|
| Cooldown | Simple scaling policies | Blocks further scaling activity for a period after one completes |
| Instance warmup | Target tracking and step scaling policies | Keeps new instances out of metric aggregation until they are ready |
Scheduled actions ignore both. A scheduled action runs at its set time regardless of recent activity.
Cooldown
A cooldown is a pause. After a simple scaling policy launches or terminates instances, the group refuses further activity from that policy until the cooldown ends. The group-wide default cooldown is 300 seconds. A simple scaling policy can override it with its own value.
Simple scaling is the oldest policy type. It waits for the activity to finish and then waits out the cooldown before it reacts again. For most workloads, target tracking or step scaling is a better choice, so cooldown is mostly relevant when you maintain older setups.
This command creates a simple scaling policy with a 120-second cooldown:
aws autoscaling put-scaling-policy \
--auto-scaling-group-name web-asg \
--policy-name add-two-instances \
--policy-type SimpleScaling \
--adjustment-type ChangeInCapacity \
--scaling-adjustment 2 \
--cooldown 120Instance warmup
Instance warmup is the time you estimate a new instance needs before it contributes to the metrics. The group handles instances in warmup in two ways:
- Instances still warming up are not counted when the group aggregates the metric. A booting instance with 5% CPU does not drag the average down and hide real load.
- Instances still warming up do count toward the capacity the group already has. If an alarm stays in alarm state, the group does not launch a duplicate batch for the same shortfall.
Because of this, target tracking and step scaling can keep reacting to a growing load without the full pause a cooldown imposes. A larger spike can still trigger additional scale-out while earlier instances warm up.
Setting a default warmup
You can set the warmup once for the group:
aws autoscaling update-auto-scaling-group \
--auto-scaling-group-name web-asg \
--default-instance-warmup 180All target tracking and step scaling policies then use 180 seconds. Instance refresh also uses this value, which is described below. If you do not set a default warmup, the group falls back to the default cooldown value, which is 300 seconds. That is often longer than your application needs, so set it explicitly.
You can also set a per-policy value for step scaling with --estimated-instance-warmup, which overrides the group default for that policy. Prefer the group default unless a policy has a real reason to differ, because one value is easier to reason about.
Choosing the value
Measure how long a new instance takes to start serving traffic. Use the time from the instance entering InService until the metric you scale on settles. Then add a small margin.
- Too short: new instances are counted while still booting. The average metric dips or spikes oddly, and the group may overshoot.
- Too long: the group ignores real contribution from new instances. Scale-out stays aggressive for longer than needed and scale-in decisions are delayed.
How warmup relates to the health check grace period
These are separate settings, and people often confuse them.
| Setting | Question it answers | Effect |
|---|---|---|
| Health check grace period | How long before the group may judge an instance unhealthy? | Prevents replacement of an instance that is still booting |
| Instance warmup | How long before an instance's metrics count? | Prevents scaling decisions based on immature data |
Both start when the instance launches, but they act on different decisions. A reasonable pattern is a grace period at least as long as your slowest boot, and a warmup roughly as long as the time to reach steady load.
Sequence of a scale-out with warmup
Effect on instance refresh
When you run an instance refresh to replace instances, the group waits for the default warmup after each replacement before continuing. A warmup that is too short lets the refresh move on before the new instance is ready, which can reduce capacity. A warmup that is too long makes the refresh slow.
Common errors
- Setting a cooldown on a target tracking policy. Target tracking does not use cooldown, so the value has no effect. Use warmup.
- Leaving the default. The 300-second fallback may be far longer than your boot time, so scaling reacts more slowly than it could.
- Expecting warmup to delay an alarm. Warmup changes which instances count in the metric. It does not stop the alarm from firing.
- Setting warmup shorter than boot time. The group counts instances that cannot yet serve traffic, which hides load and causes overshoot.
Exercise
A web tier uses a target tracking policy on average CPU. New instances take about 4 minutes to start serving traffic, yet the group launches too many instances during every traffic spike. Which setting would you check first, and why would adding a cooldown value to the policy not help?
Show answer
Check the instance warmup, and set the default instance warmup to a little over 240 seconds. With a shorter warmup, booting instances are counted in the metric before they handle traffic, so the group misjudges the load. Cooldown applies only to simple scaling policies, so a cooldown value on a target tracking policy has no effect.