Lesson 4 of 4 VM Availability and Scale Sets

Configuring Autoscale for Scale Sets

This lesson explains autoscale profiles and rules and how to design rules that scale reliably.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe autoscale profiles, rules and cool-down periods.
  • Explain how scale-out and scale-in rules interact and how to avoid flapping.
  • Describe scale-in policies and predictive autoscale.

Autoscale settings

An autoscale setting, configured on the scale set's Scaling page (Azure Monitor autoscale), has one or more profiles. Each profile has a minimum, maximum and default instance count and a set of rules. A default profile applies when no other profile matches; recurrence profiles apply on schedules such as weekdays from 08:00 to 18:00, and fixed date profiles apply to events. The default count is used when metrics are unavailable.

A metric rule names a metric (such as Percentage CPU, available memory or a custom metric, or a metric of another resource such as Service Bus queue length), a time aggregation, an operator and threshold, a duration (the lookback window, for example 10 minutes), an action (increase or decrease the count by a number or percentage, or to a specific count) and a cool down period during which no further scaling happens.

Match the pairs

Autoscale building blocks

Exam skills 3.2.7

Match each part of an autoscale setting with its role.

Log in to try this activity Interactive activities are free with an account.

Designing rules that behave well

Every scale-out rule should have a matching scale-in rule, or instances are never removed. The thresholds must leave a gap to avoid flapping: if the scale-out threshold is CPU above 70% and the scale-in threshold is CPU below 60%, removing an instance could push the average back above 70%. Autoscale estimates the result before scaling in and skips the action if it would trigger an immediate scale-out. When several rules match, scale-out happens if any scale-out rule is met, while scale-in happens only if all scale-in rules are met.

The scale-in policy chooses which instances are removed: Default (balance across zones and fault domains, then remove the highest instance ID), NewestVM or OldestVM. Instance protection excludes specific instances from scale-in or scale set actions. Predictive autoscale uses machine learning on CPU history to scale out before predictable load, initially in forecast-only mode. Autoscale run history is shown on the Scaling page and in the activity log.

The following diagram compares a scale set's instance count with and without a scale-in rule.

Why the scale set stays at 8 instances all afternoon at 10% CPU. Autoscale scales in only when a scale-in rule is met, and the profile has only the scale-out rule. Adding a rule that removes one instance when average CPU is below 30% for 10 minutes, with a gap from the 75% threshold to avoid flapping, lets it return towards the minimum of 2.
The timeline is illustrative.
Troubleshooting

Autoscale that misbehaves

Exam skills 3.2.7

Find the fix for each autoscale problem.

Log in to try this activity Interactive activities are free with an account.

Example rule set

The following settings, shown as an Azure CLI equivalent, scale a scale set between 2 and 10 instances on CPU.

az monitor autoscale create --resource-group rg-web --resource vmss-web \
  --resource-type Microsoft.Compute/virtualMachineScaleSets --name web-autoscale \
  --min-count 2 --max-count 10 --count 2

az monitor autoscale rule create --resource-group rg-web --autoscale-name web-autoscale \
  --condition "Percentage CPU > 70 avg 10m" --scale out 2

az monitor autoscale rule create --resource-group rg-web --autoscale-name web-autoscale \
  --condition "Percentage CPU < 30 avg 10m" --scale in 1
Fill in the number

Reading the rule set

Exam skills 3.2.7

Read the example autoscale commands and work out the numbers.

Log in to try this activity Interactive activities are free with an account.
Worked example

Autoscale that never scales in

A scale set's autoscale profile has a minimum of 2 and a maximum of 8 instances, one rule that adds 2 instances when average CPU exceeds 75% over 10 minutes, and no other rules. After a busy morning it runs 8 instances all afternoon at 10% CPU. Why, and what should you change?

Autoscale scales in only when a scale-in rule is met, and there is none, so the count stays at 8. Add a scale-in rule, for example decrease by 1 when average CPU is below 30% over 10 minutes, leaving a gap with the 75% scale-out threshold to avoid flapping. Raising the minimum or changing the scale-in policy would not reduce the count.

Check yourself

Two scale-in rules exist. One is met and the other is not. Does autoscale scale in?

Show answer

No. Scale-in happens only when all scale-in rules are met; scale-out happens when any scale-out rule is met.

Exam Tips

Remember for the exam

  • Always pair a scale-out rule with a scale-in rule.
  • Leave a gap between scale-out and scale-in thresholds to avoid flapping.
  • Any scale-out rule triggers scale-out; scale-in needs all scale-in rules to be met.
  • Use schedule-based profiles for predictable business hours.