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 some ECS instance types, you can specify these options when you call the RunInstances operation to create an instance.

CPU and vCPU

CPUs are central processing units. A single CPU can contain several physical cores. The Hyper-Threading (HT) technology can be used to create two virtual processing cores for each physical core that is present in a CPU. Virtual CPUs (vCPUs) are virtual processing cores of ECS instances.

Alibaba Cloud ECS supports multi-threading based on HT of the x86 architecture. HT enables 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 improve the CPU-to-memory ratio of an instance. This can reduce the number of billable items and software licensing costs. For more information, see Limits.
Number of threads per core CpuOptions.ThreadsPerCore Specifies whether to enable 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:
  • High-performance computing (HPC) scenarios. In these scenarios, you can disable HT to improve the performance of instances.
  • Memory-intensive business scenarios. You can disable HT to reduce the number of vCPUs and increase the CPU-to-memory ratio. This can also reduce the number of billable items and software licensing costs.
For more information, see Limits.

Billing

You can specify CPU options at no additional costs.

Limits

  • The following instance families support custom CPU options.
    Note Click the following links to check the default and valid values for the number of physical CPU cores (CpuOptions.Core) and the number of threads per core (CpuOptions.ThreadsPerCore). Instance types that are not listed do not support custom CPU options.
  • CPU options can be specified only when you create an ECS instance. You cannot modify CPU options after the instance is created.
  • If you upgrade or downgrade the configurations of an instance, the custom CPU options are changed to the default CPU options of the new instance type.
  • 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 formula described in the preceding table: 4 (Number of vCPUs) = 2 (Number of physical CPU cores) × 2 (Number of threads per core). 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:
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.