All Products
Search
Document Center

Customize CPU options

Last Updated: May 24, 2021

The CPU options of an elastic container instance include the number of physical CPU cores and the number of threads per core. Some elastic container instances support custom CPU options whereas other elastic container instances do not. This is determined based on how the instances are created.

Overview

Elastic Container Instance allows up to two threads to concurrently run on a single physical core based on Intel® Hyper-Threading (HT) technology. Each thread can be considered as a vCPU. You can use the following formula to calculate the number of vCPUs: Number of physical CPU cores × Number of threads per core.

The following table describes the CPU options of an elastic container instance, which are the number of physical CPU cores and the number of threads per core. Elastic container instances may support or not support custom CPU options. This is determined based on how the instances are created.

Note

You can customize CPU options at no additional costs.

CPU option

Description

Scenario

Number of physical CPU cores

Specifies the number of physical CPU cores to use.

You can specify a smaller number of physical CPU cores to decrease the number of vCPUs, improve the CPU-to-memory ratio, and reduce the number of billable items and software license costs.

Number of threads per core

Specifies the number of threads per core to enable or disable HT on the CPU.

By default, Elastic Compute Service (ECS) instance types that support custom CPU options have HT enabled for common workloads. In this case, the number of threads per core is not 1. You can disable HT in the following scenarios:

  • Some high-performance computing (HPC) scenarios. In these scenarios, you can improve the performance of instances by disabling HT.

  • Memory-intensive business scenarios. You can disable HT to decrease the number of vCPUs, improve the CPU-to-memory ratio, and reduce the number of billable items and software license costs.

You can specify ECS instance types or specify vCPU and memory specifications to create elastic container instances. The system uses the specified ECS instance types or tries multiple ECS instance types based your specified vCPU and memory specifications to create elastic container instances. If the system is using an ECS instance type that supports custom CPU options, the created elastic container instances also support custom CPU options.

Note

Only some ECS instance types support custom CPU options, and HT is enabled on instances of these instance types by default. For more information, see Customize CPU options.

Elastic container instances may support or not support custom CPU options. This is determined based on how the instances are created.

  • Elastic container instances created by specifying one or more ECS instance types

    • One ECS instance type specified

      • If the specified ECS instance type supports custom CPU options, elastic container instances are created with the customized CPU options based on the ECS instance type.

      • If the specified ECS instance type does not support custom CPU options, elastic container instances are created based on the ECS instance type while the settings of CPU options are ignored. Then, an event notification is sent to you. If the customized CPU options are invalid, elastic container instances cannot be created and an error message is sent to you.

    • Multiple ECS instance types specified

      The system tries the ECS instance types in the order that they are specified to create elastic container instances.

      • If the system is using an ECS instance type that supports custom CPU options, elastic container instances are created with the customized CPU options based on the ECS instance type.

      • If the system is using an ECS instance type that does not support custom CPU options or if the customized CPU options are invalid, elastic container instances are created based on the ECS instance type while the settings of CPU options are ignored. Then, an event notification is sent to you.

  • Elastic container instances created by specifying vCPU and memory specifications

    When you use this method to create elastic container instances, the ECS instance types that support custom CPU options are preferentially used.

When you create an elastic container instance, you can use one of the following modes to customize CPU options:

Kubernetes mode

You can add annotations to metadata in the configuration file of the pod to customize CPU options. Take note of the following items:

  • k8s.aliyun.com/eci-cpu-option-core: the number of physical CPU cores.

  • k8s.aliyun.com/eci-cpu-option-ht: the number of threads per core.

Sample code:

apiVersion: v1
kind: Pod
metadata:
  annotations:
    k8s.aliyun.com/eci-use-specs : "ecs.c6.2xlarge"    #Specify an ECS instance types that supports custom CPU options.
    k8s.aliyun.com/eci-cpu-option-core: 2                 #Set the number of physical CPU cores to 2.
    k8s.aliyun.com/eci-cpu-option-ht: 1                    #Set the number of threads per core to 1 to disable HT.
  name: nginx-test
spec:
  containers:
  - name: nginx
    image: nginx:latest
  restartpolicy: Always

API mode

When you call the CreateContainerGroup operation to create an elastic container instance, you can use the CpuOptionsCore and CpuOptionsThreadsPerCore parameters to customize CPU options. The following table describes the parameters. For more information, see CreateContainerGroup.

Parameter

Type

Required

Example

Description

CpuOptionsCore

Integer

No

2

The number of physical CPU cores. Only some ECS instance types allow you to customize this number.

CpuOptionsThreadsPerCore

Integer

No

2

The number of threads per core. Only some ECS instance types allow you to customize this number. If the CpuOptions.ThreadPerCore parameter is set to 1, HT is disabled.