Set the number of threads per core Stay organized with collections Save and categorize content based on your preferences.
Simultaneous multithreading (SMT), which is known on Intel processors asHyper-Threading Technology (HTT), lets a CPU core run as two hardwaremultithreads. On Compute Engine, each virtual CPU (vCPU) is implemented as asingle hardware multithread, and two vCPUs share each physical CPU core bydefault.
Compute Engine lets you manually set the value for the number ofthreads per core. For example, workloads with the following concerns mightbenefit from disabling SMT (setting the number of threads per core to 1):
Performance: Reducing the number of threads that run on each physical CPUcore can help improve the performance of workloads that are highly-parallel orthat perform floating point calculations.
Security: If a VM runs untrusted code, reducing the number of threads percore can help mitigate CPU vulnerabilities such asMicroarchitectural DataSampling.
Licensing: Some licensing agreements have requirements related to thenumber of vCPUs that you consume. Reducing the number of threads per core from2 to 1 might reduce your licensing costs. For more information, consult yourlicensing agreement.
For many general computing tasks or tasks that require lots of I/O, SMT canincrease application throughput significantly. For compute-bound jobs in whichboth virtual cores are compute-bound, SMT can hinder overall applicationperformance and can add unpredictable variance to jobs. In this case, turningoff SMT allows more predictable performance and can decrease job times.
Important: Disabling SMT changes the way cores are counted and may increasethe cost per core. Although cost per core is a common metric for on-premiseshardware, a more appropriate metric for the cloud is cost per workload, orcost per job. For compute-bound jobs, you pay for what you use. Turning off SMTcan reduce the overall runtime, which can reduce the overall cost of the job.We recommend that you benchmark your application and use this feature whereit's beneficial.Limitations
You cannot set the number of threads per core on VMs for the followingmachine types:
- All C4A machine types
- All H4D machine types
- All H3 machine types
- All N4A machine types
- All Tau T2A machine types
- All Tau T2D machine types
- Machine types that have fewer than 2 vCPUs, for example,
n1-standard-1 - Shared-core machinetypes, such as
e2-small.
Forbare metal instances,the number of hyperthreads you have access to is equivalent to the numberof hyperthreads on the machine.
In the Google Cloud console, when the number of threads per core is setto 1, the CPU utilization metric can only scale up to a maximum of 50%. Whenthe number of threads per core is set to 2, the CPU utilization metric canscale up to 100%.
Pricing
You are billed for the number of vCPUs defined by a VM's machine type, not thenumber of threads that run on each core. For example, then2-standard-8machine type can run up to 8 vCPUs, which is 2 vCPUs for each of the 4 physicalCPU cores. If, with then2-standard-8 machine type, you decide to only run 1thread per core—effectively 4 vCPUs—you are still billed for 8vCPUs. For more information about how you are billed for VMs, seeVM instancepricing.
Change the number of threads per core during VM creation
To change the number of threads per core during VM creation, use theGoogle Cloud console, the gcloud CLI, or theCompute Engine API.
Permissions required for this task
To perform this task, you must have the followingpermissions:
- All permissions required tocreate a new VM
Console
To change the number of threads per core during VM creation, use the followingGoogle Cloud console procedure:
In the Google Cloud console, go to theCreate an instance page.
In theName field, enter a name for the VM.
Choose aRegion and aZone for the VM.
Choose aMachine family and a supportedMachine type.
ClickAdvanced configurations to expand the section.
InvCPUs to core ratio, choose the number of threads per core.
Finish configuring other settings for the VM and clickCreate.
gcloud
To change the number of threads per core during VM creation, use thegcloud compute instances create command.
Before using any of the command data below, make the following replacements:
- VM_NAME: the name for the new VM.
- ZONE: the zone for the new VM.
- MACHINE_TYPE: the machine type for the new VM. Must be a machine type with 2 or more vCPUs.
- THREADS_PER_CORE: the number of threads per physical core. Set to either
2or1.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloudcomputeinstancescreateVM_NAME\--zone=ZONE\--machine-type=MACHINE_TYPE\--threads-per-core=THREADS_PER_CORE
Windows (PowerShell)
gcloudcomputeinstancescreateVM_NAME`--zone=ZONE`--machine-type=MACHINE_TYPE`--threads-per-core=THREADS_PER_CORE
Windows (cmd.exe)
gcloudcomputeinstancescreateVM_NAME^--zone=ZONE^--machine-type=MACHINE_TYPE^--threads-per-core=THREADS_PER_CORE
You should receive a response similar to the following:
Created [https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME].NAME:VM_NAMEZONE:ZONEMACHINE_TYPE:MACHINE_TYPEPREEMPTIBLE:INTERNAL_IP:EXTERNAL_IPEXTERNAL_IP:INTERNAL_IPSTATUS: RUNNING
REST
To change the number of threads per core during VM creation, use theinstances.insertmethod with thethreadsPerCore field.
Before using any of the request data, make the following replacements:
- PROJECT_ID: the project ID.
- ZONE: the zone for the new VM.
- MACHINE_TYPE: the machine type for the new VM. Must be a machine type with 2 or more vCPUs.
- VM_NAME: the name for the new VM.
- THREADS_PER_CORE: the number of threads per physical core. Set to either
2or1.
HTTP method and URL:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances
Request JSON body:
{ "machineType": "projects/PROJECT_ID/zones/ZONE/machineTypes/MACHINE_TYPE", "name": "VM_NAME", "advancedMachineFeatures": { "threadsPerCore":THREADS_PER_CORE }, "disks": [ { "type": "PERSISTENT", "boot": true, "initializeParams": { "sourceImage": "projects/debian-cloud/global/images/family/debian-11" } } ], "networkInterfaces": [ { "network": "global/networks/default" } ]}To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Save the request body in a file namedrequest.json, and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances"
PowerShell (Windows)
Save the request body in a file namedrequest.json, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances" | Select-Object -Expand Content
APIs Explorer (browser)
Copy the request body and open themethod reference page. The APIs Explorer panel opens on the right side of the page. You can interact with this tool to send requests. Paste the request body in this tool, complete any other required fields, and clickExecute.
You should receive a JSON response similar to the following:
{ "kind": "compute#operation", "id": "7334609091572405391", "name": "operation-1663806045894-5e939085735d8-7499db32-c12fcc03", "zone": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE", "operationType": "insert", "targetLink": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME", "targetId": "1226375378512516273", "status": "RUNNING", "user": "EMAIL_ADDRESS", "progress": 0, "insertTime": "2022-09-21T17:20:48.751-07:00", "startTime": "2022-09-21T17:20:48.751-07:00", "selfLink": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/operations/operation-1663806045894-5e939085735d8-7499db32-c12fcc03"}Change the number of threads per core on a VM
To change the number of threads per core on a VM, use theGoogle Cloud console, the gcloud CLI, or theCompute Engine API.
Permissions required for this task
To perform this task, you must have the followingpermissions:
compute.instances.geton the projectcompute.instances.updateon the project
Console
To change the number of threads per core on an existing VM, use thefollowing Google Cloud console procedure:
In the Google Cloud console, go to theVM instances page.
Click theName of the VM.
ClickStopto stop the VM. If there is noStop option, clickMore actions >Stop.
ClickEdit.
ClickAdvanced configurations to expand the section.
In thevCPUs to core ratio drop-down list, choose the number ofthreads per core.
ClickSave.
gcloud
To change the number of threads per core on an existing VM, do thefollowing:
Export the properties of the VM by using the following
gcloud computeinstances exportcommand:gcloud compute instances exportVM_NAME \ --destination=YAML_FILE_PATH \ --zone=ZONE
Replace the following:
VM_NAME: the name of the VM from which toexport propertiesYAML_FILE_PATH: the path and filename of aYAML file in which to save the exported configuration dataZONE: the zone that contains the VM
In the VM configuration file that was saved inFILE_PATH,update the value for
threadsPerCore. If the value is not in the file,add the following: Tip: To avoid getting an error such asadvancedMachineFeatures: threadsPerCore:THREADS_PER_CORE
"ERROR: (gcloud.compute.instances.update-from-file) Cannot parse YAML: [Expected type, add quotes (for field value, found True (type )]" ' ') around any label values ofyesornoin the exported instance configuration file. This indicates the values are strings, not Boolean values.Update the VM with the new count of threads per core by using thefollowing
gcloud compute instances update-from-filecommand:gcloud compute instances update-from-fileVM_NAME \ --source=FILE_PATH \ --most-disruptive-allowed-action=RESTART \ --zone=ZONE
Replace the following:
VM_NAME: the name of the VM to updateFILE_PATH: the path to the updated VMconfiguration fileZONE: the zone that contains the VM to update
REST
To change the number of threads per core on an existing VM, use thefollowinginstances.updatemethod:
PUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME?most_disruptive_allowed_action=RESTART{ ... "advanced_machine_features": { ... "threadsPerCore": "THREADS_PER_CORE" }, ...}Replace the following:
PROJECT_ID: the ID of the projectZONE: the zone that contains the VMVM_NAME: the name of the VM from which toexport propertiesTHREADS_PER_CORE: the number of threads per core
View the number of threads per core
To view the number of threads per core, use the procedure that corresponds tothe OS that is running on the VM.
Linux
To view the number of threads per core on Linux-based VMs, use the followingprocedure:
Run the
lscpucommand.lscpu
Review the output to view the number of threads per core.
In the following sample output from an
n2-standard-16machine, the value for the number of threads percore is1as shown in theThread(s) per coreline....CPU(s): 8On-line CPU(s) list: 0-7Thread(s) per core: 1Core(s) per socket: 8Socket(s): 1NUMA node(s): 1Vendor ID: GenuineIntelCPU family: 6Model: 85Model name: Intel(R) Xeon(R) CPU @ 2.80GHz...
Windows
To view the number of threads per core on Windows-based VMs, use thefollowing procedure:
Launch Powershell.
Run the following command.
Get-WmiObject -Class Win32_processor | Select-Object NumberOfCores, @{Name="Thread(s) per core";Expression={$_.NumberOfLogicalProcessors/$_.NumberOfCores}}Review the output to view the number of threads per core.
In the following sample output from an
n2-standard-16machine, the value for the number of threads percore is1as shown in theThread(s) per corecolumn.NumberOfCores Thread(s) per core------------- ------------------ 8 1
What's next
- Learn about theoperating systems that you can run on Compute Engine VMs.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.