Spot Instances

Last updated: 2024-05-15 15:25:32

Scenario

This document provides guidance on managing and purchasing spot instances. Spot instances are available through the following channels:
Cloud Virtual Machine Console: The CVM purchase page supports spot instance mode.
Batch Compute Console: Batch Compute supports selecting spot instances when submitting jobs and creating compute environments.
Cloud API: The RunInstance interface has added parameters related to spot instances.

Instructions

Cloud Virtual Machine Console
Batch Compute Console
TencentCloud API
2. When selecting an instance type, choose Spot Instance as the billing mode.

3. Select region, availability zone, network type, instance and other configuration information as needed and prompted by the page.
4. Check the information of the spot instance to be purchased and the cost details of each configuration item.
5. Click Activate to complete the payment. After the payment is completed, you can access your spot instances in the Cloud Virtual Machine Console.

BatchCompute feature description

Asynchronous Interface When submitting jobs, creating compute environments, or modifying the desired number of instances in a compute environment, Batch Compute processes your requests asynchronously. This means that if your current request cannot be fulfilled due to inventory or pricing constraints, Batch Compute will continue to request spot instance resources until the desired number is met. To release instances, you need to adjust the number of instances in the compute environment through the Batch Compute Console. If you release instances from the Cloud Virtual Machine Console, Batch Compute will automatically create new instances for you until the desired number is reached.
Cluster Mode Batch Compute's compute environment supports maintaining a group of spot instances in a cluster mode. You only need to submit the required quantity, configuration, and maximum bid. The compute environment will automatically initiate requests until the desired quantity is met, and will automatically re-initiate requests to replenish the quantity in case of interruptions.
Fixed Price At this stage, a fixed discount model is used. You must set the parameter to be greater than or equal to the current market price. For detailed market prices, please refer to Supported Regions, Instance Types, and Specifications for Spot Instances.

Directions

1. Log in to the Batch Compute console.
2. On the Compute Environment Management page, select any region (e.g., Guangzhou), and click Create. You will be directed to the New Compute Environment page.
3. On the Create Compute Environment page, set the "Billing Type" to Spot Instance and select the desired model, image, name, expected quantity, and other information based on your requirements.

4. Click Confirm to complete the creation. After the creation is complete, you can view the newly created compute environment in the Batch Compute Console. Meanwhile, the CVMs within the compute environment are being created synchronously. You can check the creation status through the Activity Log and Instance List of the compute environment.
In the RunInstance interface, the InstanceMarketOptionsRequest parameter can be used to specify the spot instance mode and configure related information.
Synchronous Interface: Currently, RunInstance provides a one-time synchronous request interface. If the application fails (due to insufficient inventory or a request price lower than the market price), it will immediately return a failure and will not continue to apply.
Fixed Price: At this stage, a fixed discount mode is used. You must set the parameter to be greater than or equal to the current market price. For detailed market prices, please refer to Supported Regions, Instance Types, and Specifications for Spot Instances.

Example

You have an instance located in Guangzhou Zone 3 with an hourly postpaid spot pricing mode. The specific spot pricing configuration details are as follows:
MaxPrice: 0.6 CNY/hour
SpotInstanceType: one-time
ImageId: img-pmqg1cw7
InstanceType: S2.MEDIUM4 (Standard 2, 2-core, 4GB)
InstanceCount: 1

Request Parameters

https://cvm.tencentcloudapi.com/?Action=RunInstances
&Placement.Zone=ap-guangzhou-3
&InstanceChargeType=SPOTPAID
&InstanceMarketOptions.MarketType=spot
&InstanceMarketOptions.SpotOptions.MaxPrice=0.60
&InstanceMarketOptions.SpotOptions.SpotInstanceType=one-time
&ImageId=img-pmqg1cw7
&InstanceType=S2.MEDIUM4
&InstanceCount=1
&<Common request parameter>

Response parameters

{
"Response": {
"InstanceIdSet": [
"ins-1vogaxgk"
],
"RequestId": "3c140219-cfe9-470e-b241-907877d6fb03"
}
}