Understanding Resource Pools in VMware vSphere

It is my experience that resource pools are nearly a four letter word in the virtualization world. Typically I see a look of fear or confusion when I bring up the topic. Even with some other great resources out there that discuss this topic, a lack of education remains on how resource pools work, and what they do. In this post, I’ll give you my spin on some of the ideals behind a resource pool, show off a fancy infographic, and then discuss ways to properly balance resource pools by hand and with the help of PowerShell.

Who Needs Resource Pools?

That’s a good question. You can’t even make a resource pool on a cluster unless you have DRS running. So, if your license level excludes this technology, you don’t have to worry about resource pools at all. If you are graced with the awesomeness of DRS, you may need a resource pool if you want to “weight” different types of workloads for two scenarios:

  • For when memory and CPU resources become constrained on the cluster, and
  • … for when a workload needs a dedicated amount of resources at all times.

Now, this isn’t to say that a resource pool is the only way to accomplish these things – you can use per VM shares and reservations. But, these values sometimes reset when a VM vMotions to another host, and frankly it’s a bit of an administrative nightmare to manage resource settings on the VMs individually. I’ll give an exception to those using some sort of script, but it would require adding some creative solutions to identifying which VMs should be set to what resource values (folders, annotations, etc.).

The only debate more epic than resource pools is the infamous “Pancake vs Waffle” debacle

I personally like resource pools and use them often in a mixed workload environment. If you don’t have the luxury of a dedicated management cluster, resource pools are an easy way to dedicate resources to your vCenter, VUM, DB, and other “virtual infrastructure management” (VIM) VMs.

Why People Fear Resource Pools

People fear resource pools because they are mysterious like a wild unicorn. Ok, maybe not that mysterious, but they are a bit wonky at first. Also, they are easy to misunderstand, and thus misuse. Here is an infographic I’ve created that shows a typical scenario where someone has deployed a resource pool without understanding fully how they work. Look through the graphic and then we’ll discuss further. Have you had a chance to look at the picture? Hopefully yes, so let’s cover it.

Where Did I Get Those Numbers?

Let’s start with the resource pools. You’ll notice 3 bullet points for each pool – the shares setting (high or low), the amount of shares for RAM, and the amount of shares for CPU. Here’s the math and the documentation supporting it:

  • RAM is calculated like this: [Cluster RAM in MB] * [ 20 for High | 10 for Normal | 5 for Low]
  • Our cluster has 100 GB of RAM (see the blue section) and thus the math is: 102,400 MB of RAM * 20 = 2,048,000 for High and 102,400 MB of RAM * 5 = 512,000 for Low
  • CPU is calculated like this: [Cluster CPU Cores] * [ 2,000 for High, 1,000 for Normal, 500 for Low ]
  • Our cluster has 100 CPU cores (see the blue section) and thus the math is: 100 * 2,000 = 200,000 for High and 100 * 500 = 50,000 for Low

Based on this math, the Production resource pool has roughly 80% of the shares. However, when you divide those shares for the resource pool by the number of VMs that live in the resource pool, you start to see the problem. The bottom part of the infographic shows the entitlements at a Per VM level. Dev/Test has more than twice what Production has when looking at individual VMs.

Giving Dev/Test more weight than Production? Eeeeexcelent. (Doh!)

Maintaining the Balance

The trick to keeping your resource pools balanced is to work the math backwards and never, ever use the default high, normal, and low shares values. Decide the weight of your per VM shares first. Let’s say that I want my Dev/Test VMs to receive half as much share weight as Production. Instead of worrying about VMware’s default share value calculations above, create your own. Shares are an arbitrary value that just determine weight, they aren’t a magic number. So, let’s give Dev/Test VMs 50 shares each, and Production VMs 100 shares each. I would change the resource pools to this:

  • Production would get [ 90 VMs ] * [ 100 shares ] = 9,000 shares of RAM and CPU
  • Dev/Test would get [ 10 VMs ] * [ 50 shares ] = 500 shares of RAM and CPU

Much easier, right? Realistically, I could have just chosen a per VM share value of 2 for Production and 1 for Dev/Test. They would both do the same thing. Note! If the number of VMs in the resource pool change, you’ll need to update the resource pool shares value to reflect the added VMs. Your options are to manually update the pool when the number of VMs inside change (no fun) or use … PowerCLI!

Using PowerCLI to Balance Resource Pool Shares

Now that I’ve invoked the PowerCLI SpongeBob graphic (Wooo!) let’s do some coding. This very basic script will connect to the vCenter server and cluster specified and look at the resource pools within. It then reports on the number of VMs contained within and offers to adjust the shares value based on an input you provide. It confirms before making any changes (just click or answer No if you don’t want the change).

## Variables
$vcenter = $args[0]
$cluster = $args[1]

## Gather RPools
Connect-VIServer $vcenter
[array]$rpools = Get-ResourcePool -Location (Get-Cluster $cluster)
cls

## Enumerate Members of RPools
Foreach ($rpool in $rpools)
	{
	If ($rpool.name -ne "Resources")
		{
		[int]$pervmshares = Read-Host "How many shares per VM in the $($rpool.Name) resource pool?"
		$totalvms = $rpool.ExtensionData.Vm.count
		[int]$rpshares = $pervmshares * $totalvms
		Write-Host -ForegroundColor Green -BackgroundColor Black $rpool.name
		Write-Host "Found $totalvms in the $($rpool.name) resource pool. At $pervmshares each, this pool should be set to $rpshares shares."
		Set-ResourcePool -ResourcePool $rpool.Name -CpuSharesLevel:Custom -NumCpuShares $rpshares -MemSharesLevel:Custom -NumMemShares $rpshares -Confirm:$true | Out-Null
		}
	}

Make sure to change line 02 and 03 to specify your vCenter and cluster name. Feel free to distribute and modify at your leisure, I take no responsibility if your environment catches fire, becomes sentient, etc.

[symple_box color=”black” fade_in=”false” float=”center” text_align=”left” width=””]You can find all of my various PowerShell scripts in my GitHub repository[/symple_box]

Thoughts

I hope this has helped clear some confusion around resource pools, although it’s a big chunk to swallow in one bite, and I’m sure there are a lot of other competing opinions floating out there that won’t jive with mine. I’m OK with that. One thing I would like changed is the ability to set per VM shares on the resource pool, and let the pool automatically adjust for membership values.