Create an autoscale setting for Azure resources based on performance data or a schedule
Autoscale settings enable you to add or remove instances of service based on preset conditions. These settings can be created through the portal. This method provides a browser-based user interface for creating and configuring an autoscale setting.
In this tutorial, you will:
- Create a web app and Azure App Service plan.
- Configure autoscale rules for scale-in and scale-out based on the number of requests a web app receives.
- Trigger a scale-out action and watch the number of instances increase.
- Trigger a scale-in action and watch the number of instances decrease.
- Clean up your resources.
If you don't have an Azure subscription, create a free account before you begin.
Sign in to the Azure portal
Sign in to the Azure portal.
Create a web app and App Service plan
- On the menu on the left, select Create a resource.
- Search for and select the Web App item and select Create.
- Select an app name like MyTestScaleWebApp. Create a new resource group myResourceGroup or place it into a resource group of your choosing.
Within a few minutes, your resources should be provisioned. Use the web app and corresponding App Service plan in the remainder of this tutorial.
Go to autoscale settings
On the menu on the left, select Monitor. Then select the Autoscale tab.
A list of the resources under your subscription that support autoscale are listed here. Identify the App Service plan that was created earlier in the tutorial, and select it.
On the Autoscale setting screen, select Enable autoscale.
The next few steps help you fill the Autoscale setting screen to look like the following screenshot.
Configure default profile
Provide a name for the autoscale setting.
In the default profile, ensure Scale mode is set to Scale to a specific instance count.
Set Instance count to 1. This setting ensures that when no other profile is active, or in effect, the default profile returns the instance count to 1.
Create recurrence profile
Select the Add a scale condition link under the default profile.
Edit the name of this profile to be Monday to Friday profile.
Ensure Scale mode is set to Scale based on a metric.
For Instance limits, set Minimum as 1, Maximum as 2, and Default as 1. This setting ensures that this profile doesn't autoscale the service plan to have less than one instance or more than two instances. If the profile doesn't have sufficient data to make a decision, it uses the default number of instances (in this case, one).
For Schedule, select Repeat specific days.
Set the profile to repeat Monday through Friday, from 09:00 PST to 18:00 PST. This setting ensures that this profile is only active and applicable 9 AM to 6 PM, Monday through Friday. During all other times, the Default profile is the profile the autoscale setting uses.
Create a scale-out rule
In the Monday to Friday profile section, select the Add a rule link.
Set Metric source to be Other resource. Set Resource type as App Services and set Resource as the web app you created earlier in this tutorial.
Set Time aggregation as Total, set Metric name as Requests, and set Time grain statistic as Sum.
Set Operator as Greater than, set Threshold as 10, and set Duration as 5 minutes.
Set Operation as Increase count by, set Instance count as 1, and set Cool down as 5 minutes.
Select Add.
This rule ensures that if your web app receives more than 10 requests within 5 minutes or less, one other instance is added to your App Service plan to manage load.
Create a scale-in rule
We recommend that you always have a scale-in rule to accompany a scale-out rule. Having both ensures that your resources aren't overprovisioned. Overprovisioning means you have more instances running than needed to handle the current load.
In the Monday to Friday profile, select the Add a rule link.
Set Metric source to Other resource. Set Resource type as App Services, and set Resource as the web app you created earlier in this tutorial.
Set Time aggregation as Total, set Metric name as Requests, and set Time grain statistic as Average.
Set Operator as Less than, set Threshold as 5, and set Duration as 5 minutes.
Set Operation as Decrease count by, set Instance count as 1, and set Cool down as 5 minutes.
Select Add.
Save the autoscale setting.
Trigger scale-out action
To trigger the scale-out condition in the autoscale setting you created, the web app must have more than 10 requests in less than 5 minutes.
Open a browser window and go to the web app you created earlier in this tutorial. You can find the URL for your web app in the Azure portal by going to your web app resource and selecting Browse on the Overview tab.
In quick succession, reload the page more than 10 times.
On the menu on the left, select Monitor. Then select the Autoscale tab.
From the list, select the App Service plan used throughout this tutorial.
On the Autoscale setting screen, select the Run history tab.
You see a chart that reflects the instance count of the App Service plan over time. In a few minutes, the instance count should rise from 1 to 2.
Under the chart, you see the activity log entries for each scale action taken by this autoscale setting.
Trigger scale-in action
The scale-in condition in the autoscale setting triggers if there are fewer than five requests to the web app over a period of 10 minutes.
Ensure no requests are being sent to your web app.
Load the Azure portal.
On the menu on the left, select Monitor. Then select the Autoscale tab.
From the list, select the App Service plan used throughout this tutorial.
On the Autoscale setting screen, select the Run history tab.
You see a chart that reflects the instance count of the App Service plan over time. In a few minutes, the instance count should drop from 2 to 1. The process takes at least 100 minutes.
Under the chart, you see the corresponding set of activity log entries for each scale action taken by this autoscale setting.
Clean up resources
On the menu on the left in the Azure portal, select All resources. Then select the web app created in this tutorial.
On your resource page, select Delete. Confirm delete by entering yes in the text box, and then select Delete.
Select the App Service plan resource and select Delete.
Confirm delete by entering yes in the text box, and then select Delete.
Next steps
To learn more about autoscale settings, see Autoscale overview.