Link to home
Start Free TrialLog in
Avatar of sglee
sglee

asked on

How to assign CPUs to virtual machines

User generated imageHi,
 I have a new server running Hyper-V 2019 and it came with two Intel Silver 4110  @2.1Ghz (8 core) CPUs and 64GB of RAM.
 I have 4 virtual machines - (1) Domain Controller (2) Application Server (just files and folders)  (3) Remote Desktop Server (for two remote users running Word/Excel)  (4) Windows 10 (only used if & when I need to do some testing). There are 8 users on the network.
 I am curious what would be best way to assign CPUs to VMs since there are two physical CPUs.
 Currently each VM has 1 virtual processors as I accepted "default value" when creating these VMs except manually assigned RAM amount.
 
Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Adam Brown
Adam Brown
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You bought way too much CPU for current workloads. If you set your BIOS to allow CPU to sleep, that will save a little bit on your power bill. YOu can literally run 10 x or more VMs on the given CPU. RAM and storage is another issue.

General best practice is to assign 1 vCPU per VM, unless the VM has a demonstrated need for more. This rule really applies if you have more VMs than physical cores. The hypervisor needs to schedule all cores assigned to a VM before it can execute anything. As an extreme example, imagine that you have two VMs, each with 24 vCPU assigned. A hypervisor can't schedule a single core for the VM, even if it's only 1 thread in the VM that needs CPU time. The hypervisor needs to schedule all cores at once before the VM can execute anything. This means that the other VM can't do anything at that time, as there aren't enough physical cores to support both VMs and the hypervisor at the same time. Each VM would spend at least 50% of the time waiting for its turn to get CPU time.

In your case though, if each VM got 2 vCPU, that would be only half of the total available physical cores, so they could all run at 100% which would still leave half of the CPU power left for the hypervisor. This is ignoring hyperthreading.

I will often give 2 vCPU to Windows VMs just so Windows Updates runs faster. Windows Updates is significantly faster with 2 vCPU over 1 vCPU. Most other things don't seem to matter much, unless you have a busy Exchange Server.
(1) Domain Controller - 2 vCPUs 2GB vRAM
(2) Application Server (just files and folders)   - 2 vCPUs 4GB vRAM
(3) Remote Desktop Server (for two remote users running Word/Excel)   - 2 vCPUs 8GB vRAM - 16GB vRAM (depends on user experience)
(4) Windows 10 - 2 vCPUs 4GB vRAM

If there's a database setup with management such as Sage/Intuit in #2 then bump that up to 8GB vRAM.
You have  a LOT of cores there, for the VMs you have in use.  I typically use a 2:1 overcommit, but in your case it might be better to just use 1:1, assuming the W10 box is not running.  

So, I suppose:
RDP server: 16 cores.
DC: 8 cores
App server: 8 cores.
W10 box 8 cores.

This means every VM has way more cores that it is ever likely to need.

Another option might be to disable hyperthreading, and allocating half the number of cores to each VM. Hyperthreading gives you double the number of cores, however the additional ones are quite a bit slower than the base ones. Thus, you will possibly get better single core performance, if some application pegs a core.
I suggest starting with the configuration I mentioned. Assigning too many vCPUs to a VM can actually have a detrimental effect on performance.

I have two very thorough EE articles on all things Hyper-V:

Some Hyper-V Hardware and Software Best Practices
Practical Hyper-V Performance Expectations

Some PowerShell Guides:
PowerShell Guide - Standalone Hyper-V Server
PowerShell Guide - New VM PowerShell
PowerShell Guide - New-VM Template: Single VHDX File
PowerShell Guide - New-VM Template: Dual VHDX Files

Here are some focused articles:
Slipstream Updates Using DISM and OSCDImg

Protecting a Backup Repository from Malware and Ransomware

Disaster Preparedness: KVM/IP + USB Flash = Recovery. Here’s a Guide