Advanced Extensions Learning Performance Reporting vCenter

Get-View Part 3: Peformance Impact – Is it really THAT much different?


Get-View

In Get-View Part 1: Introduction I introduced the advanced feature Get-View and a little bit about what it does. In Get-View Part 2: Views and Extension Data I talked about how we can interact with the data found in Get-View and the ways we can grab that information. In Part 3, we discuss performance and speed…

Overview

In the past two Get-View posts we’ve talked about what Get-View is and how it works. Some say (including myself) that using Get-View is faster than using other Get-* commands. Well, I decided it was time to put it to the test. Thankfully I had a number of awesome folks from the community that volunteered to run some scripts for me that would generate a CSV for me of how long it took for each command to run. I want to preface this with a few comments:

  • 8 different environments were used (anywhere from home labs to work environments)
  • Get- Commands were run because we didn’t want to bother anyones environments (some were ok with running a storage re-scan, others opted out as you will see in the charts)
  • The environments ranged from 5 – 108 hosts and 7 – 1373 VMs
  • I did not count the number of datastores, vDS, or datacenters in each environment, however I think you’ll get an idea of the performance differences in each of these environments without needing those (although it would have been great of me to get… next time I guess).

So as you can see below, Each environment (X-Axis is the same number throughout the charts/tests) This first image shows us the rough size of each environment. image.png

The first commands we ran were measuring performance between Get-VM and Get-View -viewtype VirtualMachine.  as you can see, Get-VM took significantly longer to return all the results, Environment 3 showed the highest increase of 1,249% (if we refer back to the first graph we see that this was with 1373 VMs). Get-VM took 337.35 seconds to execute whereas Get-View only took 25 seconds.

image.png

Next was Get-Datacenter vs Get-View -viewtype Datacenter image.png

Although not as significant as the Get-VM results, the Get-Datacenter vs. Get-View results show that there is a 321% difference between the two cmdlets. Even though the max time to return the datacenters was only 1.6 seconds, if you are working on trimming down the duration of scripts, every bit counts.

Get-VMHost vs. Get-View

image.png

Get-VMHost took 61% longer to return values than the Get-View equivalent. When solely returning the hosts in a given vCenter, 319 seconds (roughly 5 1/2 minutes) is still significantly greater than the 198 seconds (3 minutes) of Get-View. (The duration specified here was in an environment with 108 hosts, as opposed to the other environments with between 5 – 66 hosts used in these tests.)

Get-Datastore vs. Get-View

image.png

Get-VDSwitch vs Get-View

image.png

Again, we see that using the Get-* cmdlet’s as opposed to the Get-View format continues to take much longer. The greatest difference in these tests was 1940% (.4 seconds vs 8.16 seconds).

Get-VM | Select Name, NumCPU, MemoryMB, PowerState vs. Get-Viewimage.png

Starting in this test, we measured running the Get-* cmdlet and selecting specific properties from the results. This is a little bias because When running Get-VM and using Select-Object returns all data and then shows only the properties that are specified, whereas Get-View leveraging the -Property parameter, will only search for and return those specific properties, rather than searching all, and returning only a portion. The Get-View method will almost always be faster.

Commands used for the graph above:

$getvmstats = Measure-Command {Get-VM | Select-Object Name,NumCPU,MemoryMB,PowerState} $viewvmstats = Measure-Command {Get-view -viewtype VirtualMachine -property Name,Summary.config.NumCPU,Summary.config.MemorySizeMB,Summary.runtime.PowerState }

RescanAllHba and RescanVmfs vs. Get-Viewimage.png

 

This test was an interesting one, because of the nature of the command. This was an optional test for users to run and as you can see in the examples, several users opted out of running these commands. This was set to rescan all HBAs and VMFS datastores, obviously it’s something we discourage from doing in Production, and in a smaller test environment, it is up to the user. The code run is found below:

$getstoragescan = Measure-Command {Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs} $viewstoragescan = Measure-Command {$myhosts = get-view -viewtype hostsystem; $dstore = get-view $myhosts.ConfigManager.StorageSystem; $dstore.rescanallHba(); $dstore.rescanvmfs()}

Running the commands from the API Methods available in Get-View, once again is faster.

Get-VM (IP address, CPUHotAdd) vs. Get-Viewimage.png

The final example I want to show is running Get-VM with a Foreach command, vs. Get-View with a foreach command. This is a little different than previous tests because we aren’t using the view -Property parameter so both commands will return all their data before writing out select properties.

Commands used:

  • $GetVMSpecifics = Measure-Command {get-vm | ForEach-Object { Write-Host $_.name $_.extensionData.guest.IpAddress, $_.extensiondata.config.CpuHotAddEnabled}}
  • $ViewVMSpecifics = Measure-Command {get-view -viewtype VirtualMachine | ForEach-Object { Write-Host ($_.name + ” ” + $_.guest.IpAddress + ” ” + $_.config.CpuHotAddEnabled)}}

Additional Points

The biggest issue I see customers have with using Get-View, is that, as stated in the Get-View 2: blog post,  once invoking Get-View, you are no longer using a VIObject, rather a view object, and other PowerCLI cmdlets do not work off of it. This seems to be the biggest detractor from using Get-View more, however, keep in mind that not only do you have the tasks that can be run off of the view object, the object can also be converted back into a VIObject using the Get-VIObjectByVIView cmdlet, and then running other PowerCLI cmdlets from there.

Data Points

Below is a table of all of the datapoints received for these tests. Each column represents each environment tested (1-8).

Screenshot-2015-02-22-22.55.03.png

Conclusion

As this has probably shown. Get-View commands are going to be significantly faster in returning data and processing commands than the Get-* counterparts. Is there anything wrong with using Get-VM, Get-Datastore, Get-VdsSwitch, etc.? Absolutely not. However, the purpose of this was to allow you to understand how to use the View side of PowerCLI for faster retrievals which can be very beneficial when running time-sensitive monitoring or large scripts.

Stay tuned for Part 4: Deeper Dive into the vSphere API