×


Selecting the number of vCPUs and Cores for a Virtual Machine

Need support with selecting the number of vCPUs and Cores for a Virtual Machine?

This guide is for you.

As part of our Server Management Services here at Ibmi Media, we regularly help our Customers to perform Virtual Machine VM related tasks.

In this context, we will learn about how to set the number of cores per CPU in a virtual machine.


More information about vCPU ?

A vCPU is the abbreviation for a virtual centralized processing unit. As for a definition, a vCPU represents a portion or share of the underlying, physical CPU that is assigned to a particular virtual machine (VM).


Here are a few terms you need to be aware of.


Hypervisor

We can consider a hypervisor as a controller. It sometimes refers to as a virtual machine monitor (VMM). Simply put, a hypervisor is a software to create and run virtual machines (VMs).

It allows one host computer to support multiple guest VMs by virtually sharing its resources such as memory and processing. Hypervisors are smart enough to allocate resources whether a single vCPU or numerous vCPUs.


Socket

We can consider a socket as hardware. It is an array of pins that hold a processor in place and connect the motherboard to the available processing power. The number of sockets is determined by the capacity of the motherboard.

There are differences in sockets depending on which generation CPU it supports.


Thread

A thread is a path of execution within a process. A process contains one or more threads. A thread is also known as a lightweight process. The concept of parallelism is to divide a process into multiple threads.

For instance, having multiple tabs open in a browser represents different threads. For word processing, there can be multiple threads such as one for formatting text and another thread for processing inputs.


Physical Core

A physical core, refers to as processing units, within the CPU. A single physical core may correspond to one or more logical cores.


Logical Core

A logical core makes it possible for a single physical core to perform two or more actions simultaneously. Logical cores made the concept of hyper-threading (HTT) possible.

Newer cores are more like full-fledged CPUs so they are capable of working on multiple tasks simultaneously. However, they are not true CPUs as the physical cores are.


How to Calculate vCPU ?

The hypervisor controls virtual servers and their resource allocation. It uses a portion of the physical CPU computing resources and allocates it to a vCPU which assigns to a specific VM.

System administrators can use hypervisors to setup different resource allocations with specific VMs configuration and with specific vCPU capabilities.

In the past, there was a rule of thumb that there were eight vCPUs per core. Today, mostly the manufacturer determines the vCPU count.

We calculate it by taking the number of processing threads that a chipset offers per core and multiplying the number of occupied sockets.


Here is how it looks:

(Threads x Cores) x Physical CPU = Number vCPU

 

Example Calculation of vCPU & Cores

Here, our Support Engineers demonstrate how to calculate vCPU and cores through an example.

First, we need to select a virtual server and CPU. Here, we select Intel Xeon E-2288G as the underlying CPU. Key stats for the Intel Xeon E-2288G include 8 cores/16 threads with a 3.7GHz base clock and a 5.0GHz turbo boost. There is 16MB of onboard cache.

(16 Threads x 8 Cores) x 1 CPU = 128 vCPU

 

Determine Your Workload & Utilization

First, we need to know the workload and application profiles. By knowing the requirements, we can make an informed decision on the underlying hardware.

Theoretically, if we have small VMs that barely use any CPU time, we can easily get 20-30 VMs from an 8-core server. However, if we have larger workloads such as a database server, we will have far fewer VMs from that same 8 core server.

It is all about resource utilization and allocation.


Next, let us look at some different configuration options. We are doing this just as an example.


Each vCPU allocation to each VM will depend on its specific workload.

4 vCPUs per VM
128 vCPUs/4 vCPUs per VM = 32 VMs
2 vCPUs per VM
128 vCPUs/2 vCPUs per VM = 64 VMs
1 vCPUs per VM
128 vCPUs/1 vCPUs per VM = 128 VMs

 

CPU Exhaustion & Poor Performance

There is such a thing as CPU exhaustion which can cause poor performance for our virtual machines. The number of virtual cores assigned to a VM is limited.

For example, Windows Server 2008 R2 limits the number of vCPUs as 4 per VM which is extended to 64 in Windows server 2012.

When creating virtual machines in different hypervisors, we may see that sometimes a virtual machine may not see all virtual processor sockets (vCPU) assigned to it.

In our case, 8 vCPUs were assigned to a KVM virtual machine and Windows 10 was installed on it as a guest OS. However, Windows detected this vCPUs as separate processors (not cores) and it could use only 2 of them.


[Is the vCPUs calculation confusing? We'd be happy to assist. ]


How to go about Selecting the number of vCPUs and Cores for a Virtual Machine ?

Moving ahead, we will see the process of Selecting the number of vCPUs and Cores for a Virtual Machine.


Windows 10 Virtual Machine

If we open Windows Device Manager, we can make sure that all allocated cores are visible as 8 separate virtual processors QEMU Virtual CPU version 2.5+.


At the same time, Windows 10 properties (Computer -> Properties) and Task Manager show that only 2 QEMU Virtual processors are available.

It means that Windows 10 is able to use only 2 cores no matter how many of them you will add.

At the same time, a virtual server running Windows Server 2016 on the same hypervisor can see all 16 vCPUs allocated to it.


Number of Processors Supported in Windows

The problem is that desktop Windows versions have a restriction on the maximum number of physical processors a computer can use:

Windows 10 Home – 1 CPU
Windows 10 Professional – 2 CPU
Windows 10 Workstation – up to 4 CPU
Windows Server 2016 – up to 64 CPU

However, this restriction is not related to the number of cores.

In order to improve the performance of the virtual machine, we can use a processor with more cores. Most hypervisors can provide vCPUs as processors, processor cores, or even threads. It means that instead of 8 vCPUs, we can add 2 vCPUs with 4 per socket.


Let us see how to assign virtual processors as cores in different hypervisors and how to bind them to the NUMA architecture used in modern processors.


How to go about Managing Virtual Core & vCPU in KVM ?

In our KVM virtual machine running Windows 10, all assigned virtual cores are considered as separate processors.

To use all CPU resources allocated to a virtual machine, it must see one 8 core processor, 2 vCPUs with 4 cores each, or 1 vCPU with 4 cores in two threads instead of 8 vCPUs.

Now we try to change the allocation of virtual cores for the KVM virtual machine.


Initially, shut down your virtual machine:

# virsh shutdown w10testvm – where w10testvm is the name of your virtual machine

Here are the aspects of a KVM virtual machine management from the console using virsh.

Display the current XML configuration of the KVM virtual machine:

# virsh dumpxml w10testvm

We need a block describing the VM CPU settings:

<vcpu placement=’static’>8</vcpu>
<cputune>
<shares>1000</shares>
</cputune>
<resource>
<partition>/machine</partition>
</resource>
<os>
<type arch=’x86_64′ machine=’pc-i440fx-rhel7.6.0′>hvm</type>
<bootmenu enable=’yes’/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>

As you can see, 8 vCPUs are set here. Let us change the configuration:

# virsh edit w10testvm

Then, we add the following block after </features>:

<cpu mode='host-passthrough' check='none'>
<topology sockets='1' cores='4' threads='2'/>
</cpu>
Where:
host-passthrough is the emulation mode in which the virtual machine sees the physical processor of the cluster node
sockets='1' indicates that there is one vCPU (socket)
cores='4' the processor has 4 cores per socket
threads='2' ieach core has 2 threads

Save the configuration file and start the virtual machine.

Then log in to the Windows 10 guest VM, run Task Manager or Resource Monitor, and make sure that the Windows sees all allocated virtual cores.

A physical processor of the host, Intel(R) Xeon(R) Silver 4114 CPU, now display instead of a virtual one in the system properties.

Here is how we manage to solve the heavy load issue for the VM since two cores have not been enough for the apps to work properly.


[Stuck somewhere in the process of configuring VMWARE vCPU? We are here for you.]


How to go about Setting the number of vCPUs and Cores for a VMWare VM ?

We can change the way of vCPU presentation for a VMWare virtual machine in the vSphere Client interface.

i. Shut the VM down and open its settings

ii. Then expand the CPU section

iii. Change the VM configuration so that the guest OS can see 2 processors with 4 cores each. Change the value Cores per Socket to 4. It means that the guest OS will see two 4-core CPUs (2 sockets with 4 cores per socket).

iv. Finally, save the changes and run the VM.


[Couldn't set the number of vCPUs in VMWare VM ? We can help you !]


 More about Virtual Machine vCPU and NUMA Architecture ?

There are some more aspects of assigning vCPUs and cores to virtual machines.

When assigning the number of cores per socket, we make sure to have NUMA architecture. It is not recommended to assign more cores per socket to a VM than the number of cores available on the physical socket (NUMA node).


When we place it on a single physical NUMA node, a virtual machine will be able to use fast local RAM available on the specific NUMA node. Otherwise, processes will have to wait for the response from another NUMA node.

Generally, if we assign two separate virtual sockets to a VM, the hypervisor can run them on different NUMA nodes. It will affect VM performance.

If the number of vCPUs needed is more than the number of cores on 1 physical socket, we create several virtual sockets with the necessary number of cores.

Also, it is not recommended to use an odd number of processors (it is better to add 1 vCPU). It allows to maintain the virtual machine performance.


For example, it is recommended to use the following configuration for a 2-processor host with 10 cores per socket (40 vCPUs are available in total including Hyper-Threading) when we configure vCPUs for a VM:

vCPU Number Needed       Number of Virtual Sockets in the VM Settings       Number of Cores per a Virtual Processor in the VM Settings
1                        1                                                  1
……
10                      1                                                  10
11                      Not optimal
12                       2                                                  6
……
20                       2                                                 10


In a free ESXi version, we cannot create a VM with more than 8 vCPUs.

For example, a VM running Microsoft SQL Server 2016 Enterprise Edition with 16 vCPU will have poorer performance than a VM with 2 Sockets x 8 Cores per Socket.


Also, remember that some applications license depends on the number of physical sockets. Sometimes it is more profitable to license one multicore processor than multiple processors with a less number of cores.


[Looking for an easy fix to Linux related errors? Contact us now!]


Conclusion

This articles will guide you when selecting the number of vCPUs and Cores for a Virtual Machine which depends on the operating system used and some other factors.

Basically, When Selecting the Number of #vCPUs and #Cores for a Virtual Machine, you can use all CPU #resources allocated to a virtual machine, it must see one 8 core #processor, 2 vCPUs with 4 cores each or 1 vCPU with 4 cores in two threads instead of 8 vCPUs.