Why you need it

Visitors do not come at a steady rate. A sale or a mention on TV can bring three times as many in minutes, and the code still says one copy. Set the number high enough for the rush and you pay for empty copies the rest of the day.

Think of it like this

A supermarket manager who watches the queues. When lines get long, she opens more tills. When the shop empties out, she sends staff home. Nobody had to plan the rush the day before.

Where you’ll find it

What to know first

Reconciliation. A controller keeps the running copies equal to the number in the code. See Desired state and reconciliation.

Metrics. Numbers measured all the time, like how busy each copy's CPU is. See Metrics and alerts.

Target. The busyness you want each copy to sit at, for example 50% CPU, leaving room for surprises.

How it works

  1. Watch how busy the copies are. The autoscaler reads a metric every few seconds, often the average CPU across copies. This is the autoscaler in the animation.
  2. Work out the new number. If copies are three times busier than the target, you need three times as many.New copies = current copies × (busyness now ÷ target), rounded up.
  3. Change the number, not the copies. The autoscaler only raises the number in the code, from 1 to 3. The controller then starts the copies, as in Desired state and reconciliation.
  4. New copies are not instant. Each copy needs time to start, often 10 seconds to a few minutes. Visitors wait meanwhile, as in the animation. So aim the target low enough to leave room, and keep a minimum number of copies.
  5. Go down slowly. When visitors leave, the number goes back down, but only after the quiet has lasted a while (often about 5 minutes). Otherwise a short dip removes copies just before the next wave.

An example

One copy, target 30% CPU. A sale starts and that copy hits 90%.

1 × (90 ÷ 30) = 3. The autoscaler sets 3. About 30 seconds later, two new copies are up and each sits near 30%.

At night CPU falls to 10% on each of 3. 3 × (10 ÷ 30) = 1. After 5 quiet minutes, the number goes back to 1.

Further reading