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 spot Elastic Compute Service (ECS) instances to the scaling group. This topic describes how to leverage spot instances for cost-effective cluster building.
Only scaling groups of the ECS type can contain spot instances.
What is a spot instance?
Spot 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. Spot instances provide the following features:
Same performance: Spot instances and pay-as-you-go instances that use the same specifications offer identical performance, differing only in the billing method.
Bidding mechanism: When creating spot 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 spot 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 spot instances.
Instance interruption and reclaimation: Spot instances can be interrupted and reclaimed if your bid is lower than the market price or if resources are insufficient.
Protection period: Spot instances have a protection period. For example, setting a 1-hour protection period for a spot instance prevents the instance from being recycled within the first hour after creation.
For more information about spot instances, see Overview.
Summary: Spot instances in a scaling group offer cost savings with lower unit rates. However, this comes at the cost of stability, as spot instances may not always be available or created as expected.
Reduce costs by using spot instances
Spot 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 spot 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, spot 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 spot 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 optimizes cost savings while maintaining cluster stability
The following ideas can help you design a solution that balances cost effectiveness with service stability:
Set a reasonable bid strategy: To enhance the chances of securing spot 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 spot instances to pay-as-you-go instances in your scaling group based on your business requirements to balance cost-effectiveness and 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 spot 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 spot instances to pay-as-you-go instances. As the proportion of spot instances increases, costs decrease, but cluster stability also declines.
Improve cluster stability
In addition to designing a solution that strikes a balance between cost-effectiveness and cluster stability, the following methods can further optimize your business:
| |
| |
| |
| |
|
Example: Use spot instances to reduce costs in an existing scaling group
To add spot 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, increasing the availability of spot instances for the scaling group.
| |
| |
|
Step 2: Configure the cost optimization policy for the scaling group
| |
| |
|
Step 3: Modify the scaling configuration
This topic descirbes only how to modify the existing scaling configuration. You can also create a scaling configuration based on your business requirements.
| |
| |
| |
| |
| The figure shows that the Max Unit Price of Instance parameter is set to Enable Automatic Bid. |
|
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 spot 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 result
The scaling group contains nine pay-as-you-go instances and three spot instances.
Result description
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:
You can view the billing method of each instance in the ECS console.