This topic describes how to use Auto Scaling to purchase pay-as-you-go and preemptible ECS instances to reduce costs during predictable business peaks.

Prerequisites

Scenarios

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 is significantly lower. To ensure that the platform can deliver reliable services during peak hours, the number of compute resources is scaled based on the peak traffic loads. During off-peak hours, these resources are idle, which results in a large amount of wasted cost. Furthermore, when the platform experiences unexpected traffic spikes, ECS instances must be manually created to ensure service availability.

You can adopt the solutions provided in this topic if your application has the following characteristics:
  • Deployed in a cluster that has at least one server.
  • Has predictable traffic patterns. For example, traffic peaks occur from 17:00 to 22:00 each day and the compute resources are idle during other times of the day.

Solutions

Auto Scaling uses a combination of pay-as-you-go and preemptible instances to meet peak traffic requirements at lower costs.

You can adopt the following solutions:
  • Purchase subscription ECS instances to maintain a baseline compute capability for off-peak hours.
  • Specify multiple instance types and use a combination of pay-as-you-go and preemptible instances to scale compute capabilities for peak hours. Auto Scaling creates ECS instances based on unit prices of vCPUs in ascending order. Instances that use lowest-priced vCPUs are preferentially created.

Benefits

Auto Scaling enables you to reduce costs and offers the following benefits:
  • Zero backup resource cost

    Auto Scaling automatically creates and releases ECS instances based on your requirements. You do not need to maintain backup resources. You only need to reserve compute resources for off-peak hours.

  • Zero maintenance cost

    You can configure the scaling policy in advance. When the load increases, Auto Scaling automatically creates and adds ECS instances to the whitelist of the ApsaraDB for RDS instance and SLB backend server group. The whole process is automatically triggered and completed without the need for manual intervention.

  • High cost-effectiveness

    Auto Scaling supports the combination of pay-as-you-go and preemptible instances. You can purchase ECS instances at up to 90% discount. If the preemptible instances are insufficient, pay-as-you-go instances are created to ensure service availability. The cost optimization policy also supports supplemental preemptible instances. After this feature is enabled, Auto Scaling automatically creates preemptible instances at lowest price five minutes before existing preemptible instances are released.

Procedure

Evaluate business modules based on your business architecture and perform the following operations to reduce costs for required business modules:

Step 1: Use a custom image to create subscription ECS instances

Create and add the specified number of subscription ECS instances to a scaling group in response to off-peak traffic requirements of business modules. Perform the following operations:

  1. Log on to the ECS console.
  2. In the left-side navigation pane, choose Instances & Images > Images.
  3. In the top navigation bar, select a region.
  4. Find the custom image of the application and click Create Instance in the Actions column.
  5. Configure the parameters to create an instance.
    • Set Billing Method to Subscription.
    • Information in the Region and Image sections is automatically filled.

    Configure other parameters based on your needs. For more information, see Create an instance by using the provided 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. Perform the following operations:

  1. Log on to the Auto Scaling console.
  2. In the top navigation bar, select a region.
  3. Create a scaling group.
    • Set Source Type to Create from Scratch.
    • Set Minimum Number of Instances to 0.
    • Set Network Type to VPC.
    • Set Multi-zone 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.
      • Enable the supplemental preemptible instances mode.
    • Set Reclaim Mode to Release Mode.
    • Bind the SLB and ApsaraDB for RDS instances used by your current business modules.

    Configure other parameters based on your needs. For more information, see Create a scaling group.

  4. Click View Scaling Group Details.
  5. Go to the Instance Configuration Source page to create a scaling configuration.
    • Set Billing Method to Preemptible Instance.
    • Select at least three instance types.
    • Set Image to your custom image.

    Configure other parameters based on your needs. For more information, see Create a scaling configuration.

  6. Enable the scaling configuration and scaling group.

Step 3: Add subscription ECS instances and configure the automatic scaling policy

Add subscription ECS instances to a scaling group and create a step scaling rule to implement automatic and smooth scaling based on business changes. You can significantly reduce costs by using a combination of subscription and preemptible instances. Perform the following operations:

  1. Go to the ECS Instances page, and add existing subscription ECS instances to the scaling group.
  2. Switch the subscription ECS instances to the Protected state to ensure service availability during off-peak hours.
  3. Go to the Basic Information page, and modify the minimum and maximum numbers of instances in the scaling group based on business needs.
  4. Go to the Scaling Rules page, and create a step scaling rule.
    • Set Rule Type to Step Scaling Rule.
    • Set Monitoring Type to System Monitoring.
    • Set Run At to the time when the average CPU utilization is greater than 50% for three consecutive times.
    • Set Operation based on the following rules:
      • Add five instances when the average CPU utilization is greater than or equal to 60% and less than 70%.
      • Add 10 instances when the average CPU utilization is greater than or equal to 70%.

    Configure other parameters based on your needs. For more information, see Create a scaling rule.

Result

The state of subscription ECS instances is switched to Protected to ensure service availability during off-peak hours. The ECS instances in the Protected state cannot be removed from the scaling group, and their weights in SLB are not affected.

During peak hours, Auto Scaling automatically creates a specific number of ECS instances based on the average CPU utilization to implement smooth scaling. Due to the cost optimization policy and supplemental preemptible instances mode, you can purchase ECS instances at lower costs.