Another mega slow VIToolkit call (Get-HardDisk)

My good friend has found another VI Toolkit call that is amazingly slow compared to pulling useful data from it. I’ve done performance testing before of Get-VM against Get-View to get to the useful data needed day to day.   In that test using Get-View was 18x faster than using Get-VM.

This past week he was able to dig through the API/mob to find disk data for individual VMs for an internal tracking and reporting system we have.   This time he found a way to get the majority of useful data from Get-Harddisk a different way.   Rather significant change in speed with another couple hours of work.

This report he generates goes through about 1/2 of our VMs to pull VMDK information.

Get-HardDisk => 35 hours

New method => 2 mins 15 seconds

Yes.  That’s right.   976 times faster.   Do the math yourself.

Powershell speed – Get-VM vs. Get-Type -ViewType

I’ve been starting to look at using the VI Toolkit which uses Powershell.   In doing this many of the command formats tend to be “Get-VM | Get-View” or “Get-VMHost | Get-View“.   So I’m off and figuring this out and I run a small script and say “Geez that took a long time to run”.   I’m talking to my co-worker (a pretty smart cookie) and he says “Why don’t you just use “Get-View -ViewType VirtualMachine” and skip the middle man?”   Good point.  Didn’t know about that command.  Well this is just a tad bit faster.

Get-VM | Get-View timing in my script takes 1 minute and 37 seconds.

Get-View -ViewType VirtualMachine takes an amazing 5.12 seconds.

The VI Toolkit developers have identified this as a serious issue are working on ways to speed this up and retain backwards compatibility.

So the lesson today is if you need to do a Get-View immediately after doing some set collection look at using the Get-View -ViewType instead.  It isn’t as readable though it gets the job done well.