All Products
Search
Document Center

Auto Scaling:Combine scaling policies and scale-in policies

Last Updated:Feb 29, 2024

When you create or modify a scaling group, you can combine a scaling policy and a scale-in policy to control the instance removal sequence during scale-ins. Auto Scaling automatically removes Elastic Compute Service (ECS) instances that meet the requirements defined in the policies from scaling groups. This eliminates the need for manual intervention and automates business management. This topic describes the effective methods of the combination of the policies and provides examples to help you create policy combinations suitable for your business scenarios.

Background information

To remove an ECS instance, you must combine a scaling policy and a scale-in policy. The two policies together determine how an ECS instance is removed.

Note
  • For more information about how to specify policies to remove instances from scaling groups, see Manage scaling groups.

  • If a scaling group contains multiple ECS instances that meet the requirements defined in the policy combination, Auto Scaling randomly removes an ECS instance from the scaling group during a scale-in.

  • If you do not want to remove an ECS instance that is manually added from a scaling group, put the ECS instance into the Protected state.

Scaling policy

You can configure a scaling policy for a scaling group to add or remove ECS instances based on factors such as zones and resource costs. During scale-ins, Auto Scaling removes the ECS instances that meet the requirements of the configured scaling policy from the scaling group. Auto Scaling supports the following types of scaling policies:

  • Priority policy: The first vSwitch that you specified has the highest priority. Auto Scaling scales instances in the zone where the vSwitch of the highest priority resides. If the scaling fails, Auto Scaling scales instances in the zone where the vSwitch of the next highest priority resides.

  • Balanced distribution policy: This policy takes effect only when your scaling group is associated with multiple vSwitches that reside in different zones. After Auto Scaling scales ECS instances, the distribution of the ECS instances is balanced across the zones.

  • Cost optimization policy: This policy takes effect only if your scaling configuration has multiple instance types. Auto Scaling preferentially creates ECS instances that have the lowest unit price of vCPUs during scale-outs. Auto Scaling preferentially removes ECS instances that have the highest unit price of vCPUs during scale-ins.

    Note

    If your scaling configuration has multiple preemptible instance types, Auto Scaling preferentially creates preemptible instances. Auto Scaling creates pay-as-you-go ECS instances only when preemptible instances cannot be created due to insufficient inventory.

  • Custom combination policy: You can create a custom combination policy. You can use a custom combination policy to adjust the ratio of pay-as-you-go instances to preemptible instances, balance the distribution of ECS instances across zones, and select the instance types that meet your business requirements.

Scale-in policy

The Scale-in Policy feature of Auto Scaling takes effect based on a time order. When you configure a scale-in policy, you must configure one to two steps in the Auto Scaling console.

  • If you configure only one step, Auto Scaling filters ECS instances only based on the requirements defined in the step.

  • If you configure two steps, Auto Scaling first filters ECS instances based on the requirements defined in the first step and then filters ECS instances from the result based on the requirements defined in the second step.

You can configure the two steps in the following manners:

  • Earliest Instance Created Using Scaling Configuration: Auto Scaling removes instances that are created based on the earliest scaling configuration or the earliest launch template. No scaling configuration or launch template is associated with instances that are manually added to the scaling group. Therefore, instances that are manually added are not removed first. If more instances need to be removed from a scaling group after Auto Scaling removes all instances with which the earliest scaling configuration or the earliest launch template is associated, Auto Scaling removes manually added instances in a random manner.

    Note

    The scaling configuration source in the Earliest Instance Created Using Scaling Configuration setting can be a scaling configuration or a launch template.

    The version of a launch template does not indicate the order in which the template is added. For example, if you specify the lt-foress V2 launch template when you create a scaling group, and then replace the template with the lt-foress V1 launch template when you modify the scaling group, Auto Scaling considers the lt-foress V2 launch template as the earliest template.

  • Earliest Created Instance: Auto Scaling removes the instances that are created at the earliest point in time.

  • Most Recent Created Instance: Auto Scaling removes the instances that are created at the most recent point in time.

  • Custom Policy: Auto Scaling removes instances from the scaling group based on a custom policy. The custom policy contains a service. service version, and function.

Examples of ECS instance removal

In the following examples, the ECS instances that are described in the following table are used. The scenario-specific examples show how Auto Scaling removes an ECS instance from the sample scaling group based on the combination of a scaling policy and a scale-in policy.

Note

The ECS instance data in the following table is used for reference only. The data displayed in the Auto Scaling console shall prevail.

Instance ID

Zone

Added at

Scaling configuration

(asc-1 was added at the earliest point in time)

Unit price of vCPUs (USD)

i-1

Hangzhou Zone H

11:05:00 May 17, 2021

asc-1

1

i-2

Hangzhou Zone I

11:05:00 May 18, 2021

asc-1

2

i-3

Hangzhou Zone I

11:05:00 May 19, 2021

asc-1

3

i-4

Hangzhou Zone H

11:05:00 May 20, 2021

asc-2

3

i-5

Hangzhou Zone I

11:05:00 May 21, 2021

asc-2

3

Scenario 1: Priority policy + scale-in policy

Auto Scaling filters out the ECS instance that meets the requirements of the scale-in policy. The priority policy does not affect the filtering result.

In this example, a custom combination policy is defined in the first step of the scale-in policy. The zones are Hangzhou Zone I and Hangzhou Zone H. The instance IDs are i-1 and i-3. The following table describes the instance removal effect.

First step

Second step

Instance removal effect

Removed instance ID

Instances created by using the earliest scaling configuration

Earliest created instances

Auto Scaling filters out the ECS instance that is created by using the earliest scaling configuration, and then filters out the ECS instance that is created at the earliest point in time from the result.

i-1

Most recent created instances

Auto Scaling filters out the ECS instance that is created by using the earliest scaling configuration, and then filters out the ECS instance that is created the most recently from the result.

i-3

No policy

Auto Scaling filters out the ECS instance that is created by using the earliest scaling configuration, and then randomly selects an ECS instance from the result to remove.

  • i-1

  • i-2

  • i-3

Earliest created instances

-

Auto Scaling removes the ECS instance that is created at the earliest point in time.

i-1

Most recent created instances

-

Auto Scaling removes the ECS instance that is created the most recently.

i-5

Custom policy

Instances created by using the earliest scaling configuration

Auto Scaling first filters out the ECS instance that meets the requirements of the custom policy, and then selects the ECS instance that is created by using the earliest scaling configuration from the result to remove.

i-1

Earliest created instances

Auto Scaling first filters out the ECS instance that meets the requirements of the custom policy, and then selects the ECS instance that is created at the earliest point in time from the result to remove.

i-1

Most recent created instances

Auto Scaling first filters out the ECS instance that meets the requirements of the custom policy, and then selects the ECS instance that is created the most recently to remove.

i-3

No policy

Auto Scaling first filters out the ECS instance that meets the requirements of the custom policy, and then randomly selects an ECS instance from the result to remove.

  • i-1

  • i-3

Scenario 2: Balanced distribution policy + scale-in policy

Auto Scaling filters out the zones of ECS instances based on the balanced distribution policy, and then removes the ECS instance that meets the requirements of the scale-in policy from the scaling group. The distribution of the remaining ECS instances is balanced across the zones. In the example, the following rules take effect:

  • Hangzhou Zone I has one more ECS instance than Hangzhou Zone H. Therefore, Auto Scaling filters out ECS instance i-2, ECS instance i-3 and ECS instance i-5 of Hangzhou Zone I based on the balanced distribution policy.

  • If a custom policy is defined in the first step of the scale-in policy, Auto Scaling filters out ECS instance i-1 of Hangzhou Zone H based on the custom policy.

The following table describes the instance removal effect.

First step

Second step

Description

Removed instance ID

Instances created by using the earliest scaling configuration

Earliest created instances

Auto Scaling filters out the ECS instance that is created by using the earliest scaling configuration, and then filters out the ECS instance that is created at the earliest point in time from the result.

i-2

Most recent created instances

Auto Scaling filters out the ECS instance that is created by using the earliest scaling configuration, and then filters out the ECS instance that is created the most recently from the result.

i-3

No policy

Auto Scaling filters out the ECS instance that is created by using the earliest scaling configuration, and then randomly selects an ECS instance from the result to remove.

  • i-2

  • i-3

Earliest created instances

-

Auto Scaling removes the ECS instance that is created at the earliest point in time.

i-2

Most recent created instances

-

Auto Scaling removes the ECS instance that is created the most recently.

i-5

Custom policy

Instances created by using the earliest scaling configuration

Auto Scaling first filters out the ECS instance that meets the requirements of the custom policy, and then selects the ECS instance that is created by using the earliest scaling configuration from the result to remove.

i-3

Earliest created instances

Auto Scaling first filters out the ECS instance that meets the requirements of the custom policy, and then selects the ECS instance that is created at the earliest point in time from the result to remove.

i-3

Most recent created instances

Auto Scaling first filters out the ECS instance that meets the requirements of the custom policy, and then selects the ECS instance that is created the most recently to remove.

i-3

No policy

Auto Scaling first filters out the ECS instance that meets the requirements of the custom policy, and then randomly selects an ECS instance from the result to remove.

i-3

Scenario 3: Cost optimization policy + scale-in policy

Auto Scaling preferentially removes the ECS instance that has the highest unit price of vCPUs from the scaling group based on the cost optimization policy. If the scaling group contains multiple ECS instances that have the highest unit price of vCPUs at the same time, Auto Scaling removes ECS instances based on the scale-in policy. In the example, the highest unit price of vCPUs is USD 3.

  • Auto Scaling filters out ECS instance i-3, ECS instance i-4, and ECS instance i-5 based on the cost optimization policy.

  • If a custom policy is defined in the first step of the scale-in policy, Auto Scaling filters out ECS instance i-1 of Hangzhou Zone H and ECS instance i-3 of Hangzhou Zone I based on the custom policy.

The following table describes the instance removal effect.

First step

Second step

Description

Removed instance ID

Instances created by using the earliest scaling configuration

Earliest created instances

Auto Scaling filters out the ECS instance that is created by using the earliest scaling configuration, and then filters out the ECS instance that is created at the earliest point in time from the result.

i-3

Most recent created instances

Auto Scaling filters out the ECS instance that is created by using the earliest scaling configuration, and then filters out the ECS instance that is created the most recently from the result.

i-3

No policy

Auto Scaling filters out the ECS instance that is created by using the earliest scaling configuration, and then randomly selects an ECS instance from the result to remove.

i-3

Earliest created instances

-

Auto Scaling removes the ECS instance that is created at the earliest point in time.

i-3

Most recent created instances

-

Auto Scaling removes the ECS instance that is created the most recently.

i-5

Custom policy

Instances created by using the earliest scaling configuration

Auto Scaling first filters out the ECS instance that meets the requirements of the custom policy, and then selects the ECS instance that is created by using the earliest scaling configuration from the result to remove.

i-3

Earliest created instances

Auto Scaling first filters out the ECS instance that meet the requirements of the custom policy, and then selects the ECS instance that is created at the earliest point in time from the result to remove.

i-3

Most recent created instances

Auto Scaling first filters out the ECS instance that meets the requirements of the custom policy, and then selects the ECS instance that is created the most recently to remove.

i-3

No policy

Auto Scaling first filters out the ECS instance that meets the requirements of the custom policy, and then randomly selects an ECS instance from the result to remove.

i-3

References