This topic describes how to use pay-as-you-go and preemptible Elastic Compute Service (ECS) instances in Auto Scaling to respond to expected fluctuations in traffic and save your money.
An online education platform experiences traffic peaks from 17:00 to 22:00 every day. However, during other times of the day, the business traffic drops. To ensure that the platform can provide services during peak hours, the number of computing resources is adjusted based on the traffic during peak hours. During off-peak hours, these resources are idle, which results in a large amount of unnecessary costs. Furthermore, when the platform experiences unexpected traffic spikes, ECS instances must be manually created to ensure service availability.
- The application is deployed in a cluster that has at least one server.
- The application is highly fault-tolerant and can still run in the event of a failure. Example: the test service that is deployed on a preemptible instance.
- The application has predictable traffic patterns. For example, traffic peaks occur from 17:00 to 22:00 every day and the computing resources are idle during other times of the day.
Auto Scaling combines pay-as-you-go and preemptible instances to handle expected fluctuations in traffic at lower costs.
- You can purchase subscription ECS instances to handle stable traffic.
- You can create scheduled tasks to add ECS instances during peak hours and release ECS instances during off-peak hours. Details:
- During peak hours, Auto Scaling creates and adds the required number of ECS instances of multiple instance types as scheduled. Auto Scaling combines pay-as-you-go instances and preemptible instances to reduce costs. Auto Scaling preferentially creates instances of the instance type that uses the vCPU provided at the lowest price.
- During off-peak hours, Auto Scaling releases the ECS instances that are no longer needed as scheduled.
- Zero cost of backup resources
Auto Scaling creates and releases ECS instances based on your business requirements. You do not need to prepare backup resources. You need to only reserve computing resources for traffic that has stable patterns.
- Zero O&M costs
You can configure scaling policies before peak hours. When the traffic increases, Auto Scaling creates and adds ECS instances to the backend server group of the associated Server Load Balancer (SLB) instance, and adds the IP addresses of the ECS instances to the whitelist that manages access to the associated ApsaraDB RDS instance. The entire process is automatically triggered and completed without the need for manual operations.
Auto Scaling combines pay-as-you-go and preemptible instances. You can save up to 90% of costs when you purchase preemptible instances. If the preemptible instances are insufficient, pay-as-you-go instances are created to ensure service availability. The Enable Supplemental Preemptible Instances feature is supported when you select the cost optimization policy. After you enable this feature, Auto Scaling creates preemptible instances that are provided at a lower price five minutes before the system releases the existing preemptible instances.
Step 1: Use a custom image to create subscription ECS instances
Create a specified number of subscription ECS instances based on the requirements of business modules that have stable traffic patterns, and add the ECS instances to your scaling group.
- Log on to the ECS console.
- In the left-side navigation pane, choose .
- In the top navigation bar, select a region.
- Find the custom image that you want to use to create subscription ECS instances and click Create Instance in the Actions column.
- Configure the parameters that are required to create the instances.
- Set Billing Method to Subscription.
- Information in the Region and Image sections is automatically populated.
For information about how to configure other parameters, see Create an instance by using the wizard.
Step 2: Create and enable a scaling group
Create a scaling group for business modules that require lower costs. Select a custom image for the scaling configuration to ensure that automatically created ECS instances meet application requirements.
- 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.
- Create a scaling group.
- Set Scaling Group Name to a custom name. In this example, testname is used.
- Set Instance Configuration Source to Create from Scratch.
- Set Minimum Number of Instances to 0.
- Set Maximum Number of Instances to 10.
- Set Default Cooldown Time (Seconds) to 300.
- Set Network Type to VPC.
- Set Scaling Policy to Cost Optimization Policy.
- Set Minimum Pay-as-you-go Instances to 0.
- Set Percentage of Pay-as-you-go Instances to 30.
- Set Lowest Cost Instance Types to 3.
- Turn on Enable Supplemental Preemptible Instances.
- Turn on Use Pay-as-you-go Instances to Supplement Preemptible Capacity. By default, this feature is enabled.
- Set Instance Reclaim Mode to Release.
- Select a virtual private cloud (VPC) and one or more vSwitches that you created.
- Associate the SLB and ApsaraDB RDS instances that are required by your current business modules with the scaling group.
Configure other parameters based on your business requirements. For more information, see Manage scaling groups.
- Find the scaling group that you created and click Details in the Actions column.
- In the upper part of the page, click the Instance Configuration Sources tab.
- Create a scaling configuration.
- Set Billing Method to Preemptible Instance.
- Select at least three instance types.
- Set Image to Custom Image and select an image.
Configure other parameters based on your business requirements. For more information, see Create scaling configurations for scaling groups that contain ECS instances.
- Enable the scaling configuration and the scaling group.
Step 3: Add subscription ECS instances and configure the automatic scaling policy
Add subscription ECS instances to the scaling group and create scheduled tasks to enable automatic scaling based on business changes. You can significantly reduce costs by combining subscription and preemptible instances.
- On the Instances tab, add the created subscription ECS instances to the scaling group.
- Put the subscription ECS instances into the Protected state to ensure service availability when the traffic is stable.
- On the Basic Information tab, change the minimum and maximum numbers of instances in the scaling group based on your business requirements. For more information about how to change the maximum and minimum numbers of instances in a scaling group, see Modify scaling groups.
- On the Scaling Rules tab, create two simple scaling rules. You must configure the following parameters:
- Set Rule Type to Simple Scaling Rule.
- The following rules apply when you configure the Operation parameter:
- For simple scaling rule 1, select Add and enter 5. This rule specifies that five instances are added during a scale-out activity.
- For simple scaling rule 2, select Remove and enter 5. This rule specifies that five instances are removed during a scale-in activity.
Configure other parameters based on your business requirements. For more information, see Manage scaling rules.
- On the Scheduled Task tab, create two scheduled tasks.
- The following rules apply when you configure the Executed At parameter:
- For scheduled task 1, set Executed At to Nov 20, 2021 4:59 PM if the peak hours start from 5:00 PM. In this case, the scale-out activity is triggered at the specified point in time.
- For scheduled task 2, set Executed At to Nov 20, 2021 9:59 PM if the off-peak hours start from 10:00 PM. In this case, the scale-in activity is triggered at the specified point in time.
- Select the scaling group to which you want to add subscription ECS instances for the Scaling Group parameter.
- Set Scaling Method to Select Existing Scaling Rule.
- The following rules apply when you configure the Simple Scaling Rule parameter:
- For scheduled task 1, select simple scaling rule 1 for the expected peak hours.
- For scheduled task 2, select simple scaling rule 2 for the expected off-peak hours.
Configure other parameters based on your business requirements. For more information, see Create a scheduled task.
- The following rules apply when you configure the Executed At parameter:
On the Scaling Activities tab, you can view the details of scaling activities and check whether the instances in the scaling group are scaled as scheduled. For more information, see View the details of a scaling activity.
- The subscription ECS instances are put into the Protected state. The ECS instances are prepared for traffic that has stable patterns. The ECS instances in the Protected state are not removed from the scaling group. The weights of these instances as backend servers of the associated SLB instances are not affected.
- Auto Scaling scales out ECS instances during peak hours based on the scheduled tasks that you created. After you configure the cost optimization policy and enable the Enable Supplemental Preemptible Instances feature, you can purchase ECS instances at lower costs.
- Auto Scaling scales in ECS instances during off-peak hours based on the scheduled tasks that you created.