Bobcares

Selecting the number of vCPUs and Cores for a Virtual Machine

by | Jan 2, 2021

Need help with selecting the number of vCPUs and Cores for a Virtual Machine? At Bobcares, we assist our customers with several VM queries on a daily basis as part of our Server Management Services.

Overview
  1. What is a vCPU?
  2. How to Calculate vCPU?
  3. Selecting the number of vCPUs and Cores for a Virtual Machine
  4. Setting the number of vCPUs and Cores for a VMWare VM
  5. Conclusion

What is a 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 our Support Engineers suggest 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 calculation heavy? We’d be happy to assist]

 

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+.

Selecting the number of vCPUs and Cores for a Virtual Machine

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.

 

  • 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? We are here for you]

 

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.

  1. Shut the VM down and open its settings
  2. Then expand the CPU section
  3. 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)
    Selecting the number of vCPUs and Cores for a Virtual Machine
  4. Finally, save the changes and run the VM.

[Couldn’t set the number? We can help you!]

 

  • 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? We’re available 24/7.]

 

Conclusion

To conclude, selecting the number of vCPUs and Cores for a Virtual Machine depends on the operating system used and some other factors. Today we saw how our Support Techs go about with this query.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF