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

  1. On the menu on the left, select Create a resource.
  2. Search for and select the Web App item and select Create.
  3. 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.

Screenshot that shows creating a new app service in the portal.

Go to autoscale settings

  1. On the menu on the left, select Monitor. Then select the Autoscale tab.

  2. 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.

    Screenshot shows the Azure portal with Monitor and Autoscale selected.

  3. 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.

Screenshot that shows saving the autoscale setting.

Configure default profile

  1. Provide a name for the autoscale setting.

  2. In the default profile, ensure Scale mode is set to Scale to a specific instance count.

  3. 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.

    Screenshot that shows the Autoscale setting screen with a name entered for the setting.

Create recurrence profile

  1. Select the Add a scale condition link under the default profile.

  2. Edit the name of this profile to be Monday to Friday profile.

  3. Ensure Scale mode is set to Scale based on a metric.

  4. 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).

  5. For Schedule, select Repeat specific days.

  6. 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

  1. In the Monday to Friday profile section, select the Add a rule link.

  2. 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.

  3. Set Time aggregation as Total, set Metric name as Requests, and set Time grain statistic as Sum.

  4. Set Operator as Greater than, set Threshold as 10, and set Duration as 5 minutes.

  5. Set Operation as Increase count by, set Instance count as 1, and set Cool down as 5 minutes.

  6. 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.

Screenshot that shows creating a scale-out rule.

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.

  1. In the Monday to Friday profile, select the Add a rule link.

  2. 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.

  3. Set Time aggregation as Total, set Metric name as Requests, and set Time grain statistic as Average.

  4. Set Operator as Less than, set Threshold as 5, and set Duration as 5 minutes.

  5. Set Operation as Decrease count by, set Instance count as 1, and set Cool down as 5 minutes.

  6. Select Add.

    Screenshot that shows creating a scale-in rule.

  7. Save the autoscale setting.

    Screenshot that shows saving 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.

  1. 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.

  2. In quick succession, reload the page more than 10 times.

  3. On the menu on the left, select Monitor. Then select the Autoscale tab.

  4. From the list, select the App Service plan used throughout this tutorial.

  5. On the Autoscale setting screen, select the Run history tab.

  6. 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.

  7. 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.

  1. Ensure no requests are being sent to your web app.

  2. Load the Azure portal.

  3. On the menu on the left, select Monitor. Then select the Autoscale tab.

  4. From the list, select the App Service plan used throughout this tutorial.

  5. On the Autoscale setting screen, select the Run history tab.

  6. 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.

  7. Under the chart, you see the corresponding set of activity log entries for each scale action taken by this autoscale setting.

    Screenshot that shows viewing scale-in actions.

Clean up resources

  1. On the menu on the left in the Azure portal, select All resources. Then select the web app created in this tutorial.

  2. On your resource page, select Delete. Confirm delete by entering yes in the text box, and then select Delete.

  3. Select the App Service plan resource and select Delete.

  4. Confirm delete by entering yes in the text box, and then select Delete.

Next steps

To learn more about autoscale settings, see Autoscale overview.