This topic describes how to configure a cost optimization policy for a scaling group. A cost optimization policy can be used to create multiple types of Elastic Compute Service (ECS) instances in different zones. This increases the chance of successful scaling and reduces the cost.

Prerequisites

  • Before you perform the operations provided in the tutorial, you must have registered an Alibaba Cloud account. To create an Alibaba Cloud account, click Create a new Alibaba Cloud account.
  • A Virtual Private Cloud (VPC) is created. For more information, see Create a VPC.
  • Multiple VSwitches are created in different zones of the VPC. For more information, see Create a VSwitch.

Background information

Auto Scaling supports creating ECS instances of multiple types in a scaling group. You can specify multiple instance types in a scaling configuration. Auto Scaling creates instances based on the priorities of the instance types. If an instance of the type with the highest priority cannot be created, Auto Scaling creates an instance of the type with the next highest priority. The same rule applies to the rest instance types until an instance is created. This increases the chance of successful scaling when instances of a specified type are insufficient in the inventory. During the business peak periods, ECS instances must be created in time to bear traffic. In this case, the system must focus on creating ECS instances with sufficient performance to meet business requirements, instead of creating ECS instances of a specified type. We recommend that you specify multiple instance types to guarantee that instances can be created.

Auto Scaling supports creating ECS instances in different zones. You can select VSwitches in multiple zones when you create a scaling group. If the zone where a VSwitch resides does not have sufficient ECS instances in stock, Auto Scaling attempts to create instances in other zones. This increases the chance of successful scaling. After configuring multiple zones, you can also configure a multi-zone scaling policy based on your actual business needs. Multi-zone scaling policies include priority policies, distribution balancing policies, and cost optimization policies.
Note
  • Multi-zone scaling policies are available only for VPC-connected scaling groups.
  • The multiple-zone scaling policy of a scaling group cannot be modified.

Auto Scaling cannot create a preemptible instance when the market price of the instance exceeds your bid. This may delay scale-out activities and then affect your service. To avoid this issue, you can configure a cost optimization policy as the multi-zone scaling policy. With this policy, when failing to create a preemptible instance, Auto Scaling attempts to create a pay-as-you-go instance of the same type. This guarantees a high success rate for scaling activities and controls the cost. You can configure a cost optimization policy and multiple instance types at the same time to further increase the chance of successful scaling. Scaling groups that apply cost optimization policies attempt to create ECS instances based on the unit prices of vCPUs, from low to high. Even if you set the billing method of instances to pay-as-you-go, a cost optimization policy guarantees that you can use ECS instance resources at the lowest cost.

Procedure

  1. Create a scaling group.
    This step describes parameters related to the multi-zone scaling policy. For more information about other parameters of the scaling group, see Create a scaling group.
    1. Set the network type to VPC and select multiple VSwitches of the VPC.
      A VSwitch belongs to only one zone. After you configure multiple VSwitches for the scaling group, the scaling group can create ECS instances in multiple zones. This helps you utilize available ECS resources in different zones based on your requirements.
    2. Set the multi-zone scaling policy to Cost Optimization.
    3. Set other parameters as required.
  2. Create a scaling configuration.
    This step describes parameters related to the multi-zone scaling policy. For more information about other parameters of the scaling configuration, see Create a scaling configuration.
    1. Set the billing method to Preemptible Instance.
    2. Select instance types. You can select up to 10 instance types.
      • We recommend that you select instance types with similar performance in terms of the vCPU, memory, physical processor, clock speed, internal network bandwidth, or packet forwarding rate.
      • We recommend that you set a maximum bid for each instance type. If you use automatic bidding, the scaling group bids for and creates preemptible instances at the market price.
      • The specifications of I/O optimized instances vary greatly from those of non-I/O optimized instances. If you choose these two types of instances at the same time, the success rate of scaling activities cannot be increased significantly.
    3. Set other parameters as required.
  3. Enable the scaling group.
  4. Create a scaling rule.
    This step describes parameters for creating a simple rule to verify the cost optimization policy. For more information about other parameters of the scaling rule, see Create a scaling rule.
    1. Set the rule type to Simple Scaling Rule.
    2. In the Operation field, specify that one ECS instance is added after the scaling rule is triggered.
    3. Set other parameters as required.
  5. Execute the scaling rule.

Verification

Assume that in the preceding procedure, you have selected a VSwitch in Zone B of China (Qingdao) and a VSwitch in Zone C of China (Qingdao) for the scaling group, and selected the ecs.sn1.large and ecs.sn1.xlarge instance types for the scaling configuration. The billing method is set to Preemptible Instance. Therefore, instances of a specified type have two unit prices of vCPUs. One is for preemptible instances, and the other is for pay-as-you-go instances.
Notice The prices listed in this topic are used only as examples. Refer to the purchase page of ECS instances for actual prices.
Based on the preceding settings of the instance types and billing method, you have four plans for creating instances. The following table lists the four plans by vCPU unit price from low to high.
No. Instance type Billing method vCPU Market price of instance (RMB per hour) Unit price of vCPU (RMB per hour)
Plan 1 ecs.sn1.xlarge Preemptible instance 8 0.158 0.01975
Plan 2 ecs.sn1.large Preemptible instance 4 0.088 0.022
Plan 3 ecs.sn1.xlarge Pay-as-you-go 8 1.393 0.174125
Plan 4 ecs.sn1.large Pay-as-you-go 4 0.697 0.17425

Expected process for creating instances: In a scale-out activity, Auto Scaling creates ECS instances based on Plan 1. If such instances are unavailable in both Zone B and Zone C, Auto Scaling attempts to create ECS instances based on Plan 2, Plan 3, and Plan 4 in sequence.

Execute the scaling rule to trigger a scale-out activity in which an ECS instance is created and added to the scaling group. Go to the Instances page of the ECS console and click the created ECS instance to view its instance type and billing method. In this example, the instance type is ecs.sn1.xlarge and the billing method is Pay-As-You-Go-Preemptible Instance. This indicates that the cost is reduced.