All Products
Search
Document Center

Elastic Compute Service:Specify and view CPU options

Last Updated:Mar 26, 2024

For specific Elastic Compute Service (ECS) instance types, you can specify CPU options when you call the RunInstances operation to create an instance. The CPU options are determined by the number of physical CPU cores and the number of threads per core. You can adjust the number of virtual CPUs (vCPUs) (the number of physical cores and the number of threads per core) of an ECS instance based on the performance requirements of your applications to achieve better performance and control costs. For example, in memory-intensive business scenarios, you can disable Hyper-Threading (HT) to reduce the number of vCPUs. This can improve the memory-to-CPU ratio and reduce software licensing costs.

CPU and vCPU

CPUs are central processing units. A single CPU can contain several physical cores. The HT technology can create two logical processing cores for each physical core. 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 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 memory-to-CPU ratio of an instance. This can reduce the number of billable items and software licensing costs.

For more information, see Instance type limits.

Number of threads per core

CpuOptions.ThreadsPerCore

Specifies the number of threads per core. A value of 1 disables HT on the CPU, and a value other than 1 enables 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 performance.

  • Memory-intensive business scenarios. In these scenarios, you can disable HT to reduce the number of vCPUs. This can increase the memory-to-CPU ratio and reduce the number of billable items and software licensing costs.

For more information, see Instance type limits.

Billing

Specifying CPU options does not incur additional costs.

Instance type limits

The following instance families support custom CPU options.

Important

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

Specify CPU options

Important
  • 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.

You can call the RunInstances operation to specify the CPU options (the number of physical CPU cores and the number of threads per core) of an ECS instance. Number of vCPUs of an ECS instance = Number of physical CPU cores × Number of threads per core.

Number of physical CPU cores

The instance type of an instance determines the number of physical cores available for the instance. You can configure the CpuOptions.Core parameter to specify the number of physical CPU cores to be enabled within the value range. You cannot set a value outside the value range. For information about the value range for each instance type, see Instance type limits.

For example, the valid values of the number of physical CPU cores for an ecs.g6.2xlarge instance are 2 and 4. When you call the RunInstances operation to specify the number of physical CPU cores of an ecs.g6.2xlarge instance, you can set the CpuOptions.Core parameter to 2. This indicates that the instance provides two physical cores.

Number of threads per core

The number of threads per core of an ECS instance is determined by the CpuOptions.ThreadsPerCore parameter. You can specify the number of threads per core within the value range, but you cannot set a value outside the value range. For information about the value range for each instance type, see Instance type limits.

  • If you set the CpuOptions.ThreadsPerCore parameter to a value other than 1, HT is enabled and the number of threads per core is the value you set.

    The following sample request shows how to specify the number of CPU threads in Alibaba Cloud CLI. If you want to use an Alibaba Cloud ECS SDK, upgrade the SDK to the latest version.

    Note

    By default, HT is enabled on ECS instances.

    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***

    In the preceding sample request, the number of physical cores is set to 2, HT is enabled, and the number of threads per core is set to 2 for an ecs.g6.xlarge instance. After the instance is created, the instance has 4 vCPUs. The number of vCPUs is calculated by using the following formula: 2 × 2 = 4.

  • If you set the CpuOptions.ThreadsPerCore parameter to 1, HT is disabled and the number of threads per core is 1.

    The following sample request shows how to disable HT in Alibaba Cloud CLI. If you want to use an Alibaba Cloud ECS SDK, upgrade the SDK to the latest version.

    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***

    In the preceding sample request, the number of physical cores is set to 2 and HT is disabled. One physical core can run only one thread. After the instance is created, 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.

The following example shows how to view the CPU options of an instance in Alibaba Cloud CLI. 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.

References

  • After an ECS instance is created, we recommend that you perform system stability tests on the instance to ensure that the instance can run as expected. You can run some load tests or application scenario tests to observe the response and performance of the instance.

  • After an ECS instance is created, you can monitor the performance metrics and resource utilization of the instance and optimize settings based on your business requirements. For more information, see View the monitoring information of an ECS instance.