What is Autoscaling in Azure?
Autoscaling is a method used in cloud computing to automatically scale computing resources of your application base on a company's server farm. Resources scale up when there is an increase in web traffic and resources scale down when traffic levels are low.
The elastic cloud
Your application may experience a large or small amount of visits and with that said, it is ideal to keep your applications running in both scenarios.
Sometimes a lot of users visit your applications, and sometimes, it's not busy. You want your application to stay up and running in both scenarios. The cloud offers flexible capabilities to make this possible. When a lot of users visit your application, you can automatically scale your application to meet those needs. When visits decrease, your applications will scale back to minimise costs and Azure App Service Web Apps accomplishes just that.
Let's go through and configure an Azure App Service Web App to automatically scale your applications
If you want to follow along, you'll need the following:
- An Azure subscription (If you don't have an Azure subscription, create a free account before you begin
- An existing Azure App Service Web App with an application running in it. Learn how to create one in this quickstart. Make sure that it is running on an App Service plan of the S family or higher. This is required to use autoscaling
Scaling a Web App out and in
Scaling up and down means that you increase or decrease the processing capacity of your infrastructure. In the case of an Azure App Service Web App, scaling up would mean choosing a more powerful App Service plan. Scaling out and in means that you increase or decrease the amount of instances that run your application. For a Web App, that means scaling the amount of Web App instances up or down.
Let's configure a Web App to automatically scale out and in, based on a metric.
- Go to the Azure portal (opens new window)and navigate to the existing Web App
- Navigate to the Scale out (App Service plan) menu
- You can scale the amount of Web App instances that run in the App Service plan. Multiple instances will all share the computing power of the same App Service plan. You can scale the instance count manually, or automatically
Scale the number of instances
Click on Custom autoscale. You'll now see the first scale condition. You can add and remove conditions that dictate how the autoscaling works.
Let's configure the first condition. We will scale based on a metric. Click the Add a rule link.
Add an autoscale rule
Pick a Metric name. This is the metric that we will base the rule on. For instance, pick CPU Percentage. When you select a metric, you'll see the graph of the metric value for the last 10 minutes.
Next, fill in the Metric threshold to trigger scale action. For CPU percentage, this could be 70. With the default settings, this means that if the average CPU percentage of the Web App was greater than 70 percent for 10 minutes, a scale action is triggered. You can change this rule by changing the Operator, Duration, and Time grain statistic, that determine how the metric is evaluated.
Next, enter the Instance count that you want the Web App to scale with. Leave the operation to increase count by, and the cool down to 5. This means that the Web App will increase its number of instances by 3 when it scales, and that it will not execute this scale action again for 5 minutes (the cool down period).
Click Add to add the rule. You can add more rules to the scale condition, and we will leave it to just this one.
In the condition, you can set the Instance limits. This is the minimum, maximum, and default number of instances the Web App should have.
Add another condition by clicking on the Add a scale condition.
Select scale to a specific instance count.
Enter a Start date and time and an End date and time. You can use this to scale in or out at certain times, like to scale in to save costs over the weekend when there are less users.
Scale based on a schedule
Click Save to save the scale conditions
Use the web application until it scales. When you go back to the Scale out menu, you can see the scale actions in the Run history tab.
Autoscaling is a powerful feature of Azure App Service that enables you to continue serving users when it is busy, and save cost when there are less visitors. Check out how Azure enhances your business application!