The CPU options of an Elastic Compute Service (ECS) instance include the number of physical CPU cores and the number of threads per core. For specific ECS instance types, you can specify these options when you call the RunInstances operation to create an instance. This topic describes how to specify and view CPU options.
CPU and vCPU
CPUs are central processing units. A single CPU can contain several physical cores. The Hyper-Threading (HT) technology can create two logical processing cores for each physical core. Virtual CPUs (vCPUs) are virtual processing cores of ECS instances.
Alibaba Cloud ECS supports multi-threading based on HT of the x86 architecture. HT allows two threads to concurrently run on a single physical core. Each thread can be considered as a vCPU.
The following table describes the CPU options for ECS instances.
CPU option | API parameter | Description | Scenario | Supported instance type |
Number of physical CPU cores | CpuOptions.Core | Specifies the number of physical CPU cores to use. | You can use a smaller number of physical CPU cores to increase the CPU-to-memory ratio of an instance. This can reduce the number of billable items and software licensing costs. | For more information, see the "Limits" section of this topic. |
Number of threads per core | CpuOptions.ThreadsPerCore | Specifies the number of threads per core to enable or disable HT on the CPU. Number of vCPUs = Number of physical CPU cores × Number of threads per core. | In most cases, the default configuration of an ECS instance type provides sufficient performance. You can disable HT in the following scenarios:
| For more information, see the "Limits" section of this topic. |
Billing
You can specify CPU options at no additional costs.
Limits
The following instance families support custom CPU options.
NoteClick the following links to check the default and valid values of the number of physical CPU cores (CpuOptions.Core) and the number of threads per core (CpuOptions.ThreadsPerCore) for each instance type. Instance types that are not listed do not support custom CPU options.
You can specify CPU options only when you create an ECS instance and cannot modify CPU options after the instance is created.
After you upgrade or downgrade the configurations of an instance, the custom CPU options of the instance are reset to the default CPU options.
The instance type of an instance determines the number of physical cores available for the instance. You can specify the number of physical CPU cores to be enabled within the specified value range.
Enable or disable HT
You can call the RunInstances operation to specify the CPU options of an ECS instance. If you want to use an Alibaba Cloud ECS SDK, upgrade the SDK to the latest version.
By default, HT is enabled on ECS instances. You can enable HT by using Alibaba Cloud CLI. The following code shows a sample request:
aliyun ecs RunInstances --RegionId cn-hangzhou --CpuOptions.Core 2 --CpuOptions.ThreadsPerCore 2 --ImageId ubuntu_18_04_64_20G_alibase_20190624.vhd --InstanceType ecs.g6.xlarge --SecurityGroupId sg-bp67acfmxazb4ph*** --VSwitchId vsw-bp1s5fnvk4gn2tws03*** --Amount 1 --SystemDisk.AutoSnapshotPolicyId sp-bp67acfmxazb4ph***
To disable HT, set the CpuOptions.ThreadsPerCore parameter to 1 by using Alibaba Cloud CLI. The following code shows a sample request:
aliyun ecs RunInstances --RegionId cn-hangzhou --CpuOptions.Core 2 --CpuOptions.ThreadsPerCore 1 --ImageId ubuntu_18_04_64_20G_alibase_20190624.vhd --InstanceType ecs.g6.xlarge --SecurityGroupId sg-bp67acfmxazb4ph*** --VSwitchId vsw-bp1s5fnvk4gn2tws03*** --Amount 1 --SystemDisk.AutoSnapshotPolicyId sp-bp67acfmxazb4ph***
For example, the ecs.g6.xlarge instance type provides 2 physical CPU cores by default.
If you enable HT for an instance of this instance type and set the number of threads per core to 2, the instance has 4 vCPUs. The number of vCPUs is calculated by using the following formula: 2 × 2 = 4. By default, HT is enabled for this instance type.
If you disable HT for an instance of this instance type, only one thread can run on each physical CPU core. This way, the instance has 2 vCPUs, which is equal to the number of its physical CPU cores.
View CPU options
You can call the DescribeInstances operation to view the CPU options of an ECS instance. If you want to use an Alibaba Cloud ECS SDK, upgrade the SDK to the latest version.
For example, you can run the following sample request in Alibaba Cloud CLI to view the CPU options of an instance: Sample request:
aliyun ecs DescribeInstances --InstanceIds '["i-bp19rxmzeocge2z57***"]' --output cols=CpuOptions rows=Instances.Instance[]
Sample response:
CpuOptions
----------
map[CoreCount:1 ThreadsPerCore:2]
In the response, CoreCount:1
indicates that the number of physical CPU cores is 1, and ThreadsPerCore:2
indicates that the number of threads per core is 2.