PowerCLI – Create Report on pCPU vCPU ratios

The  pCPU to vCPU ratio is an important design consideration – it’s difficult to put a hard value on what is acceptable.
But you’d like to see the numbers, maybe you have an automated environment and some crazy project managers who deploy 50 muti-core vms at 9 am, resulting in DRS initiated VMotion events before you get to go for a coffee break…

Here are a reference by vcdx Scott Lowe

vsphere-oversubscription-best-practices

” vSphere 5 supports a ratio of up to 25:1, the ability to achieve a high ratio is very dependent on the kinds of workloads…

• 1:1 to 3:1 is no problem
• 3:1 to 5:1 may begin to cause performance degradation
• 6:1 or greater is often going to cause a problem

keeping the CPU Ready metric at 5% or below is considered a best practice.”

 

And another from Magnus Andersson (vcdx 56)
http://vcdx56.com/2014/06/01/vsphere-vm-vcpu-to-esxi-host-cpu-core-allocation/

 

First check the current pCPU to vCPU ratio per host

 Get-vCPUpCPU-Ratio.ps1

[code language=”powershell”]
# vmCpuHostCpuRatios
# Acknowledgement: http://www.vnoob.com/category/scripts/

Write-Host "—————————————————————————————————————-"
Write-Host " Collect vm vcpu and host pcpu ratios "
Write-Host "—————————————————————————————————————-"

param($vmhosts="*")

$vmhosts=Get-VMHost $vmhosts
$vms=Get-VM

$Output=@()

ForEach ($vmhost in $vmhosts)
{

$vcpus=0
$ratio=$null
$hostthreads=$vmhost.extensiondata.hardware.cpuinfo.NumCpuCores
$vms |Where-Object {$_.vmhost -like $vmhost}|ForEach {$vcpus+=$_.numcpu}
if ($vcpus -ne "0") {$ratio= "$("{0:N2}" -f ($vcpus/$hostthreads))" + ":1"}

$temp= New-Object psobject
$temp| Add-Member -MemberType Noteproperty "Hostname" -value $vmhost.name
$temp| Add-Member -MemberType Noteproperty "PhysicalThreads" -Value $Hostthreads
$temp| Add-Member -MemberType Noteproperty "vCPUs" -Value $vcpus
$temp| Add-Member -MemberType Noteproperty "Ratio" -Value $ratio
$Output+=$temp

}

$output | Export-Csv C:\vSpherePowerCLI\Output\vmCpuHostCpuRatios.csv
[/code]

 

Next check ready and co-stop values

csv is output to the the folder C:\vSpherePowerCLI\Output\ you might have to change that depending how you installed PowerCL
Keep in mind that the max value is a single sample, and the average is the average of all the samples, these are ball park values, the csv will make it easy to see potential problems, but the average values are flattening the hills and valleys.

 

Get-VmCpuCoStopValues.ps1

[code language=”powershell”]
# russ o. 10/06/2015
# vmCpuCostopValues
# Ref: http://www.virtu-al.net/2009/07/01/powercli-stats-one-liner/

Write-Host "—————————————————————————————————————-"
Write-Host " Collect cpu mhz, ready and co-stop values over past 2 hours and output averages "
Write-Host "—————————————————————————————————————-"

# Getting Cluster info
$Cluster = Get-Cluster
$countCL = 0
Write-Output " "
Write-Output "Clusters: "
Write-Output " "
foreach($oC in $Cluster){
Write-Output "[$countCL] $oc"
$countCL = $countCL+1
}
$choice = Read-Host "Which Cluster do you want to review?"
Write-Output " "
Write-Output "please wait for script to finish, it may take a while…."
Write-Output "Output will be saved to C:\vSpherePowerCLI\Output\vmCpuCostopValues.csv…"
$cluster = get-cluster $cluster[$choice]

$vms = Get-cluster $cluster | Get-VM

Get-VM $vms | Where {$_.PowerState -eq "PoweredOn"} |
Select Name, Host, NumCpu, `
@{N="Cpu.UsageMhz.Average";E={[Math]::Round((($_ |Get-Stat -Stat cpu.usagemhz.average -Realtime |Measure-Object Value -Average).Average))}},`
@{N="Cpu.Ready.Average";E={[Math]::Round((($_ |Get-Stat -Stat cpu.ready.summation -Realtime |Measure-Object Value -Average).Average)/200,1)}},`
@{N="Cpu.Costop.Average";E={[Math]::Round((($_ |Get-Stat -Stat cpu.costop.summation -Realtime |Measure-Object Value -Average).Average)/200,1)}} `
| Export-Csv C:\vSpherePowerCLI\Output\vmCpuCostopValues.csv
[/code]

Now at we have a an idea of what is going on, where the ratio is high, cpu ready is above 5%, and there are co-stop issues, we will need to investigate

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.