Windows Server How-To
How To Limit Hyper-V Virtual Machine CPU Consumption
Many approaches taken with physical hardware can work here as well.
Server virtualization is based on the idea that server hardware has become so powerful in recent years that most workloads do not require a dedicated server. Instead, a number of virtual machines can share the resources present within a physical machine. The downside, however, is that if too many virtual machines are placed on a host server then resource contention can become an issue.
Any server, no matter how powerful it might be, has a limited supply of hardware resources such as memory or processing power. Making efficient use of these resources is something of an art form. Administrators must ensure that virtual machines receive the resources that they need, but prevent those same virtual machines from consuming so many resources that the resource consumption begins to negatively impact other virtual machines that are running on the host.
When it comes to throttling resource consumption, most of the emphasis has traditionally been placed on bandwidth and memory. After all, those tend to be some of the resources that have the greatest impact on virtual server performance. Even so, managing CPU resources can also be important.
Hyper-V gives administrators two main ways of limiting a virtual machine's CPU consumption. The first method involves controlling virtual processor allocation. This usually means maintaining a reasonable ration between logical and virtual processors.
For all practical purposes, you can think of a logical processor as a physical CPU core. For example, if a server has two physical CPUs that each have six cores then the server has twelve logical processors.
A virtual processor is the processor that you assign to a virtual machine. In Hyper-V 2012 R2, a virtual machine can have up to eight virtual processors, as shown in Figure 1.
There is no direct correlation between virtual processors and logical processors. For instance, if a server is equipped with 12 logical processors then you are not limited to assigning 12 virtual processors. In other words, a virtual processor is not a direct representation of a physical CPU core.
One way to control a virtual machine's CPU consumption is to limit virtual processor assignments. Even though you can assign up to eight virtual CPUs to a virtual machine, many VMs run just fine with one or two virtual processors. There are no firm rules about how many virtual CPUs you can collectively assign to your virtual machines, and the recommendations seem to vary based on who you talk to. Many people recommend that you create no more than eight virtual processors for every one logical processor in your server. Keep in mind however, that if you are running CPU intensive workloads then the ratio should probably be much lower.
The other way in which you can reserve CPU resources is by using the resource controls shown in the figure above. As you can see in the figure, there are several different controls that you can use to limit CPU consumption on a per VM basis in an effort to better balance your workloads.
The available controls include:
Virtual Machine Reserve (percentage): This is the percentage of logical processor resources that Hyper-V will reserve for the virtual machine. If for example, a VM has two virtual CPUs then setting this value to 50 percent would cause an entire logical CPU to be reserved.
Percent of Total System Resources: This value is populated automatically and reflects the percentage of logical processor resources that are being reserved. Suppose, for instance, that a system has six logical processors and a VM is configured to use one virtual processor and has a reservation set to 50 percent. The VM is effectively reserving 50 percent of one logical processor, or 8 percent of the total logical processor resources that are available on the system.
Virtual Machine Limit (percentage): This setting limits the amount of the host's logical processor capacity that can be consumed.
Percent of Total System Resources: This value is populated automatically and shows the percentage of logical processors resources that can be used.
Relative Weight: The relative weight setting is used to prioritize virtual machines that are competing for CPU resources. VMs with a higher relative weight have a higher priority.
As you can see, Hyper-V gives administrators quite a bit of control over CPU resource consumption. By configuring the number of virtual processors assigned to a VM and by setting reservations and limits, it is possible to establish fine grained control over a VM's physical CPU utilization.
Brien Posey is a 19-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site.