With all the focus (including mine) being on that other critical resource, (dynamic) memory, it is good to also review what Hyper-V does for CPUs. These articles explain exactly how CPU scheduling works in Hyper-V.
Virtual machine reserve
This is configured as a percentage of the total possible CPU usage of a virtual machine. The virtual machine reserve functions in a couple of ways.
The first one is when a virtual machine is turned on. We will not let a virtual machine turn on if we determine that it is not possible to honor the virtual machine reserve. For example, if you configured each of your (4 virtual processor) virtual machines (on our fictitious computer) with a reserve of 20% we would only let you start 5 virtual machines. When you tried to start a 6th virtual machine you would get an error message stating that you cannot initialize the virtual machine.
Note that you will get this error even if all 5 running virtual machines are completely idle and are not using any CPU resource.
The second way that the virtual machine reserve is used is when there is contention for resource on the CPU. Simply put – if there is higher demand for CPU than is physically available, we will ensure that a virtual machine that needs CPU resource gets at least its CPU reserve.
What surprises some people is that we do not enforce the reserve when there is no contention for CPU resource. To explain what I mean by this:
Imaging our fictitious setup with 5 virtual machines, each with a 20% reserve, and all 5 virtual machines running and idle (0 CPU utilization). At this point in time all CPU resource has been reserved. Now, what will happen if one of these virtual machines tries to use 100% of available CPU resource while the others remain idle? In short – we will let the virtual machine have 100% of the available CPU.
The reason for this is that we can always take CPU resource back from a virtual machine. So as long as we know that the sum total of running virtual machines do not exceed 100% CPU reserve, we can let any given virtual machine chew into another virtual machines reserve, because when it is needed we can make sure the reserve is honored.
A final interesting note about the virtual machine reserve is that by default it is set to “0%” – which means the reserve is disabled. Furthermore – if you have a configuration like the one we have been discussing where all CPU is reserved, you can still start extra virtual machines as long their CPU reserve is set to 0%.
The lesson to learn here is that you should not get over-zealous with the virtual machine reserve, as things can get confusing.
Virtual machine limit
This is the second resource control setting that you can configure on the processor settings for a virtual machine and, like the virtual machine reserve, it is configured as a percentage of the total possible CPU usage of a virtual machine.
The virtual machine limit (or CPU limit) simply states that a virtual machine will never be allowed to use more than the specified percentage of its virtual processors – and compared to the other controls it is relatively easy to understand.
How do people use the CPU limit?
There is really only one common usage for the CPU limit – and that is for dealing with poorly written applications.
The classic scenario here is that you have a flaky application that is key to your operating environment – but every now and then it just gets confused and starts chewing up all the CPU resource it can. In these cases – you can use the CPU limit to make sure that it does not run away with all of your system resources.