All Products
Search
Document Center

Auto Scaling:use preemptible instances to reduce costs

Last Updated:Dec 24, 2024

After you create a scaling group, you can apply an appropriate scaling policy to enhance resource utilization and cut costs. For additional savings, consider adding preemptible Elastic Compute Service (ECS) instances to the scaling group. This topic describes how to leverage preemptible instances for cost-effective cluster building.

Important

Only scaling groups of the ECS type can contain preemptible instances.

What is a preemptible instance?

Preemptible instances are on-demand instances offering the same performance as regular ECS instances, but at a lower cost. Their prices fluctuate based on market supply and demand, potentially saving up to 90% compared to pay-as-you-go instances. Preemptible instances provide the following features:

  • Same performance: Preemptible instances and pay-as-you-go instances that use the same specifications offer identical performance, differing only in the billing method.

  • Bidding and reclamation: When creating preemptible instances, you can place a bid. Alibaba Cloud adjusts the market price based on supply and demand. If your bid is lower than the market price, the preemptilbe instances may be reclaimed. You can also enable automatic bidding, which enables the system to automatically adjust bids based on the market price, with the bid cap set at the price of pay-as-you-go instances.

  • Real-time bidding: Instance prices fluctuate in real time based on market supply and demand. If your bid exceeds the market price and resources are available, you can create preemptible instances.

  • Instance interruption and reclaimation: Preemptible instances can be interrupted and reclaimed if your bid is lower than the market price or if resources are insufficient.

  • Protection period: Preemptible instances have a protection period. For example, setting a 1 hour protection period for a preemptible instance prevents the instance from being recycled within the first hour after creation.

For more information about preemptible instances, see What are preemptible instances?

Summary: Preemptible instances in a scaling group offer cost savings with lower unit prices. However, this comes at the cost of stability, as preemptible instances may not always be available or created as expected.

Reduce costs by using preemptible instances

Preemptible instances offer cost savings for instance clusters in a scaling group. However, their instability requires careful consideration of potential impacts on cluster stability. Cluster stability can be assessed from the following aspects:

  • Scale-out stability: As the workload increases, new instances must be launched promptly and reliably to meet scale-out requirements.

    Using preemptible instances may cause delays in instance creation due to market price fluctuations or insufficient inventory, impacting scale-out stability. However, you can configure mechanisms to enhance scale-out stability.

  • Instance stability: Instances should run stably without unexpected interruptions.

    However, preemptible instances may be automatically reclaimed due to market price fluctuations or insufficient resource inventory. This requires the business system to quickly recover and seamlessly switch to available resources when preemptible instances are reclaimed.

After you evaluate the potential cost savings and impacts on cluster stability, the next step is to strike a balance that minimizes costs while ensuring service reliability and performance.

Design a solution that balances cost savings with cluster stability

The following ideas can help you design a solution that balances cost savings with cluster stability:

  • Set a reasonable bid strategy: To enhance the chances of securing preemptible instances and minimize interruptions, set a bid slightly higher than the market price but lower than the pay-as-you-go price.

  • Use multiple instance types: Adjust the ratio of preemptible instances to pay-as-you-go instances in your scaling group based on your business requirements to balance cost savings with cluster stability.

    For example, you can set the ratio of pay-as-you-go instances to the minimum required for stable business running, and use preemptible instances to handle workload spikes and reduce costs.

    The following figure illustrates how the stability and cost of a scaling group change with varying ratios of preemptible instances to pay-as-you-go instances. As the proportion of preemptible instances increases, costs decrease, but cluster stability also declines.

    使用抢占式实例降低成本

Improve cluster stability

In addition to designing a solution that stikes a balance cost savings with cluster stability, the following methods can further optimize your business:

  • Combine multiple instance types to enhance the scale-out success rate

    You can configure multiple instance types for a scaling group. This expands the available inventory of preemptible instances and improves the scale-out success rate.

image
  • Combine multiple vSwitches to enhance the scale-out success rate

    You can configure multiple vSwitches across different zones for a scaling group, expanding the inventory of preemptible instances and enabling them to span the zones, thereby increasing the scale-out success rate.

image
  • Prevent performance gaps from failed scale-out of preemptible instances and ensure stable performance

    You can use pay-as-you-go instances to supplement preemptible capacity. This feature allows the system to automatically create pay-as-you-go instances when preemptible instance inventory is insufficient, preventing performance gaps.

image
  • Prevent abrupt service exceptions caused by preemptible instances being reclaimed to ensure stable performance

    Enabling the preemptible instance compensation feature ensures that a new instance is launched 5 minutes before the old one is reclaimed, reducing performance disruptions.

image

Example: Use preemptible instances to reduce costs in an existing scaling group

To add preemptible instances to an existing scaling group, perform the following steps:

Step 1: Configure vSwitches across multiple zones for the scaling group

Configuring vSwitches across multiple zones combines the resource inventories of the zones, which increases the availability of preemptible instances for the scaling group.

  1. Log on to the Auto Scaling console.

  2. In the top navigation bar, select the region where Auto Scaling is activated.

  3. In the left-side navigation pane, click Scaling Groups.

  4. Find the scaling group for which you want to configure vSwitches across multiple zones and click the group ID to go to the group details page.

image

  1. On the Basic Information tab, find the VPC section and click the image icon to go to the Edit VPC dialog box.

image

  1. Configure multiple vSwitches and click OK.

    Note

    If no vSwitches are available in the current VPC, you can create vSwitches in the Virtual Private Cloud (VPC) console. For more information, see Create and manage a vSwitch.

image

Step 2: Configure the cost optimization policy for the scaling group

  1. On the Basic Information tab, find the Instance Scaling Configuration section and click the image icon to go to the Edit Instance Scaling Configuration dialog box.

image

  1. Set the Scaling Policy parameter to Cost Optimization Policy and configure other parameters based on your business requirements. Parameter description:

    • Minimum Pay-as-you-go Instances

      The minimum number of pay-as-you-go ECS instances required in the scaling group. Default value: 0. If the number of pay-as-you-go ECS instances in the scaling group is less than the value of this parameter, Auto Scaling will create pay-as-you-go ECS instances.

    • Percentage of Pay-as-you-go Instances

      The proportion of pay-as-you-go ECS instances compared to all automatically created ECS instances. Default value: 70 %. Make sure to exclude the minimum number of pay-as-you-go ECS instances specified by the Minimum Pay-as-you-go Instances parameter when you calculate the percentage.

    • Lowest Cost Instance Types

      The number of the lowest-priced instance types. Default value: 1. This parameter takes effect only if you specify multiple instance types in the scaling configuration. Auto Scaling evenly creates preemptible ECS instances of the lowest-priced instance types.

    • Enable Supplemental Preemptible Instances

      If you enable this feature, Auto Scaling will create preemptible ECS instances 5 minutes before the existing ones are reclaimed.

    • Use Pay-as-you-go Instances to Supplement Preemptible Capacity

      If preemptible instances cannot be created due to factors such as cost-related issues and insufficient resources, Auto Scaling will create pay-as-you-go ECS instances to meet the required number of preemptible instances.

image

  1. After the configuration is complete, click OK.

Step 3: Modify the scaling configuration

Note

This topic descirbes only how to modify the existing scaling configuration. You can also create a scaling group of the ECS type based on your business requirements.

  1. Choose Instance Configuration Sources > Scaling Configurations, find the effective scaling configuration, and then click Edit to go to the Modify Scaling Configuration page.

image

  1. On the Modify Scaling Configuration page, change the value of the Billing Method parameter to Preemptible Instance.

image

  1. Change the value of the Instance Configuration Mode parameter to Specify Instance Type.

  1. Configure an instance protection period and a bidding mode.

    • Usage Duration

      The protection period of preemptible instances. During the specified protection period, the system does not interrupt or reclaim preemptible instances. Valid values:
      • 1 Hour: Preemptible instances have a protection period of 1 hour. Once a preemptible instance is created, it will not be interrupted or reclaimed by the system for 1 hour. After this protection period ends, the system will monitor resource inventory and bidding price changes every 5 minutes to determine if the preemptible instance should be reclaimed.

      • None: Preemptible instances have no protection period. Preemptible instances without a protection period are more cost-effective than those with a protection period.

    • Max Unit Price of Instance

      The bidding mode of preemptible instances. Valid values:
      • Enable Automatic Bid: Auto Scaling will place bids on preemptible instances based on the varying market price. The maximum bid for these instances is set to the unit price of pay-as-you-go instances with identical specifications.

      • Max. Price Per Instance: Preemptible instances will be automatically released if the market price exceeds the bid price, or if there is a change in supply and demand. Make sure to back up the data on preemptible instances before they are released.

        You can use this bidding method to control the maximum price for preemptible instances.

image

  1. Select multiple instance types from the Select Instance Type drop-down list to improve the scale-out success rate.

    Note

    If you set the Max Unit Price of Instance parameter to Max. Price Per Instance, you must configure a bid price for each instance type.

image

The figure shows that the Max Unit Price of Instance parameter is set to Enable Automatic Bid.
  1. Confirm the configurations and click Modify.

Step 4: Trigger a scale-out operation to verify the configurations

After the configuration is complete, you can trigger a scale-out operation to verify the creation of preemptible instances in the scaling group. In this example, a scale-out operation is triggered by changing the expected number of instances.

Parameters

  • Percentage of Pay-as-you-go Instances: Set the value to 70%.

  • Minimum Pay-as-you-go Instances: Set the value to 2.

  • Expected Number of Instances: Change the value from 0 to 12.

Expected results

The scaling group contains nine pay-as-you-go instances and three preemptible instances.

Remarks

The minimum number of pay-as-you-go ECS instances specified by the Minimum Pay-as-you-go Instances parameter must be excluded when you calculate the percentage of.pay-as-you-go instances in the scaling group.

Therefore, the total number of pay-as-you-go instances is:. And the total number of preemptible instances is:

Note

You can view the billing method of each instance in the ECS console.