Specify CPU options for an Amazon EC2 instance
You can specify CPU options during or after instance launch through the AWS Management Console,
AWS CLI, EC2 API, or SDKs. This page covers the AWS Management Console and AWS CLI methods, as follows.
Disable simultaneous
multithreading
To disable simultaneous multithreading (SMT), also known as hyper-threading,
specify 1 thread per core.
- Console
-
- AWS CLI
-
To disable SMT during instance launch
Use the run-instances
AWS CLI command and specify a value of 1
for
ThreadsPerCore
for the --cpu-options
parameter. For CoreCount
, specify the number of CPU
cores. In this example, to specify the default CPU core count for an
r5.4xlarge
instance, specify a value of
8
.
aws ec2 run-instances \
--image-id ami-1a2b3c4d
\
--instance-type r5.4xlarge
\
--cpu-options "CoreCount=8
,ThreadsPerCore=1
" \
--key-name MyKeyPair
Specify a custom number of
vCPUs at launch
You can customize the number of CPU cores and threads per core when you launch an
instance from the EC2 console or AWS CLI. The examples in this section use an
r5.4xlarge
instance type, which has the following default settings:
-
CPU cores: 8
-
Threads per core: 2
Instances launch with the maximum number of vCPUs available for the instance
type by default. For this instance type, that's 16 total vCPUs (8 cores running 2 threads
each). For more information about this instance type, see
Memory optimized instances.
The following example launches an r5.4xlarge
instance with 4
vCPUs.
- Console
-
- AWS CLI
-
To specify a custom number of vCPUs during instance launch
Use the run-instances AWS CLI command and specify the number of
CPU cores and number of threads in the --cpu-options
parameter. You can specify 2 CPU cores and 2 threads per core to get
4 vCPUs.
aws ec2 run-instances \
--image-id ami-1a2b3c4d
\
--instance-type r5.4xlarge
\
--cpu-options "CoreCount=2
,ThreadsPerCore=2
" \
--key-name MyKeyPair
Alternatively, specify 4 CPU cores and 1 thread per core (disable
SMT) to get 4 vCPUs:
aws ec2 run-instances \
--image-id ami-1a2b3c4d
\
--instance-type r5.4xlarge
\
--cpu-options "CoreCount=4
,ThreadsPerCore=1
" \
--key-name MyKeyPair
Specify a custom number of
vCPUs in a launch template
You can customize the number of CPU cores and threads per core for the instance in
a launch template. The examples in this section use an r5.4xlarge
instance
type, which has the following default settings:
-
CPU cores: 8
-
Threads per core: 2
Instances launch with the maximum number of vCPUs available for the instance
type by default. For this instance type, that's 16 total vCPUs (8 cores running 2 threads
each). For more information about this instance type, see
Memory optimized instances.
The following example creates a launch template that specifies the configuration
for an r5.4xlarge
instance with 4 vCPUs.
- Console
-
To specify a custom number of vCPUs in a launch template
-
Follow the Create a launch template
by specifying parameters procedure and
configure your launch template as needed.
-
Expand Advanced details, and select the Specify CPU
options checkbox.
-
To get 4 vCPUs, specify 2 CPU cores and 2 threads per core, as
follows:
-
For Core count, choose
2.
-
For Threads per core, choose
2.
-
In the Summary panel, review your
instance configuration, and then choose Create launch
template. For more information, see Store instance launch parameters in Amazon EC2 launch templates.
- AWS CLI
-
To specify a custom number of vCPUs in a launch template
Use the create-launch-template AWS CLI command and specify the
number of CPU cores and number of threads in the
CpuOptions
parameter. You can specify 2 CPU cores
and 2 threads per core to get 4 vCPUs.
aws ec2 create-launch-template \
--launch-template-name TemplateForCPUOptions
\
--version-description CPUOptionsVersion1
\
--launch-template-data file://template-data
.json
The following is an example JSON file that contains the launch
template data, which includes the CPU options, for the instance configuration for this example.
{
"NetworkInterfaces": [{
"AssociatePublicIpAddress": true,
"DeviceIndex": 0,
"Ipv6AddressCount": 1,
"SubnetId": "subnet-7b16de0c
"
}],
"ImageId": "ami-8c1be5f6
",
"InstanceType": "r5.4xlarge
",
"TagSpecifications": [{
"ResourceType": "instance",
"Tags": [{
"Key":"Name
",
"Value":"webserver
"
}]
}],
"CpuOptions": {
"CoreCount":2
,
"ThreadsPerCore":2
}
}
Alternatively, specify 4 CPU cores and 1 thread per core (disable
SMT) to get 4 vCPUs:
{
"NetworkInterfaces": [{
"AssociatePublicIpAddress": true,
"DeviceIndex": 0,
"Ipv6AddressCount": 1,
"SubnetId": "subnet-7b16de0c
"
}],
"ImageId": "ami-8c1be5f6
",
"InstanceType": "r5.4xlarge
",
"TagSpecifications": [{
"ResourceType": "instance",
"Tags": [{
"Key":"Name
",
"Value":"webserver
"
}]
}],
"CpuOptions": {
"CoreCount":4
,
"ThreadsPerCore":1
}
}
Change CPU options for your EC2 instance
As your needs change over time, you might want to change the configuration of CPU options
for an existing instance. Each thread that runs on your instance is known as a virtual CPU (vCPU).
You can change the number of vCPUs that run for an existing instance in the Amazon EC2 console, AWS CLI,
API, or SDKs. The instance state must be Stopped
before you can make this change.
To view console or command line steps, select the tab that matches your environment. For API
request and response information, see ModifyInstanceCpuOptions in the Amazon EC2 API Reference.
- Console
-
Follow this procedure to change the number of active vCPUs for your instance from
the AWS Management Console.
Open the Amazon EC2 console at
https://console.aws.amazon.com/ec2/.
-
In the left navigation pane, choose Instances.
This opens the list of instances that are defined for the current AWS Region.
-
Select the instance from the Instances list. Alternatively,
you can select the instance link to open the instance detail page.
-
If the instance is running, you must stop it before you proceed. Choose
Stop instance from the Instance state
menu.
-
To change your vCPU configuration, choose Change CPU options
from Instance settings in the Actions menu.
This opens the Change CPU options page.
-
Choose one of the following CPU options to change the configuration for your instance.
- None
-
This option resets your instance to the default number of vCPUs
for your instance type. The default is to run all threads for all
CPU cores.
- Specify CPU options
-
This option enables configuration of the number of vCPUs that are
running on your instance.
-
If you selected Specify CPU options, the
Active vCPU configuration is displayed.
-
The first selector configures the number of threads that
run for each CPU core. To disable simultaneous multithreading,
you can change the number of threads that run per core to
1
.
-
The second selector configures the number of CPUs that are
running for your instance.
The following fields are updated dynamically, as you make changes to the CPU
option selectors.
-
Active vCPUs: The number of CPU cores multiplied
by the threads per core, based on the selections that you made. For example,
if you selected 2 threads and 4 cores, that would equal 8 vCPUs.
-
Total vCPUs: The maximum number of vCPUs for
the instance type. For example, for an m6i.4xlarge
instance
type, this is 16 vCPUs (8 cores running 2 threads each).
-
To apply your updates, choose Change.
- AWS CLI
-
Follow this procedure to change the number of active vCPUs for your instance from
the AWS CLI.
Use the modify-instance-cpu-options AWS CLI command and specify the number of CPU cores
that run in the --core-count
parameter, and the number of threads that
run per core in the --threads-per-core
parameter.
The following examples shows two possible configurations on an m6i.4xlarge
instance type to run 8 vCPUs on the specified instance. The default for this instance type
is 16 vCPUs (8 cores running 2 threads each).
Example 1: Run 4 CPU cores with 2 threads per core, for
a total of 8 vCPU.
aws ec2 modify-instance-cpu-options \
--instance-id i-1234567890abcdef0
\
--core-count=4
\
--threads-per-core=2
Example 2: Disable simultaneous multi-threading by changing
the number of threads that run per core to 1
. The resulting configuration also runs
a total of 8 vCPUs (8 CPU cores with 1 thread per core,).
aws ec2 modify-instance-cpu-options \
--instance-id i-1234567890abcdef0
\
--core-count=8
\
--threads-per-core=1