Επεξεργασία

Κοινή χρήση μέσω


Autoscale with multiple profiles

Scaling your resources for a particular day of the week, or a specific date and time can reduce your costs while still providing the capacity you need when you need it.

You can use multiple profiles in autoscale to scale in different ways at different times. If for example, your business isn't active on the weekend, create a recurring profile to scale in your resources on Saturdays and Sundays. If black Friday is a busy day, create a profile to automatically scale out your resources on black Friday.

This article explains the different profiles in autoscale and how to use them.

You can have one or more profiles in your autoscale setting.

There are three types of profile:

  • The default profile. The default profile is created automatically and isn't dependent on a schedule. The default profile can't be deleted. The default profile is used when there are no other profiles that match the current date and time.
  • Recurring profiles. A recurring profile is valid for a specific time range and repeats for selected days of the week.
  • Fixed date and time profiles. A profile that is valid for a time range on a specific date.

Each time the autoscale service runs, the profiles are evaluated in the following order:

  1. Fixed date profiles
  2. Recurring profiles
  3. Default profile

If a profile's date and time settings match the current time, autoscale applies that profile's rules and capacity limits. Only the first applicable profile is used.

The following example shows an autoscale setting with a default profile and recurring profile.

A screenshot showing an autoscale setting with default and recurring profile or scale condition.

In the example above, on Monday after 3 AM, the recurring profile will cease to be used. If the instance count is less than 3, autoscale scales to the new minimum of three. Autoscale continues to use this profile and scales based on CPU% until Monday at 8 PM. At all other times scaling is done according to the default profile, based on the number of requests. After 8 PM on Monday, autoscale switches to the default profile. If for example, the number of instances at the time is 12, autoscale scales in to 10, which the maximum allowed for the default profile.

Multiple contiguous profiles

Autoscale transitions between profiles based on their start times. The end time for a given profile is determined by the start time of the following profile.

In the portal, the end time field becomes the next start time for the default profile. You can't specify the same time for the end of one profile and the start of the next. The portal forces the end time to be one minute before the start time of the following profile. During this minute, the default profile becomes active. If you don't want the default profile to become active between recurring profiles, leave the end time field empty.

Tip

To set up multiple contiguous profiles using the portal, leave the end time empty. The current profile will stop being used when the next profile becomes active. Only specify an end time when you want to revert to the default profile. Creating a recurring profile with no end time is only supported via the portal and ARM templates.

Multiple profiles using templates, CLI, and PowerShell

When creating multiple profiles using templates, the CLI, and PowerShell, follow the guidelines below.

See the autoscale section of the ARM template resource definition for a full template reference.

There's no specification in the template for end time. A profile will remain active until the next profile's start time.

Add a recurring profile using ARM templates

The following example shows how to create two recurring profiles. One profile for weekends from 00:01 on Saturday morning and a second Weekday profile starting on Mondays at 04:00. That means that the weekend profile starts on Saturday morning at one minute passed midnight and end on Monday morning at 04:00. The Weekday profile will start at 4am on Monday and end just after midnight on Saturday morning.

Use the following command to deploy the template: az deployment group create --name VMSS1-Autoscale-607 --resource-group rg-vmss1 --template-file VMSS1-autoscale.json where VMSS1-autoscale.json is the file containing the following JSON object.

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [
        {
            "type": "Microsoft.Insights/autoscaleSettings",
            "apiVersion": "2015-04-01",
            "name": "VMSS1-Autoscale-607",
            "location": "eastus",
            "properties": {

                "name": "VMSS1-Autoscale-607",
                "enabled": true,
                "targetResourceUri": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/rg-vmss1/providers/Microsoft.Compute/virtualMachineScaleSets/VMSS1",
                "profiles": [
                    {
                        "name": "Weekday profile",
                        "capacity": {
                            "minimum": "3",
                            "maximum": "20",
                            "default": "3"
                        },
                        "rules": [
                            {
                                "scaleAction": {
                                    "direction": "Increase",
                                    "type": "ChangeCount",
                                    "value": "1",
                                    "cooldown": "PT5M"
                                },
                                "metricTrigger": {
                                    "metricName": "Inbound Flows",
                                    "metricNamespace": "microsoft.compute/virtualmachinescalesets",
                                    "metricResourceUri": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/rg-vmss1/providers/Microsoft.Compute/virtualMachineScaleSets/VMSS1",
                                    "operator": "GreaterThan",
                                    "statistic": "Average",
                                    "threshold": 100,
                                    "timeAggregation": "Average",
                                    "timeGrain": "PT1M",
                                    "timeWindow": "PT10M",
                                    "Dimensions": [],
                                    "dividePerInstance": true
                                }
                            },
                            {
                                "scaleAction": {
                                    "direction": "Decrease",
                                    "type": "ChangeCount",
                                    "value": "1",
                                    "cooldown": "PT5M"
                                },
                                "metricTrigger": {
                                    "metricName": "Inbound Flows",
                                    "metricNamespace": "microsoft.compute/virtualmachinescalesets",
                                    "metricResourceUri": "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/rg-vmss1/providers/Microsoft.Compute/virtualMachineScaleSets/VMSS1",
                                    "operator": "LessThan",
                                    "statistic": "Average",
                                    "threshold": 60,
                                    "timeAggregation": "Average",
                                    "timeGrain": "PT1M",
                                    "timeWindow": "PT10M",
                                    "Dimensions": [],
                                    "dividePerInstance": true
                                }
                            }
                        ],
                        "recurrence": {
                            "frequency": "Week",
                            "schedule": {
                                "timeZone": "E. Europe Standard Time",
                                "days": [
                                    "Monday"
                                ],
                                "hours": [
                                    4
                                ],
                                "minutes": [
                                    0
                                ]
                            }
                        }
                    },
                    {
                        "name": "Weekend profile",
                        "capacity": {
                            "minimum": "1",
                            "maximum": "3",
                            "default": "1"
                        },
                        "rules": [],
                        "recurrence": {
                            "frequency": "Week",
                            "schedule": {
                                "timeZone": "E. Europe Standard Time",
                                "days": [
                                    "Saturday"                                    
                                ],
                                "hours": [
                                    0
                                ],
                                "minutes": [
                                    1
                                ]
                            }
                        }
                    }
                ],
                "notifications": [],
                "targetResourceLocation": "eastus"
            }

        }
    ]
}    

Next steps