The CPU options of an ECS instance include the number of CPU cores and the number of threads per core. For some ECS instance types, you can customize the CPU options of an instance when you create the instance by calling the RunInstances operation.

CPU and vCPU

A CPU is the physical processor of an ECS instance. Alibaba Cloud ECS instances use the Hyper-Threading (HT) technology to enable multiple threads to run concurrently on a single CPU core. Each CPU thread is virtualized as a virtual CPU (vCPU).

The following table describes the parameters of the CPU options for an ECS instance.

CPU option API parameter Function Scenario Applicable instance type
Number of CPU cores CpuOptions.Core Determines the number of physical CPU cores. You can increase the number of CPU cores for memory-optimized instance types to significantly improve instance performance and optimize the licensing costs of software. This option cannot be customized, and the default value is used.
Number of threads per core CpuOptions.ThreadsPerCore Determines the total number of vCPUs.

Number of vCPUs = Number of CPU cores × Number of threads per core.

In most cases, an ECS instance type provides sufficient threads per core to suit your workloads. You can customize this parameter for the following scenarios:
  • High-performance computing (HPC) workloads
  • Memory-intensive business needs
For more information, see Numbers of CPU cores and threads per core.

Billing

Customizing CPU options does not incur additional charges.

Limits

  • CPU options can only be customized when you create an instance, and cannot be modified after the instance is created.
  • When you change the instance type of an ECS instance, its CPU options are changed to the default CPU options for the new instance type.
  • The number of CPU cores cannot be customized.
  • Only the g6, r6, c6, hfc6, hfg6, and hfr6 instance families support customizing CPU options. For information about valid values of CPU options, see Numbers of CPU cores and threads per core.

Enable or disable Hyper-Threading

You can call the RunInstances operation to customize the CPU options of an ECS instance. If an SDK is used, upgrade it to the latest version.

  • By default, Hyper-Threading is enabled on ECS instances. You can enable Hyper-Threading in the Alibaba Cloud CLI, shown in the following 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.6xlarge --SecurityGroupId sg-bp67acfmxazb4ph*** --VSwitchId vsw-bp1s5fnvk4gn2tws03*** --Amount 1 --SystemDisk.AutoSnapshotPolicyId sp-bp67acfmxazb4ph***
  • To disable Hyper-Threading, set the CpuOptions. ThreadsPerCore parameter to 1 in the Alibaba Cloud CLI, shown in the following 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.6xlarge --SecurityGroupId sg-bp67acfmxazb4ph*** --VSwitchId vsw-bp1s5fnvk4gn2tws03*** --Amount 1 --SystemDisk.AutoSnapshotPolicyId sp-bp67acfmxazb4ph***
In this example, the ecs.g6.xlarge instance type provides two physical CPU cores.
  • Enable Hyper-Threading: You can enable Hyper-Threading by setting the number of threads per core to 2. The instance type will have 4 vCPUs, which is the number of CPU cores multiplied by the number of threads per core. Hyper-Threading is enabled by default for this instance type.
  • Disable Hyper-Threading: You can disable Hyper-Threading by setting the number of threads per core to 1. The instance type will have only 2 vCPUs.

View the CPU options

You can call the DescribeInstances operation to view the specified CPU options for an ECS instance. If an SDK is used, upgrade it to the latest version.

  • Sample request in the Alibaba Cloud CLI:
    aliyun ecs DescribeInstances --InstanceIds '["i-bp19rxmzeocge2z57***"]' --output cols=CpuOptions rows=Instances.Instance[]
  • Sample response in the Alibaba Cloud CLI:
    CpuOptions
    ----------
    map[CoreCount:1 ThreadsPerCore:2]
  • Sample codes by using the Shell command lscpu:
    shell@ecshost:~$ lscpu
    Architecture:        x86_64
    Byte Order:          Little Endian
    CPU(s):              1   # Number of CPU cores
    On-line CPU(s) list: 0
    Thread(s) per core:  2   # Number of threads per core
    Core(s) per socket:  1
    Socket(s):           1
    Vendor ID:           GenuineIntel
    CPU family:          6
    Model:               85
    Model name:          Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
    ......

Numbers of CPU cores and threads per core

The following table lists the default value and valid values of CPU cores (CpuOptions.Core) and threads per core (CpuOptions.ThreadsPerCore). Instance types not listed in the table do not support customizing CPU options.

Instance type Default value of vCPUs Default value of CPU cores Default value of threads per core Valid values of threads per core
ecs.g6.large 2 1 2 1, 2
ecs.g6.xlarge 4 2 2 1, 2
ecs.g6.2xlarge 8 4 2 1, 2
ecs.g6.3xlarge 12 6 2 1, 2
ecs.g6.4xlarge 16 8 2 1, 2
ecs.g6.6xlarge 24 12 2 1, 2
ecs.g6.8xlarge 32 16 2 1, 2
ecs.g6.13xlarge 52 26 2 1, 2
ecs.g6.26xlarge 104 52 2 1, 2
ecs.r6.large 2 1 2 1, 2
ecs.r6.xlarge 4 2 2 1, 2
ecs.r6.2xlarge 8 4 2 1, 2
ecs.r6.3xlarge 12 6 2 1, 2
ecs.r6.4xlarge 16 8 2 1, 2
ecs.r6.6xlarge 24 12 2 1, 2
ecs.r6.8xlarge 32 16 2 1, 2
ecs.r6.13xlarge 52 26 2 1, 2
ecs.r6.26xlarge 104 52 2 1, 2
ecs.c6.large 2 1 2 1, 2
ecs.c6.xlarge 4 2 2 1, 2
ecs.c6.2xlarge 8 4 2 1, 2
ecs.c6.3xlarge 12 6 2 1, 2
ecs.c6.4xlarge 16 8 2 1, 2
ecs.c6.6xlarge 24 12 2 1, 2
ecs.c6.8xlarge 32 16 2 1, 2
ecs.c6.13xlarge 52 26 2 1, 2
ecs.c6.26xlarge 104 52 2 1, 2
ecs.hfc6.large 2 1 2 1, 2
ecs.hfc6.xlarge 4 2 2 1, 2
ecs.hfc6.2xlarge 8 4 2 1, 2
ecs.hfc6.3xlarge 12 6 2 1, 2
ecs.hfc6.4xlarge 16 8 2 1, 2
ecs.hfc6.6xlarge 24 12 2 1, 2
ecs.hfc6.8xlarge 32 16 2 1, 2
ecs.hfc6.10xlarge 40 20 2 1, 2
ecs.hfc6.16xlarge 64 32 2 1, 2
ecs.hfc6.20xlarge 80 40 2 1, 2
ecs.hfg6.large 2 1 2 1, 2
ecs.hfg6.xlarge 4 2 2 1, 2
ecs.hfg6.2xlarge 8 4 2 1, 2
ecs.hfg6.3xlarge 12 6 2 1, 2
ecs.hfg6.4xlarge 16 8 2 1, 2
ecs.hfg6.6xlarge 24 12 2 1, 2
ecs.hfg6.8xlarge 32 16 2 1, 2
ecs.hfg6.10xlarge 40 20 2 1, 2
ecs.hfg6.16xlarge 64 32 2 1, 2
ecs.hfg6.20xlarge 80 40 2 1, 2
ecs.hfr6.large 2 1 2 1, 2
ecs.hfr6.xlarge 4 2 2 1, 2
ecs.hfr6.2xlarge 8 4 2 1, 2
ecs.hfr6.3xlarge 12 6 2 1, 2
ecs.hfr6.4xlarge 16 8 2 1, 2
ecs.hfr6.6xlarge 24 12 2 1, 2
ecs.hfr6.8xlarge 32 16 2 1, 2
ecs.hfr6.10xlarge 40 20 2 1, 2
ecs.hfr6.16xlarge 64 32 2 1, 2
ecs.hfr6.20xlarge 80 40 2 1, 2