All Products
Search
Document Center

Auto Scaling:Expected number of instances

Last Updated:Dec 15, 2023

If you enable the Expected Number of Instances feature for a scaling group, Auto Scaling adjusts the number of instances in the scaling group to maintain the specified expected number of instances. Auto Scaling also flexibly executes parallel scaling activities. Manual intervention is not required. This topic describes the Expected Number of Instances feature and its limits, instance change patterns, and usage examples.

Feature description

The Expected Number of Instances feature can ensure that a specified number of instances are kept in a scaling group. If you enabled the Expected Number of Instances feature for a scaling group and the current number of instances in the scaling group does not match the specified expected number of instances, Auto Scaling executes scaling activities in the scaling group to ensure that the number of instances matches the specified expected number of instances. No manual intervention is required during the process.

Benefits

The Expected Number of Instances feature improves the utilization of scaling groups and automates the execution of scaling activities, which effectively resolves the following issues:

Note

For more information about the differences that the Expected Number of Instances feature makes, see Differences between scaling groups with an expected number of instances and scaling groups without an expected number of instances.

  • Low utilization of scaling groups. If you do not enable the Expected Number of Instances feature for a scaling group, Auto Scaling rejects the execution of a new scaling activity when the scaling group has an ongoing scaling activity.

    For example, if the Health Check feature attempts to trigger a scaling activity in a scaling group while the scaling group has an ongoing scaling activity, Auto Scaling rejects the scaling activity triggered by the Health Check feature.

  • Manual retry upon scaling failures. If you do not enable the Expected Number of Instances feature for a scaling group, you must manually retry the scaling operation when a scaling failure occurs.

Enable or disable the Expected Number of Instances feature

You can enable or disable the Expected Number of Instances feature in the following ways:

  • When you create a scaling group or modify an existing scaling group, you can configure the Expected Number of Instances parameter to enable the Expected Number of Instances feature. For more information, see Manage scaling groups.

    Note

    After you enable the Expected Number of Instances feature for a scaling group, you can modify the expected number of instances based on your business requirements.

  • You can call an API operation to disable the Expected Number of Instances feature. For more information, see ModifyScalingGroup.

Basic concepts

Before you use the Expected Number of Instances feature, we recommend that you understand the concepts described in the following table.

Concept

Description

Steady-state instance

An instance that is in the In Service, Protected, or Standby state in a scaling group.

Parallel scaling activity

A scaling activity that can be executed in parallel with other ongoing scaling activities in a scaling group. Parallel scaling activities can be triggered by the following actions:

  • Execute a scaling rule manually or by using a scheduled task.

  • Manually add or remove instances.

  • Check the expected number of instances, instance health, minimum number of instances, and maximum number of instances.

Non-parallel scaling activity

A scaling activity that cannot be executed in parallel with other ongoing scaling activities in a scaling group. A scaling activity that is not a parallel scaling activity is a non-parallel scaling activity. Non-parallel scaling activities can be triggered by the following actions:

  • Execute a scaling rule by using an event-triggered task.

  • Manually execute a rebalancing task on the Instances tab.

  • Automatically supplement preemptible instances.

    Note

    If you set the Scaling Policy parameter to Cost Optimization Policy and turn on the Enable Supplemental Preemptible Instances switch when you create a scaling group, Auto Scaling creates preemptible instances to supplement the instances that are going to be reclaimed in five minutes.

Limits

  • Scaling groups for which the Expected Number of Instances feature is enabled cannot have parallel scaling activities and non-parallel scaling activities in progress at the same time.

  • You must set the Expected Number of Instances parameter to a value that ranges from the Minimum Number of Instances value to the Maximum Number of Instances value.

Change patterns of the expected number of instances

You can manually specify an expected number of instances. You can also manually execute scaling activities to modify the expected number of instances. The change patterns of the expected number of instances vary based on how scaling activities are triggered.

Scaling activity type

Method to trigger a scaling activity

Scaling activity result

Change pattern

Example

Parallel scaling activities

Manually execute a scaling rule.

Only the expected number of instances is changed. You must wait for Auto Scaling to perform a check on the new expected number of instances to determine whether to add or remove instances.

Number of steady-state instances ± Number of scaled instances

Scenario:

  • Current expected number of instances: 3

  • Current number of steady-state instances: 2

The add3 scaling rule specifies to create four ECS instances.

Result:

The expected number of instances is changed to 6, but the Elastic Compute Service (ECS) instances are not immediately created. You must wait for Auto Scaling to check the expected number of instances to determine whether to create instances.

Execute a scaling rule by using a scheduled task.

Only the expected number of instances is changed. You must wait for Auto Scaling to check the new expected number of instances to determine whether to add or remove instances.

Number of steady-state instances ± Number of scaled instances

Scenario:

  • Current expected number of instances: 3

  • Current number of steady-state instances: 2

The add3 scaling rule specifies to create four ECS instances.

Result:

The expected number of instances is changed to 6, but the ECS instances are not immediately created. You must wait for Auto Scaling to check the expected number of instances to determine whether to create instances.

Manually add instances.

The instances are immediately added, and the expected number of instances is changed.

Current expected number of instances + Number of manually added instances

Scenario:

  • Current expected number of instances: 3

  • Current number of steady-state instances: 2

Manually add four ECS instances to the scaling group.

Result:

Four ECS instances are added to the scaling group. The number of steady-state instances is changed to 6, and the expected number of instances is changed to 7.

Manually remove instances.

The instances are immediately removed, and the expected number of instances is changed.

Current expected number of instances - Number of manually removed instances

Scenario:

  • Current expected number of instances: 3

  • Current number of steady-state instances: 2

Manually remove one ECS instance from the scaling group.

Result:

One instance is removed from the scaling group. The number of steady-state instances is changed to 1, and the expected number of instances is changed to 2.

Check the minimum and maximum numbers of instances.

-

To be manually specified

Scenario:

  • Current maximum number of instances: 5

  • Current minimum number of instances: 0

  • Current expected number of instances: 3

  • Current number of steady-state instances: 2

Attempt to change the maximum number of instances to 1.

Result:

The maximum number failed to be changed. You must change the expected number of instances at the same time.

Check the health status of instances.

The instances are immediately removed from the scaling group.

The expected number of instances remains unchanged.

Scenario:

  • Current expected number of instances: 3

  • Current number of steady-state instances: 2

One ECS instance is considered unhealthy.

Result:

The expected number of instances remains unchanged. The unhealthy instance is removed from the scaling group, and the number of steady-state instances is changed to 1. Auto Scaling detects the difference between the expected number of instances and the number of steady-state instances, and checks the health status of the expected number of instances to create two ECS instances.

Check the expected number of instances.

The instances are immediately added to or removed from the scaling group.

The expected number of instances remains unchanged.

Scenario:

  • Current expected number of instances: 3

  • Current number of steady-state instances: 2

Result:

The expected number of instances remains unchanged. Auto Scaling detects the difference between the expected number of instances and the number of steady-state instances and checks the expected number of instances to create one ECS instance.

Non-parallel scaling activities

Execute a scaling rule by using an event-triggered task.

The instances are immediately added to or removed from the scaling group, and the specified expected number of instances is changed.

Number of steady-state instances ± Number of scaled instances

Scenario:

  • Current expected number of instances: 3

  • Current number of steady-state instances: 2

The add3 scaling rule specifies to create four ECS instances.

Result:

A scaling activity is triggered to create four instances, and the expected number of instances is changed to 6.

Note

For more information about how to specify an expected number of instances, see Examples of parallel scaling activities and Examples of non-parallel scaling activities.

Differences between scaling groups with an expected number of instances and scaling groups without an expected number of instances

The following table describes the differences between scaling groups with an expected number of instances and scaling groups without an expected number of instances.

Item

With an expected number of instances

Without an expected number of instances

Maintenance costs

Automatic maintenance: Auto Scaling automatically scales instances to maintain the expected number of instances in a scaling group. If a scaling activity fails in the scaling group, Auto Scaling automatically retries the failed scaling activity.

Manual maintenance: You must manually adjust the number of instances in a scaling group. If a scaling activity fails in the scaling group, you must manually retry the failed scaling activity.

Execution results of scaling activities

The execution results of scaling activities vary based on how scaling rules are executed.

  • If you manually execute a scaling rule or if you use a scheduled task to execute a scaling rule in a scaling group, Auto Scaling does not immediately trigger a scaling activity. Auto Scaling just automatically changes the expected number of instances. During the check on the expected number of instances, Auto Scaling calculates the difference between the number of steady-state instances and the expected number of instances and scales instances based on the difference.

  • If you manually add instances to or remove instances from a scaling group, manually delete instances, or use an event-triggered task to execute a scaling rule, Auto Scaling immediately triggers a scaling activity and automatically changes the expected number of instances.

If you manually execute a scaling rule, use an event-triggered task or scheduled task to execute a scaling rule, manually add instances to or remove instances from a scaling group, or manually delete instances, Auto Scaling immediately triggers a scaling activity to add or remove instances.

Execution of parallel scaling activities

Scaling groups support the execution of parallel scaling activities. For more information, see Examples of parallel scaling activities.

A scaling group supports only one scaling activity at a time. The scaling activity may take a long time to execute. During this period, you cannot adjust the number of instances in the scaling group.

Examples of parallel scaling activities

After you specify the expected number of instances, Auto Scaling can execute parallel scaling activities at the same time.

  • Example 1: Manually execute scaling rules in a consecutive manner

    Scenario:

    • Expected number of instances: 3

    • Number of steady-state instances: 3

    • The add3 scaling rule specifies to create three ECS instances.

    • The add1 scaling rule specifies to create one ECS instance.

    • Manually execute the add3 scaling rule and the add1 scaling rule in sequence.

    Result: After the add3 scaling rule is executed, the expected number of instances is changed from 3 to 6. After you execute the add1 scaling rule, the expected number of instances is changed from 6 to 4. The purpose of the parallel scaling activity is to create one ECS instance. After the scaling activity is completed, the number of steady-state instances in the scaling group is 4. 示例1

  • Example 2: Manually execute a scaling rule and add instances at the same time

    Scenario:

    • Expected number of instances: 3

    • Number of steady-state instances: 3

    • The add1 scaling rule specifies to create one ECS instance.

    • Manually execute the add1 scaling rule and add an existing ECS instance at the same time.

    Result: After the add1 scaling rule is executed, the expected number of instances is changed from 3 to 4. After you add one existing ECS instance to the scaling group, the expected number of instances is changed from 4 to 5. The purpose of the parallel scaling activity is to create one ECS instance and add an existing ECS instance. After the scaling activity is completed, the number of steady-state instances is changed to 5. 示例2

Examples of non-parallel scaling activities

After you specify the expected number of instances, Auto Scaling cannot execute parallel and non-parallel scaling activities at the same time. Example:

Scenario:

  • Expected number of instances: 1

  • Number of steady-state instances: 1.

  • The scaling rule associated with an event-triggered task specifies to create three ECS instances.

  • The add1 scaling rule specifies to create one ECS instance.

  • You trigger the event-trigger task and then manually execute the add1 scaling rule.

Result: The event-triggered task takes effect and the expected number of instances is changed from 1 to 4. Since the scaling activity triggered by the event-triggered task is a non-parallel scaling activity, your request to execute the add1 scaling rule is rejected. The expected number of instances remains 4. The purpose of the non-parallel scaling activity is to create three ECS instances. After the non-parallel scaling activity is completed, the number of steady-state instances is 4.非并行活动示例