Spot instances are Pay-As-You-Go instances designed to reduce your ECS computing cost. The price of spot instances is set by Alibaba Cloud ECS, which is subject to the supply-demand changes of these instances in the market. Therefore, you can take full advantage of the price fluctuations of spot instances. By buying spot instances at the right time, you can reduce your computing costs at a whole, while increasing your business throughput for this period. For more information, see Spot instance.
Same as the ECS instances, no additional fees are charged for your spot instance use in Batch Compute. For types of spot instances supported by Batch Compute, see Instance types.
1. Submit the job
See the following table for the parameters used to specify spot instance resource.
Parameter | Description |
ResourceType | Resource type. Optional values: |
InstanceType | Type of the spot instance. You can get the list of available spot instance types in the |
SpotStrategy | Optional values: SpotWithPriceLimit: Set the maximum price for the spot instance. SpotAsPriceGo: The system provides a price automatically, and the maximum value is the Pay-As-You-Go price. |
SpotPriceLimit | Maximum price of an instance per hour. The value can contain at most three decimals. It takes effect when |
1.1. Use Java SDK to submit a job
TaskDescription taskDesc = new TaskDescription();
AutoCluster autoCluster = new AutoCluster();
autoCluster.setResourceType("Spot");
autoCluster.setInstanceType("ecs.sn1.large");
//Optional configuration
autoCluster.setSpotStrategy("SpotWithPriceLimit");
autoCluster.setSpotPriceLimit(0.1f);
1.2. Use Python SDK to submit a job
job_desc['DAG']['Tasks']['my-task']['AutoCluster']['ResourceType'] = 'Spot'
job_desc['DAG']['Tasks']['my-task']['AutoCluster']['InstanceType'] = 'ecs.sn1.large'
# The following configurations are optional.
job_desc['DAG']['Tasks']['my-task']['AutoCluster']['SpotStrategy'] = 'SpotWithPriceLimit'
job_desc['DAG']['Tasks']['my-task']['AutoCluster']['SpotPriceLimit'] = 0.1 # USD 0.1
1.3. Use command line tool to submit a job
Example 0: Submit a spot job.
bcs sub "python demo.py" --resource_type Spot -t ecs.sn1.large
Example 1: Specify the maximum price per hour to be USD 0.1.
bcs sub "python demo.py" --resource_type Spot -t ecs.sn1.large --spot_price_limit 0.1
Example 2: When spot_price_limit is set to 0, the price is assigned automatically by the system, which is no more than the price of Pay-As-You-Go instances.
bcs sub "python demo.py" --resource_type Spot -t ecs.sn1.large --spot_price_limit 0
2. Create and modify a cluster
2.1. Use Java SDK
GroupDescription group = new GroupDescription();
group.setDesiredVMCount(3);
group.setInstanceType("ecs");
group.setResourceType("OnDemand");
//Optional configuration
group.setSpotPriceLimit(0.1f);
group.setSpotStrategy("SpotWithPriceLimit");
2.2. Use Python SDK
group_desc['ResourceType'] = 'Spot'
group_desc['InstanceType'] = 'ecs.sn1.large'
# The following configurations are optional.
group_desc['SpotStrategy'] = 'SpotWithPriceLimit'
group_desc['SpotPriceLimit'] = 0.1 # USD 0.1
2.3. Use command line tool
Set the spot price policy when creating a cluster:
bcs cc cluster_1 -t ecs.sn1.large --resource_type Spot --spot_price_limit 0.1
Modify the cluster spot price policy:
bcs uc cls-xxxx --spot_price_limit 0.8