Thursday, May 3, 2018

How many vCPU per pCPU.

virsh # nodeinfo
CPU model:           x86_64
CPU(s):              12
CPU frequency:       1200 MHz
CPU socket(s):       1
Core(s) per socket:  6
Thread(s) per core:  2
NUMA cell(s):        1
Memory size:         16741656 KiB


  • Socket - physical socket which the processor package sits in, on the motherboard
  • Processor package is what you get when you buy a single hardware processor.
  • Core - is a hardware term that describes the number of independent central processing units in a single computing component (Cores count = Sockets*Cores per socket)). vCPU count equals to the cores count
  • Thread - A Thread, or thread of execution, is a software term for the basic ordered sequence of instructions that can be passed through or processed by a single CPU core.
  • NUMA - Non-uniform memory access is a computer memory design used in multiprocessing, where the memory access time depends on the memory location relative to the processor. Under NUMA, a processor can access its own local memory faster than non-local memory (memory local to another processor or memory shared between processors). The benefits of NUMA are limited to particular workloads, notably on servers where the data is often associated strongly with certain tasks or users
  • ht Flag - Intel® Hyper-Threading Technology (Intel® HT Technology) delivers two processing threads per physical core - instructions are processed through two threads simultaneously,. Highly threaded applications can get more work done in parallel, completing tasks sooner. (also we see that Thread(s) per core equals to 2 - meaning that HT is enabled). Hyper-Threading doesn't double the performance, max performance increases are up to max 30%
  • CPU - equals Cores*Threads per core (in example case 6*2=12). vCPU count equals to CPU count

KVM uses Virtual CPU (vCPU) notion while assigning Processor CPU (pCPU) to the newly created virtual machine. vCPU is neither an OS thread nor a process.
Intel VT-x proposed a new mode methodology with two modes: VMX root mode and VMX non-root mode (VMX - Virtual Machine Extensions, this is set of CPU instructions added by Intel to their processors to support virtualization), for running host VMM (Virtual Machine Monitor=Hypervisor) and guest respectively.
Intel VT-x also contains a new structure: VMCS (Virtual Machine Control Structure - supports nested virtualization - a VM inside the VM ), which saves all information both host and guest need. VMCS is one per guest.
The guest code is running directly on CPU in VMX non-root mode. No software emulation layer for vCPU is needed. That’s why KVM has better performance, and there is no specific thread for guest.

A vCPU equates to 1 physical core, but (by default - rhel.link) when your VM attempts to process something, it can potentially run on any of the cores that happen to be available at that moment. The scheduler handles this, and the VM is not aware of it. You can assign multiple vCPUs to a VM which allows it to run concurrently across several cores. Cores are shared between all VMs as needed, so you could have a 4-core system, and 10 VMs running on it with 2 vCPUs assigned to each. VMs share all the cores in your system quite efficiently as determined by the scheduler. This is one of the main benefits of virtualization - making the most use of under-subscribed resources to power multiple OS instances.

The exact amount of CPU overcommitment a KVM host can accommodate will depend on the VMs and the applications they are running. A general guide for performance of {allocated vCPUs}:{total vCPU} from the Best Practices recommendations is:

  • 1:1 to 3:1 is no problem (the general recommendation is only using 1 vCPU per VM until you determine there is a need to add more than that. Over allocations of vCPU can cause lags in the VMs because too many are trying to use the same physical processors simultaneously. )
  • 3:1 to 5:1 may begin to cause performance degradation
  • 6:1 or greater is often going to cause a problem
So that if you will use overcommitment rate 3:1, then 12 vCPU (as in example) can be assigned as 36 vCPUs 

No comments:

Post a Comment