All Products
Search
Document Center

Batch Compute:Bidding resources

Last Updated:Apr 12, 2018

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: Spot and OnDemand. Spot instances are used here.
InstanceType Type of the spot instance. You can get the list of available spot instance types in the getQuota() method.
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 SpotStrategy is SpotWithPriceLimit.

1.1. Use Java SDK to submit a job

  1. TaskDescription taskDesc = new TaskDescription();
  2. AutoCluster autoCluster = new AutoCluster();
  3. autoCluster.setResourceType("Spot");
  4. autoCluster.setInstanceType("ecs.sn1.large");
  5. //Optional configuration
  6. autoCluster.setSpotStrategy("SpotWithPriceLimit");
  7. autoCluster.setSpotPriceLimit(0.1f);

1.2. Use Python SDK to submit a job

  1. job_desc['DAG']['Tasks']['my-task']['AutoCluster']['ResourceType'] = 'Spot'
  2. job_desc['DAG']['Tasks']['my-task']['AutoCluster']['InstanceType'] = 'ecs.sn1.large'
  3. # The following configurations are optional.
  4. job_desc['DAG']['Tasks']['my-task']['AutoCluster']['SpotStrategy'] = 'SpotWithPriceLimit'
  5. 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.

  1. 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.

  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.

  1. 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

  1. GroupDescription group = new GroupDescription();
  2. group.setDesiredVMCount(3);
  3. group.setInstanceType("ecs");
  4. group.setResourceType("OnDemand");
  5. //Optional configuration
  6. group.setSpotPriceLimit(0.1f);
  7. group.setSpotStrategy("SpotWithPriceLimit");

2.2. Use Python SDK

  1. group_desc['ResourceType'] = 'Spot'
  2. group_desc['InstanceType'] = 'ecs.sn1.large'
  3. # The following configurations are optional.
  4. group_desc['SpotStrategy'] = 'SpotWithPriceLimit'
  5. group_desc['SpotPriceLimit'] = 0.1 # USD 0.1

2.3. Use command line tool

Set the spot price policy when creating a cluster:

  1. bcs cc cluster_1 -t ecs.sn1.large --resource_type Spot --spot_price_limit 0.1

Modify the cluster spot price policy:

  1. bcs uc cls-xxxx --spot_price_limit 0.8