What do you mean share resources?

Sharing is caring

Resource pools are certainly nothing new in the world of virtualization but they can still come up as a topic of debate on how to be properly managed. Whether you use them or not largely depends on your environment. If your environment is fairly lax on resource over provisioning and utilization then there is a good chance you do not touch resource pools. But if you are trying to get the most out of your hardware contention can and will come up so you need to have a way to set priority for your resources.

The meat

The quick and dirty of it is that each pool will share the resources assigned to it with the VMs that reside in it. Seems pretty straight forward but that is where the issue stands. If you stick with default share values and give production 4000 shares (high) and dev 1000 shares (low) but have 50 production servers to 10 dev servers you are essentially giving production VMs 80 slices out of that initial share value and dev VMs 100 slices. This is why custom shares are needed to properly scale resource pools to insure performance under contention. Most experts (for example Chris Wahl and Duncan Epping), agree that the proper way to maintain resources pools is to use custom share values based on the number of VMs in each resource pool. I am going to share a script that I wrote to help manage some of these pains in a more automated fashion.

The TL;DR version of the script can be as easy as:

$pools = Get-ResourcePool | Where-Object {$_.Name -ne "Resources"}
ForEach ($pool in $pools){
$vmCount = $pool.ExtensionData.vm.count
$poolShare = read-host ("Enter share value for Pool: {0}" -f $pool)
$shares = $poolShare * $vmCount
Set-ResourcePool -ResourcePool $pool.Name -NumCpuShares $shares -NumMemShares $shares

This basic script will require you to already be connected to the vCenter Server that you want to make the changes to and it will not play very well with nested resource pools (Those can be problematic and an administrative nightmare on their own). This quick script is a good way to test the process in lab or as a base to build out your own script, but it certainly is not a good way to automate any production vcenter.

The following script is more production ready with a more logic and error handling built in. It and can be located here: https://github.com/gmadro/vMadBro/tree/master/Set-Pool

The script is composed of three parts. The main script: Set-Pool.ps1, a functions script: Set-Pool-Functions.ps1, and a configuration file: Set-Pool.jsonI try to make my code as modular as I can and I have set a practice of using a functions script and configuration file for all of my scripts. This way I can keep the main script as lean as possible but also make it easy to make configuration changes by having all of that data in the JSON. With this script any share changes or pool additions would go into the JSON with no changes to the main script required.

What would you say… you do here?

What the script will do:

# Audit the Resource Pools on the connected vcenter server
# Report on VMs that are in the default resource pool (Thus taking resource priority over VMs in your own pools)
# Validate that pools exist in in JSON config
# Set default share value for any pool not speficied in JSON
# Change Resource Pool share values based on values set in JSON
# Check for child pools (One layer deep (Parent > Child). More than that could become an administrative nightmare)


A future addition may be to move an VMs located in the default folder into a specified folder or to use VM tags to move them into their proper pool. I may also work on and post a Python version of the script because I am just that kind of masochist. If this is of value to you…or if my coding is complete crap please let me know. I welcome the feedback and criticism: @gregmadro or Greg Madro