December 20, 2022
Hyper-V Virtual Machine Load Balancing
One of the main benefits of the virtualization of an environment is rational resources usage. When specific virtual machines are not needed, they can be powered off; this allows freed up computing resources to be provisioned to the VMs that are needed. Hyper-V Failover Cluster allows you to reduce downtime in your virtual machines; and beginning from editions for Windows Server 2016, Hyper-V can provide VM load balancing between Hyper-V hosts (which are called cluster nodes in this case).
This blog post covers the VM Load Balancing feature for Hyper-V Failover clusters and explores the working principle, the configuration parameters, as well as the advantages of using Load Balancing in Hyper-V virtual environments.
What Is Hyper-V VM Load Balancing and How Can This Feature Be Used?
Load Balancing is a feature that ensures optimization in the utilization of Hyper-V hosts’ resources within a cluster. A VM load can become uneven over time; as a result, Hyper-V hosts can become either more or less loaded. This, in turn, may result in some of the nodes being temporarily unavailable during patching or other maintenance processes. Hyper-V cluster can provide enough computing resources for VMs with the Load Balancing feature in which VMs are migrated from one node to another when one node is overloaded and another node has free computing resources. This feature is used to provide sufficient performance for VMs within a Hyper-V cluster, and as a result, helps keep high quality for the provided services that run on VMs.
How Does Load Balancing Work?
Load Balancing automatically checks a Hyper-V cluster state, and then depending on the results and settings found, it initiates VM migration from the overloaded node to the less loaded node in order to redistribute loads across Hyper-V hosts.
There two methods that can be used to check host loads:
- Checking RAM (random-access memory) utilization. Insufficient memory on a Hyper-V host is one of the most common problems, and can cause lags.
- Checking CPU (central processor unit) utilization. Insufficient processor capacity can also cause lags.
The more CPU and RAM resources are consumed by a host, the more loaded the host is considered by Hyper-V. If periodic load balancing is configured for a cluster, then the load of the hosts is evaluated every 30 minutes. You can also evaluate the hosts’ load on demand. A system identifies the hosts in which the load exceeds the defined threshold, as well as the hosts in which the load is under the threshold value. If the current load of cluster nodes is uneven and meets the mentioned conditions, Hyper-V will initiate VM live migration between the nodes. Hyper-V Live Migration allows you to perform VM migration unnoticeably, and without significant downtime.
The integration of Load Balancing with a Hyper-V Failover Cluster is provided. The following clustering rules are honored for load balancing: Possible Owners, Anti-affinity (these two rules existed before Windows Server 2016), and Fault Domains (new).
The Possible Owners rule defines the Hyper-V hosts for which the migration can be performed. This rule only defines possible VM owners, and can prevent VM migration to unwanted hosts.
Anti-affinity rules allow you to prevent running two defined VMs on the same host. For example, if you have two VMs with both a primary and a secondary Domain Controller that must not run on the same host. This approach increases reliability in a case of the host with one of the Domain Controllers fails.
Fault domain is a feature that defines a set of Hyper-V hosts that can be affected for some types of physical failure, for example, network failure, power failure etc. Hyper-V hosts with VMs of the same fault domain are usually connected to the same power source and network switch, thus they can be mounted to the same rack. If any failures occur, then all VMs of the same fault domain would be affected. A cluster can be logically broken (divided) into multiple fault domains, and failure of one domain should not affect other domains.
Load Balancing is enabled by default for Failover Clusters in Hyper-V 2016. There are two types of behavior: “Use only when a new node is added to the cluster” and “Check with time intervals”.
Use only when a new node is added to the cluster. In this case, a cluster gets more CPU as well as RAM resources, and extends the overall computing capacity. A system evaluates the load of each node. If any of the nodes are overloaded (a threshold value set in the configuration is exceeded), then the appropriate VMs are migrated from overloaded nodes to recently added nodes that have free resources. This option is useful if you regularly add capacity to your Hyper-V Failover Cluster, and may be useful for clusters based on Storage Spaces technology. This option doesn’t have an impact on a cluster if the node that was previously disconnected from the cluster (for maintenance, for example) is connected back to the cluster.
Check with time intervals. This option initiates checking cluster nodes’ loads every 30 minutes. If any of the nodes are overloaded (a threshold value set in configuration is exceeded), then the appropriate VMs are migrated from overloaded nodes to nodes that have free resources.
Aggressiveness threshold is a parameter that defines the aggressiveness of balancing, which is based on RAM and CPU utilization by nodes. Aggressiveness threshold can be one of three values: Low (1), Medium (2) and High (3). You can see more details about the configuration in the section below.
Hyper-V Load Balancing can be configured by using either GUI (graphical user interface) or PowerShell. To configure Hyper-V Load Balancing, start by opening Failover Cluster Manager, right-click your cluster name and select Properties in the context menu.
In the Properties window, select the Balancer Tab. Check/Uncheck the box if you want to enable/disable load balancing. You can select the balancing mode and aggressiveness.
You can also set the balancing mode or disable automatic balancing in PowerShell:
(Get-Cluster).AutoBalancerMode = <value>
Where <value> can be 0, 1 or 2 (see the table below).
|1||Load Balance to a node when it joins|
|2 (used by default)||Always load balance|
In order to set the aggressiveness threshold, type the following command in PowerShell:
(Get-Cluster).AutoBalancerLevel = <value>
Where <value> can be 1, 2 or 3 (see the table below).
|1 (used by default)||Low||VMs are moved when host load is more than 80%|
|2||Medium||VMs are moved when host load is more than 70%|
|3||High||VMs are moved when host load is more than 60%|
System Center Virtual Machine Manager (SCVMM) can also be used for cluster management as an alternative to using Failover Cluster Manager. SCVMM includes the Dynamic Optimization feature (available since Windows Server 2012) that also redistributes a VM between cluster nodes. If you have Hyper-V Load Balancing enabled and use the SCVMM Dynamic Optimization, then Load Balancing will be disabled automatically once you enable Dynamic Optimization in SCVMM. In this case, load balancing management is taken by SCVMM in order to prevent conflicts that may be caused by the simultaneous working of two features and related issues. Microsoft recommends you to use SCVMM with Dynamic Optimization.
The Advantages of Hyper-V Load Balancing
Load Balancing is a helpful feature. The advantages of using load balancing for Hyper-V Failover Cluster include:
- No overloading of physical servers
- No overloading of VMs
- Improved application responsiveness
- Improves the quality of provided services
- Improves the scalability for your services and applications
- Mitigates failures
NAKIVO Backup & Replication and Backing Up Clustered VMs
Hyper-V Failover Cluster is an effective solution that can both improve the availability of running VMs, as well as protect them against possible hardware failure of the nodes. In order to protect your data against other types of disaster, VM Backup & Replication should be used. VMs residing on the clustered Hyper-V hosts can migrate between hosts during events such as failover or load balancing. As a result, backing up the needed VM may appear difficult because you would be required to detect the host on which the VM resides (host-level VM backup is considered). NAKIVO Backup & Replication is a fast, reliable, and affordable VM data protection solution that supports Hyper-V clusters. NAKIVO Backup & Replication can automatically track which host the VM resides on once you have added the entire cluster to the inventory and, as a result, the process of making VM backups or replicas from Hyper-V cluster becomes as easy as backing up the VMs from standalone Hyper-V hosts.
Hyper-V Load Balancing is a useful clustering feature that is included in Hyper-V for Windows Server 2016. The feature helps you to use hardware resources more rationally and, as a result, improves the quality of the provided services. CPU and RAM metrics are used for making decisions to redistribute the loads. Load Balancing automatically initiates VM migration from overloaded nodes to the nodes with free resources when a threshold value (set in configuration) is exceeded. There is no significant downtime because Live Migration is used. Hyper-V Failover Cluster with load balancing protects your VMs against node failure in addition to providing high availability and enough computing resources for VMs.
NAKIVO Backup & Replication can help you protect Hyper-V VMs in the best way possible, whether in a cluster or not. Downoad the Full-Featured Free Trial to see for yourself.