All Products
Search
Document Center

Elastic Compute Service:Adjust vCPU and configure Hyper-Threading to improve performance

Last Updated:Nov 06, 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 vary based on the number of physical CPU cores and the number of threads per core. You can change 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 effectively manage 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

CPU stands for central processing unit. A single CPU can contain several physical cores. The HT technology can create two logical processing cores for each physical core. vCPUs are the 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 that you want 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 the Instance type limits section of this topic.

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 the Instance type limits section of this topic.

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 the Instance type limits section of this topic.

For example, the valid values for the number of physical CPU cores of 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 the Instance type limits section of this topic.

  • 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 that you set.

    The following sample request describes 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 describes 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 the physical CPU cores of the instance.

View CPU options

To view the CPU options that you specified for an ECS instance, you can call the DescribeInstances operation. If you want to use an Alibaba Cloud ECS SDK, upgrade the SDK to the latest version.

The following example describes 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 Numa:ON ThreadsPerCore:2]

In the sample 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 specific 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.

  • In various scenarios such as virtualization environments, multi-threaded programming, and high-performance computing, you can modify the CPU topologies of ECS instances by setting the CpuOptions.TopologyType parameter to enhance the performance of ECS instances, improve parallelism, and optimize resource allocation.