Scale-in guide

更新时间:
复制 MD 格式

When the resource demand for your business workloads decreases, your scaling group triggers a scale-in event based on your policies to automatically reduce the number of instances and avoid resource waste. This guide walks you through graceful scale-in practices.

Scale-in process

When a scale-in event occurs, the scaling group selects instances for removal based on your configured policies and then reclaims them according to the instance reclaim mode. You can configure actions at various stages of the scale-in process, as shown in the following figure:

image

Trigger a scale-in

Control scale-in boundaries

  • Method: Set the Minimum Number of Instances for the scaling group.

    The minimum number of instances is the lower boundary for scale-in. If a scale-in would reduce the instance count below this minimum, the activity is rejected, ensuring your scaling group retains enough capacity for your baseline workload.

  • Procedure: For more information, see Manage scaling groups.

Scale in by workload tiers

  • Method: Create a step scaling rule for the scaling group.

    A step scaling rule lets you scale in gradually based on workload tiers, preventing service interruptions caused by removing too many instances at once. For example, you can design a scale-in plan based on the average CPU utilization of your scaling group cluster:

    • Remove 5 instances when the average CPU utilization is below 20%.

    • Remove 3 instances when the average CPU utilization is below 30%.

    • Remove 1 instance when the average CPU utilization is below 50%.

    • To implement this, you can configure the following step scaling rule. In the Create Scaling Rule dialog box, set Monitoring Type to System Monitoring. For Execution Time, select the alarm task Low CPU Utilization (Average (Agent) CPU utilization is less than or equal to 50% for 3 consecutive times). Configure the rule to remove instances in steps: remove 1 instance when CPU utilization is between 30% and 50%, remove 3 instances when it is between 20% and 30%, and remove 5 instances when it is below 20%. Set instance warmup to 300 seconds.

  • Procedure: For more information, see Configure scaling rules.

Control scale-in speed and frequency

Set a cooldown period and the trigger frequency for alarm tasks to prevent business fluctuations caused by rapid scale-in activities.

Method 1: Set a cooldown period

  • Method: Set a default cooldown period for the scaling group and a cooldown period for scaling rules.

    A cooldown period is the minimum interval between two scaling activities triggered by alarm tasks, allowing you to control scale-in frequency.

  • Procedure: For more information, see Cooldown period.

Method 2: Set the trigger frequency for alarm tasks

  • Method: For an alarm task, configure parameters such as Statistical Period, Statistical Method, and Triggered After.

    These settings control how frequently the alarm task triggers scale-in activities.

  • Procedure: For more information, see Configure alarm tasks.

Method 3: Set the trigger frequency for a target tracking scaling rule

  • Method: Set the Threshold for Scale-in Alerts for the target tracking scaling rule.

    When you create a target tracking scaling rule, an alarm task is automatically created. This parameter controls how many consecutive times the threshold must be met before the scale-in alarm task triggers.

  • Procedure: For more information, see Target tracking scaling rules.

Customize scale-in triggers

Customize when to trigger a scale-in to suit your business requirements. The following methods are available.

Method 1: Manually execute a simple rule

You can trigger a scale-in by manually executing a Simple Scaling Rule. For more information, see Configure scaling rules.

Note

This method supports API calls. For more information about the APIs, see ExecuteScalingRule and ScaleWithAdjustment.

Method 2: Modify a scaling group's instance count settings to trigger a scale-in

You can trigger a scale-in activity by modifying the Maximum Instances or the Expected Number of Instances. The scaling group automatically scales in based on these settings. For more information, see Manage scaling groups.

Note

This method supports API calls. For more information about the API, see ModifyScalingGroup.

Select instances for scale-in

By default, a scaling group removes instances based on the vSwitch priority you configure. You can change the scale-in policy to select instances for removal based on your business needs.

Important
  • If you do not want a key instance to be scaled in, you can enable the Protected state for that instance to prevent it from being accidentally scaled in and affecting your normal business operations. For detailed instructions, see Manually add an instance to or remove an instance from the Protected state.

  • Elastic Container Instance (ECI) scaling groups do not support configuring a Scaling Policy or a Instance Removing Policy. By default, an ECI scaling group first selects the set of instances created by the oldest scaling configuration, and then removes the oldest instances from within that set.

Solution 1: Balanced distribution policy

This solution prioritizes disaster recovery by keeping instances evenly distributed across zones after a scale-in, helping achieve multi-zone high availability.

  • Method: Set the Scaling Policy to Balanced Distribution Policy.

    With this policy, the scaling group prioritizes removing instances from the zone with the most instances. If multiple instances are eligible for removal, the group then uses the configured Instance Removing Policy to make the final selection, such as removing the oldest or newest instances, or instances from the earliest scaling configuration.

  • Procedure: For more information, see Scenario 2: Scaling Policy (Balanced Distribution Policy) + Scale-In Policy.

Solution 2: Cost optimization policy

This solution prioritizes cost control by removing instances with the highest unit price first.

  • Method: Set the Scaling Policy to Cost Optimization Policy.

    With this policy, the scaling group prioritizes removing instances with the highest vCPU unit price. If multiple instances have the same highest price, the group then uses the configured Instance Removing Policy to make the final selection, such as removing the oldest or newest instances, or instances from the earliest scaling configuration.

  • Procedure: For more information, see Scenario 3: Scaling Policy (Cost Optimization Policy) + Scale-In Policy.

Note

This solution also allows you to configure the ratio of preemptible instances to pay-as-you-go instances in the scaling group to balance costs.

Solution 3: Custom combination policy

You can combine the strategies from Solution 1 and Solution 2 based on your business requirements.

  • Method: Set the Scaling Policy to Custom Combination Policy.

    This policy allows you to adjust the ratio of pay-as-you-go instances to preemptible instances, balance capacity across zones, and define separate capacity distribution strategies for each instance type.

  • Procedure: For more information, see Configure an instance termination policy for a scaling group.

Solution 4: Custom scale-in policy

If the built-in scale-in policies do not meet your needs, you can create a custom policy by using Function Compute.

  • Method: Set the Instance Removing Policy to Custom Policy.

    Define your custom scale-in logic in Function Compute. Each time a scale-in event triggers, your function is invoked, and you can specify which instances to remove and which to keep.

  • Procedure: For more information, see Customize an ECS instance removal policy by using a function.

Graceful scale-in

A graceful scale-in pauses the removal of instances that are still processing tasks, allowing them to finish before being released. This prevents service interruptions.

  • Method: Set up a Lifecycle Hook.

    A lifecycle hook pauses instance removal during scale-in so you can perform custom actions. You can also call an API to extend the hook's wait time, allowing the instance to finish its tasks before termination.

  • Procedure: For more information, see Overview of lifecycle hooks and Extend the wait time of a lifecycle hook.

Important

Directly removing, deleting, or stopping instances does not trigger lifecycle hooks. This method does not apply in these cases.

Reclaiming removed instances

By default, a scaling group uses the Force Release mode to reclaim instances, which immediately releases removed instances. To change the Instance Reclaim Mode, see Manage scaling groups.