16 Running Jobs at Low Cost With Spot Instances

16 Running Jobs at Low Cost with Spot Instances #

Cost Optimization #

1.jpg

In addition to its advantages of rapid elasticity and infinite capacity, ECI also offers significant cost optimization in certain scenarios. As shown in the above figure, for instances with the same specifications, using ECI is more cost-effective when the daily running time is less than 14 hours.

2.jpg

In addition to cases where the daily running time is less than 14 hours, ECI instances support various billing types. Customers can choose the corresponding billing mode based on their business needs. For long-running instances, RI instance coupons can be used. For instances running for less than 1 hour, Spot bidding instances can be used. For burst traffic, pay-as-you-go instances can be used.

Overview of Spot Instances #

3.jpg

Spot instances are a type of on-demand instances that can reduce computing costs in scenarios such as data processing. Spot instances have a protection period of 1 hour after being successfully created. The market price of spot instances fluctuates according to supply and demand. We support two spot strategies: market price and maximum price. To use spot instances, you only need to add the corresponding annotation to the pod. It is very simple to use.

4.jpg

  • SpotAsPriceGo: Automatically follows the current market price (usually in the form of a discount).
  • SpotWithPriceLimit: Sets a maximum price for the spot instance.
  • If the user’s price is lower than the market price, the instance will be in a pending state, and a bid will be made automatically every 5 minutes. When the price is equal to or higher than the market price, the instance will be automatically created. After running for 1 hour, if the market price is higher than the user’s price, the instance may be released at any time.
  • If the user’s price is greater than or equal to the market price, an instance will be automatically created if there is inventory. The price will be calculated based on the market price when the instance is successfully created. The market price is usually an hourly rate, so to obtain the price per second, divide the hourly rate by 3600. Spot instances are billed per second.
  • If the user’s price is greater than or equal to the pay-as-you-go price for ECI instances, an instance will be created using the pay-as-you-go price for ECI instances.

Creating Spot Instances #

5.jpg

  • To view the pay-as-you-go prices for instances based on their specifications, click here to query.

First, we query the pay-as-you-go price for ECS.C5.Large instances in the Beijing region of China (North 2) which is 0.62 per hour. Then, we use this specification to create a Spot bidding instance.

6.jpg

Spot instances are used to run CronJobs, with both “specified maximum limit price” and “automatic market price” strategies. Currently, there is no direct way to see the actual market price in scenarios where the market price is following, so the real price can only be determined by querying the billing information of the instance ID.

7.jpg

Spot instances are used to run Deployments. In this experiment, the “specified maximum limit price” strategy was used with an extremely low hourly price. As can be seen, both pods failed to create. By using the kubectl describe command, you can see the detailed reason for the failure, which is that the price does not match: “The current price of recommend instanceTypes above user max price”.

8.jpg

As shown above, after the 1-hour protection period for Spot instances has expired, instances may be released due to insufficient inventory or if the set price is lower than the market price. There will be an event notification 3 minutes before the instance is released.

Use Cases #

You can deploy the following businesses on spot instances:

  • Real-time analysis business
  • Big Data computing business
  • Elastic and scalable business sites
  • Image and media encoding business
  • Scientific computing business
  • Geographical survey and analysis business
  • Web crawling business
  • Testing business

Spot instances are suitable for stateless application scenarios, such as elastic and scalable web site services, image rendering, big data analysis, and large-scale parallel computing. The higher the distribution, scalability, and fault tolerance of an application, the more suitable it is to use Spot instances to save costs and increase throughput.

Precautions #

  • How to avoid spot instance preemption due to too low bidding prices?

You need to take into account the characteristics of your own business and consider the fluctuation of market prices to choose a reasonable bidding price.

  • With automatic market price bidding, will the instance be released after 1 hour?

When the 1-hour protection period expires, the system will attempt to bid again. If there is sufficient inventory, the instance will not be released.

  • What is the upper limit for automatic market price bidding?

The upper limit is equal to or less than the maximum pay-as-you-go price for the same specification.

  • Does it only support ECS InstanceType?

Preemptible ECI instances support both ECS InstanceType and CPU/memory based creation methods.

  • Does it support GPU instances?

Yes, it supports GPU instances just like non-GPU instances.