If you want to create a large number of pay-as-you-go Elastic Compute Service (ECS) instances, you can call API operations to batch create the instances in a more efficient manner. This topic describes how to batch create pay-as-you-go ECS instances by compiling Java code to call the CreateAutoProvisioningGroup operation. This topic also describes the differences between the features, advantages, and disadvantages of the RunInstances and CreateAutoProvisioningGroup operations.
Background information
The RunInstances
operation is commonly used to create pay-as-you-go ECS instances. You can call the operation to batch create up to 100 ECS instances. However, if you want to batch create more than 100 ECS instances, you may encounter technical bottlenecks when you call the RunInstances
operation. For more information, see the Possible issues caused by using the RunInstances operation section of this topic.
If you are familiar with the technical bottlenecks caused by using the RunInstances
operation, skip the preceding section.
To allow more than 100 ECS instances to be batch created, Alibaba Cloud provides auto provisioning groups. You can call the CreateAutoProvisioningGroup
operation to create an auto provisioning group and use the group to deploy an instance cluster across billing methods, instance families, and zones within a few clicks. The CreateAutoProvisioningGroup
operation is more suitable than the RunInstances
operation when you want to batch create a large number of ECS instances. For information about the differences between and benefits of the two operations, see the Differences between RunInstances and CreateAutoProvisioningGroup and Benefits of auto provisioning groups sections of this topic.
Differences between RunInstances and CreateAutoProvisioningGroup
The following table describes the differences between the features of the RunInstances and CreateAutoProvisioningGroup operations to help you select an appropriate operation to create ECS instances.
Item | RunInstances | CreateAutoProvisioningGroup |
Maximum number of instances that can be batch created | 100. | 1,000 (up to 10,000 vCPUs). |
Capacity delivery method | Specific number of instances | Specific number of instances, specific number of vCPUs, and instance types of different weights. |
Support for multiple zones | No. | Yes. |
Support for multiple instance types | No. | Yes. |
Support for multiple disk categories | No. | Yes. |
Provisioning of policies that you can use to create instances | No. | Yes. The following policies are provided:
|
Delivery stability | Affected by resource availability. | Multiple combinations of instance types and zones reduce the impacts of resource availability. |
Response method | Returns a response in real time. | Returns a response in real time. |
The following sample scenarios describe how to use the CreateAutoProvisioningGroup
operation instead of the RunInstances
operation to create ECS instances:
You called the
RunInstances
operation to batch create instances of a single instance type in a single zone. When you call theCreateAutoProvisioningGroup
operation instead to batch create instances, you need to only configure a combination of instance types and zones.You configured a business deployment plan when you called the
RunInstances
operation to batch create instances. Instead, you can call theCreateAutoProvisioningGroup
operation to deploy instances that have multiple categories of disks attached across multiple instance types and zones, based on different instance provisioning policies provided by Auto Provisioning.For example, you manually configured a business deployment plan that traversed multiple instance types and zones to create instances when you called the
RunInstances
operation to improve the success rate of creating instances. If you call theCreateAutoProvisioningGroup
operation instead to batch create a large number of instances, you need to only configure multiple combinations of instance types and zones, and select an appropriate policy. The created auto provisioning group automatically batch creates instances based on the specified configurations and policy.
Limits apply to policies that are used for auto provisioning groups to create instances. Up to 1,000 instances can be created at the same time. If you specify the weight of each specified instance type by using the WeightedCapacity
parameter, the maximum weighted capacity that is created each time is 10,000.
Possible issues caused by using the RunInstances operation
The limits of the RunInstances
operation may cause the following issues when you call the operation to create instances.
Issue | Description | Solution |
A limited number of instances can be batch created. | You can call the RunInstances operation to batch create up to 100 ECS instances. | If you want to create more than 100 ECS instances, you must call this operation multiple times in a cyclic or concurrent manner. |
The success rate of batch creating instances is not ensured. | Each time you call the RunInstances operation to batch create instances, the operation supports only a single instance type and a single zone. When you call the operation to batch create instances, the following issues may occur:
|
|
Simple policies that are used to create instances cannot meet diversified business requirements. | The RunInstances operation can be used to create instances only of a single instance type in a single zone. If you want to deploy instances across zones to implement geo-disaster recovery or create ECS instances at minimal costs, you must create a business deployment plan to ensure that instances are deployed. When you create a business deployment plan, you may encounter the following issues:
| To resolve the issue, you may contact Alibaba Cloud for assistance. |
Benefits of auto provisioning groups
Alibaba Cloud provides auto provisioning groups to address the issues that you may encounter when you call the RunInstances
operation to batch create ECS instances. Auto provisioning groups allow you to deploy an instance cluster across billing methods, instance families, and zones with a few clicks. Auto provisioning groups provide stable computing power, reduce the instability caused by the reclaim mechanism of preemptible instances, and eliminate the need to manually create instances. The following table describes the benefits of auto provisioning groups.
Benefit | Description |
Batch creation of a large number of ECS instances | You can use an auto provisioning group to batch create up to 1,000 ECS instances. |
Creation of instances that have multiple categories of disks attached across instance types and zones | Auto provisioning groups allow you to configure up to 10 combinations of instance types and zones and to select up to five disk categories, which ensures high availability of batch instance creation. Sample scenario: When you create ECS instances based on the balanced distribution policy provided by an auto provisioning group, you can configure multiple instance types and zones. As required by the policy, instances must be created in a relatively balanced manner across zones. However, if the required number of instances cannot be created in a zone, the auto provisioning group attempts to create the same number of instances in other zones. If you specify multiple disk categories, the auto provisioning group creates disks for instances based on the priorities of the disk categories, and changes a disk category if the disk category is unavailable. Note If all disk categories are unavailable, the auto provisioning group selects another creation method. |
Support for multiple policies to create instances | Auto provisioning groups provide the following policies to create instances:
|
Improved availability of preemptible instances | The demand for preemptible instances is increasing due to the advantages in prices of preemptible instances. However, the prices of preemptible instances fluctuate, and the instances are reclaimed when bid prices become lower than current market prices after protection periods elapse. Therefore, preemptible instances are difficult to manage. Auto provisioning groups help you improve the availability of preemptible instances that remain low costs. The following items describe how to improve the availability of preemptible instances:
|
Best practices for creating auto provisioning groups by calling the CreateAutoProvisioningGroup operation
This section provides the sample Java code that is used to create an auto provisioning group (CreateAutoProvisioningGroup). This section also describes how to call the CreateAutoProvisioningGroup operation.
Install ECS SDK for Java and the Alibaba Cloud SDK core library.
For more information, see Install ECS SDK for Java.
Compile the Java code that is used to call the CreateAutoProvisioningGroup operation.
Sample code:
CreateAutoProvisioningGroupRequest request = new CreateAutoProvisioningGroupRequest(); request.setRegionId(regionId); request.setLaunchConfigurationImageId(RequestHelper.IMAGE_ID); request.setLaunchConfigurationSecurityGroupId(securityGroupId); request.setTotalTargetCapacity(totalTargetCapacity); request.setPayAsYouGoTargetCapacity(payAsYouGoTargetCapacity); request.setSpotTargetCapacity(spotTargetCapacity); request.setLaunchConfigurationSystemDiskCategory("cloud_ssd"); request.setLaunchConfigurationSystemDiskSize(40); request.setAutoProvisioningGroupType("instant"); // Configure the policy that is used to create preemptible instances. request.setSpotAllocationStrategy("lowest-price"); request.setSpotInstancePoolsToUseCount(spotInstancePoolsToUseCount); // Configure the policy that is used to create pay-as-you-go instances. request.setPayAsYouGoAllocationStrategy("prioritized"); request.setMaxSpotPrice(maxSpotPrice); // Configure up to 10 combinations of instance types and zones. request.setLaunchTemplateConfigs(launchTemplateConfigs); request.setClientToken(clientToken); CreateAutoProvisioningGroupResponse response = client.getAcsResponse(request);
Sample response in the JSON format:
{ "autoProvisioningGroupId":"apg-****", "launchResults":[ { "instanceIds":[ "i-****" ], "instanceType":"ecs.c5.large", "spotStrategy":"NoSpot", "zoneId":"cn-shanghai-b" }, { "instanceIds":[], "instanceType":"ecs.c5.large", "spotStrategy":"NoSpot", "zoneId":"cn-shanghai-b", "errorCode" : "Invalid.Parameter", "errorMsg" : "Specific Parameter 'imageId' is not valid" } ], "requestId":"20DA1E9F-BF7F-4BE7-8204-E4DE58E4FC7B" }
When you call the CreateAutoProvisioningGroup operation to create an auto provisioning group, configure items that are used to batch create instances. You do not need to worry about the creation process. The auto provisioning group creates instances in a best-effort manner.
NoteIn a best-effort manner, the system attempts to use one combination to batch create instances, and if the combination cannot be used to create enough instances, the system uses another combination of instance types and zones to batch create instances. The best-effort instance creation method requires an extended period of time, and the creation result may deviate from the creation policy that you configured.