PowerCLI adjust ResPool share values

One thing that Frank Denneman (@frankdenneman) regularly bangs on about is not using Resource Pools as folders. And with good reason – setting up resource pools without understanding the effect on performance can cause significant issues.

We we first started working with RPs in ESX 3.x, I was blissfully unaware of this, and we have quite a lot of RPs these days – we use them to group application instances for example.

This isn’t an issue generally, as there just isn’t the resource contention to cause share based rationing to be invoked. Having said that, if we did hit a level of contention, the default number of shares per RP probably wouldn’t give us the performance we were after.

Ideally, we need some way of setting the RP shares to a more sensible value, based on the number of vCPUs and amount of vRAM allocated to the VMs within. Enter PowerCLI, stage left…

$rps = get-cluster "Cluster Name" | get-resourcepool | where-object  {$_.Name -ne "Resources"}
foreach($rp in $rps) {
 $cpucount = 0
 $memcount = 0
 $vms = $rp | get-vm
 foreach ($vm in $vms) {
  $cpucount += $vm.numcpu * 1000
  $memcount += $vm.memorygb * 10240
 }
 set-resourcepool $rp -numcpushares $cpucount -nummemshares $memcount
}

This will list all the RPs in a given cluster, count the vCPUs and vMEM assigned to the VMs in each, and set the CPU and Mem shares based on those numbers.
 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s