Auto Scaling is an Alibaba Cloud service that automatically adjusts the number of Elastic Compute Service (ECS) instances based on workload changes and scaling policies. It helps to ensure sufficient computing resources, prevent idle resources, and reduce costs. To effectively address workload fluctuations that do not have identifiable patterns, you can create event-triggered tasks in the Auto Scaling console to monitor workload fluctuations and enable automatic execution of scaling rules when metrics such as the CPU utilization reach the alerting thresholds. This allows for an automatic increase or decrease in the number of ECS instances to meet your business demands.
Scenario
Description
If your workload experiences dynamic fluctuations, you may find it challenging to determine the optimal number of servers and the timing for adding or removing servers. In this case, if you intend to adjust the server capacity based on real-time workloads, you can create event-triggered tasks in the Auto Scaling console.
For example, the traffic of a news website is unpredictable. A surge of page views occurs with breaking news, but the views drop when the news loses its timeliness.
Solution
You can create event-triggered tasks to monitor CloudMonitor metrics. This allows for automatic execution of scaling rules when the metric data reaches the alerting thresholds. By using this method, you can effectively enable automatic scaling of servers based on your business workloads.
Benefits
Zero upfront resource setup costs
Auto Scaling creates and releases ECS instances based on your business requirements, eliminating the need for any upfront costs related to resource setup. You only need to reserve computing resources for daily business traffic.
Automatic scaling
Auto Scaling is integrated with CloudMonitor to monitor fluctuations in workloads, thereby efficiently executing automatic scaling of ECS instances. This integration aids in meeting business demands while simultaneously reducing resource and O&M costs.
Prerequisites
The first time you use Auto Scaling, you must complete Resource Access Management (RAM) user authorization.
The AliyunServiceRoleForAutoScaling service-linked role is created. For more information, see Service-linked role.
If you use Auto Scaling as a RAM user, the RAM user must be granted the AliyunESSFullAccess policy. For more information, see Grant permissions to a RAM user.
Step 1: Create a scaling group
A scaling group refers to a group of instances designed to meet your business requirements, serving as the fundamental unit of Auto Scaling. Auto Scaling adds instances to or removes instances from scaling groups.
Enter the Scaling Groups page.
Log on to the Auto Scaling console.
In the left-side navigation pane, click Scaling Groups.
In the top navigation bar, select the region where Auto Scaling is activated.
In the upper-left corner of the Scaling Groups page, click Create.
On the Create by Form tab, configure parameters to complete group creation and click Create.
The following table describes the parameter settings used in this example. Parameters that are not covered in the following table default to their default settings. For information about how to create a scaling group, see Create scaling groups.
Parameter
Example
Description
Scaling Group Name
test
Enter a name for the scaling group. The name must adhere to the format requirements displayed on the UI.
Type
ECS
Select ECS, which specifies that the scaling group contains ECS instances.
Instance Configuration Source
Create from Scratch
The template for automatically creating instances is not designated first. Once the scaling group is created, you will need to proceed with creating a scaling configuration.
Minimum Number of Instances
1
Define the minimum number of instances in the scaling group. If the number of instances in the scaling group is less than the value of this parameter, Auto Scaling adds instances to the scaling group until the number of instances in the scaling group reaches the minimum number.
Maximum Number of Instances
5
Define the maximum number of instances in the scaling group. If the number of instances in the scaling group is greater than the value of this parameter, Auto Scaling removes instances from the scaling group until the number of instances in the scaling group does not exceed the maximum number.
Network Type
VPC
Select VPC, which specifies that the ECS instances in the scaling group reside in a virtual private cloud (VPC).
VPC
vpc-bp1jmxxau0lur929p****
Select a VPC for ECS instances in the scaling group.
vSwitch
vsw-2zeknnyw2ewufbs4z****
vsw-2zesy03h8eaf9fe0l****
Select one or more vSwitches for ECS instances in the scaling group. We recommend that you select multiple vSwitches to improve the success rate of scale-out events.
Step 2: Create a scaling configuration and enable the scaling configuration and scaling group
A scaling configuration is a template used to create ECS instances during scale-out events, containing information such as the billing method, instance type, storage, and network settings. After you create a scaling configuration, you can enable the scaling configuration and then proceed to enable the scaling group.
Find a scaling group and use one of the following methods to go to the scaling group details page:
Click the ID of the scaling group in the Scaling Group Name/ID column.
Click Details in the Actions column.
In the upper part of the scaling group details page, click the Instance Configuration Sources tab.
On the Scaling Configurations tab, click Create Scaling Configuration.
On the Create Scaling Configuration page, configure parameters to complete the process for creating a scaling configuration and click Create.
The following table describes the parameter settings used in this topic. Any parameters not covered in the following table default to their default settings. For more information about how to create a scaling configuration, see Create a scaling configuration of the ECS type.
Section
Parameter
Example
Description
Basic Information
Scaling Configuration Name
test
Enter a name for the scaling configuration. The name must adhere to the format requirements displayed on the UI.
Billing Method
Pay-as-you-go
Auto Scaling is free of charge. However, you must pay for the ECS instances that are created during scale-out events. In this example, the pay-as-you-go billing method is used. For more information, see Billing overview.
Instance and Image
Instance Configuration Mode
Specify Instance Pattern
Select Specify Instance Pattern to configure specifications for ECS instances.
Instance Attribute Combination
2 vCPUs, 4 GiB Memory, Enterprise Level
Define the number of vCPUs and memory size for ECS instances based on your business requirements.
Select Image
Public Image: Alibaba Cloud Linux 3.2104 LTS 64-bit
Select an image to deploy ECS instances. In this example, a public image is used. In actual business scenarios, you can select the custom image of your application.
Storage
System Disk
Enterprise SSD (ESSD), 40 GiB, and PL0
Select a system disk for ECS instances.
Network and Security Group
Public IP Address
Assign Public IPv4 Address, Pay-by-bandwidth, and 1 Mbit/s bandwidth
Specify whether to assign public IP addresses to ECS instances. You are charged for the outbound public bandwidth. The bandwidth fees are built into your ECS instance fees.
Security Group
sg-bp18kz60mefsicfg****
Select an existing security group. For more information about how to create a security group, see Create a security group.
Management Settings
Logon Credentials
Set Later
Select Set Later, which specifies that you must manually configure passwords for ECS instances after you create the ECS instances.
In the Preview Scaling Configuration dialog box, confirm the information and click Create.
In the The scaling configuration is created. message, click Enable.
In the Enable Scaling Configuration dialog box, click OK.
NoteIn a scaling group, you must enable one scaling configuration. After you enable the scaling configuration, the scaling configuration is in the Active state.
In the Enable Scaling Group message, click OK.
After you enable the scaling group, Auto Scaling triggers automatic instance scaling based on your business requirements.
In this example, the Minimum Number of Instances parameter is set to 1. Therefore, after you enable the scaling group, Auto Scaling automatically creates one ECS instance from the scaling configuration in the scaling group. You can go to the Instances tab of the scaling group details page and check the instance information on the Auto Created tab.
Step 3: Create scaling rules
A scaling rule specifies the action that adds instances to or removes instances from a scaling group.
On the details page of the scaling group, click the Scaling Rules and Event-triggered Tasks tab. Then, click the Scaling Rules tab.
Click Create Scaling Rule, configure parameters to complete the process for creating the scaling rule, and click OK.
In this example, simple scaling rules are created. For information about how to create a scaling rule, see Manage scaling rules.
Parameter
Description
Rule Name
Enter a name for the scaling rule. The name must adhere to the format requirements displayed on the UI.
Rule Type
In this example, simple scaling rules are created. For more information about scaling rules, see Overview.
Operation
Define the number of instances to add or remove when the scaling rule is executed. The number of instances to add or remove during each scaling event cannot exceed 1,000.
Cooldown Time
Optional. Define a cooldown period for the scaling rule. Unit: seconds. If you do not configure this parameter, the cooldown period of the scaling group takes effect. For more information, see Cooldown period.
Repeat this step to create scale-out and scale-in rules. Sample configurations:
Scaling rule
Example
Scale-out rule
Rule Name: add
Rule Type: Simple Scaling Rule
Operation: Add 1 Instance
Scale-in rule
Rule Name: remove
Rule Type: Simple Scaling Rule
Operation: Remove 1 Instance.
Step 4: Create event-triggered tasks
Event-triggered tasks are designed to monitor specific metrics and collect real-time metric values. When these values meet the alerting conditions, Auto Scaling will trigger alerts and execute the specified scaling rules.
On the details page of the scaling group, click the Scaling Rules and Event-triggered Tasks tab. Then, click the Event-triggered Tasks tab.
On the Event-triggered Tasks (System) tab, click Create Event-triggered Task, configure parameters to complete task creation, and click OK.
NoteIn this example, system metrics are specified in event-triggered tasks. You can also report custom metrics to CloudMonitor and specify the custom metrics in your event-triggered tasks. For more information, see Overview.
The following table describes the parameter settings used in this topic. Any parameters that are not covered in the following table default to their default settings. For more information about event-triggered tasks, see Manage event-triggered tasks.
Parameter
Description
Name
Enter a name for the event-triggered task. The name must adhere to the format requirements displayed on the UI.
Alert Condition
Define the condition under which alerts are reported when the metric data reaches a specified threshold. You must specify at least one metric. If you want to specify multiple metrics, click Add Metric.
Take note of the following items:
Metric: the name of the system metric that you want to monitor. For example, if you use the (ECS) CPU Utilization metric, the CPU utilization of all ECS instances in the scaling group is monitored.
Statistical method: the method that you want to use to determine whether the metric data exceeds a specified threshold. You can use Average, Maximum, or Minimum as the statistical method. For example, if you use the Average method and specify a rule which is Average >= 70%, an alert is triggered when the average CPU utilization of all ECS instances in the scaling group reaches or exceeds 70%.
Trigger Rule
Select the scaling rule that you want to execute when alerts are reported.
Repeat this step to create event-triggered tasks that trigger the execution of scale-out and scale-in rules. Sample configurations:
Event-triggered task
Example
Event-triggered task for scale-out purposes
Name: Alarm-add
Alert Condition: (ECS) CPU Utilization > Average (Average) > 70%
Trigger Rule: add
Event-triggered task for scale-in purposes
Name: alarm-remove
Alert Condition: (ECS) CPU utilization > Average(Average) < 20%
Trigger Rule: remove
Verify the effect of automatic scaling
After you create the event-triggered tasks, Auto Scaling continuously monitors the metric data of the scaling group in real time and executes the specified scaling rules when the alerting conditions are met.
In this example, the following results are achieved:
When the CPU utilization of ECS instances in the scaling group exceeds 70%, one ECS instance is automatically added to the scaling group.
When the CPU utilization of ECS instances in the scaling group drops below 20%, one ECS instance is automatically removed from the scaling group.
You can use the stress testing tool to simulate the test and confirm the scaling effect in the following ways:
When the event-triggered tasks are triggered, go to the scaling group details page and choose Instances > Auto Create. Then, check the changes in the number of instances.
When the event-triggered tasks are triggered, go to the scaling group details page and click the Scaling Activities tab. Then, check whether any scaling activity is generated. If a corresponding scaling activity is generated, click its ID to view the scaling activity details.