question

PitawatN-1924 avatar image
1 Vote"
PitawatN-1924 asked SnehaAgrawal-MSFT answered

What is "Flapping" in App Service autoscale?

I have an App Service P1V2 plan with custom autoscale rule configured to scale out to 2 instances when avg CPU >= 40% and to scale in to 1 instance when avg CPU < 40%. The scale out rule works fine when the workload gets higher in the morning around 6:30 AM , but when the avg %CPU drops below 40% it does not scale in at the expected point. Sometimes it waited for a few hours before scaling in.

Yesterday was a bit odd, it waited the whole day before scaling in at around 7:00 PM. I checked the run history and found "Flapping" at each hour for the whole day.


125844-appserviceflapping.png



This is the avg CPU usage at the same time period. (5 mins granularity) You can see that avg CPU is at 25% at around 9:00 AM. I expect it to scale in at this point.

125799-appservicecpu.png



This is the scale in rule I currently have. Is there anything I should adjust? And what is Flapping? Does it have anything to do with the App Service plan not getting scaled in? Thanks.

125852-appservicescalein.png

azure-webapps
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SnehaAgrawal-MSFT avatar image
0 Votes"
SnehaAgrawal-MSFT answered

Thanks for asking question! There are best practices for Autoscale and it’s recommended to choose carefully different thresholds for scale-out and scale-in based on practical situations.

Estimation during a scale-in is intended to avoid "flapping" situations, where scale-in and scale-out actions continually go back and forth. Keep this behavior in mind when you choose the same thresholds for scale-out and in.

Its recommended choosing an adequate margin between the scale-out and in thresholds.

As an example, consider the following better rule combination.
• Increase instances by 1 count when CPU% >= 80
• Decrease instances by 1 count when CPU% <= 60

In this case
1. Assume there are 2 instances to start with.
2. If the average CPU% across instances goes to 80, autoscale scales out adding a third instance.
3. Now assume that over time the CPU% falls to 60.
4. Autoscale's scale-in rule estimates the final state if it were to scale-in.

For example, 60 x 3 (current instance count) = 180 / 2 (final number of instances when scaled down) = 90. So autoscale does not scale-in because it would have to scale-out again immediately. Instead, it skips scaling down.

5.The next time autoscale checks, the CPU continues to fall to 50. It estimates again - 50 x 3 instance = 150 / 2 instances = 75, which is below the scale-out threshold of 80, so it scales in successfully to 2 instances.

Note: If the autoscale engine detects flapping could occur as a result of scaling to the target number of instances, it will also try to scale to a different number of instances between the current count and the target count. If flapping does not occur within this range, autoscale will continue the scale operation with the new target.

Hope this helps. Let us know if further query or issue remains.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.