hi,
I want to get the same info as using this powercli snippet:
get-view -ViewType HostSystem -Property Name,Config.Product | select Name,{$_.Config.Product.FullName}
And this is the code I came up with:
#!/usr/bin/env perl
use strict;
use warnings;
use VMware::VIRuntime;
use VMware::VILib;
$SIG{__DIE__} = sub{Util::disconnect();};
Opts::parse();
Opts::validate();
Util::connect();
my $esxhost_view = Vim::find_entity_views(view_type => 'HostSystem');
for my $host ( sort { $a->name cmp $b->name } @$esxhost_view ) {
| print $host->name . "\t" . $host->config->product->fullName . "\n" ; |
}
Both get me the info I require, so that's cool. The performance difference between them is huge, though, so I was wondering if I was doing something wrong on the Perl side ;-). On a linux vm it takes 45 seconds to get the info, on a windows vm with similar resources I get the info with powercli in 10 seconds.
Thanks for any pointers.
Yes, if you're finding PowerCLI faster than Perl than you are definitely missing something
I have never seen PowerCLI beat out lower level API calls (which Perl can use). Even a Get-View call has a larger subset of properties than you probably want in many cases. HostSystems are also one of the larger constructs in the vSphere WebService API, so they will show the slowest retrieval times.
In the example above, you're getting every object property value. This is slower than PowerCLI because it gets a smaller subset. But if you only need two properties in your script, you can trim it even further for better results.
Try the following to get better performance:
#!/usr/bin/env perl
use strict;
use warnings;
use VMware::VIRuntime;
$SIG{__DIE__} = sub{Util::disconnect();};
Opts::parse();
Opts::validate();
Util::connect();
my $esxhost_view = Vim::find_entity_views(view_type => 'HostSystem', properties => ['config.product.fullName', 'name']);
for my $host ( sort { $a->name cmp $b->name } @$esxhost_view ) {
print $host->name . "\t" . $host->{'config.product.fullName'} . "\n" ; }
Util::disconnect();
Yes, if you're finding PowerCLI faster than Perl than you are definitely missing something
I have never seen PowerCLI beat out lower level API calls (which Perl can use). Even a Get-View call has a larger subset of properties than you probably want in many cases. HostSystems are also one of the larger constructs in the vSphere WebService API, so they will show the slowest retrieval times.
In the example above, you're getting every object property value. This is slower than PowerCLI because it gets a smaller subset. But if you only need two properties in your script, you can trim it even further for better results.
Try the following to get better performance:
#!/usr/bin/env perl
use strict;
use warnings;
use VMware::VIRuntime;
$SIG{__DIE__} = sub{Util::disconnect();};
Opts::parse();
Opts::validate();
Util::connect();
my $esxhost_view = Vim::find_entity_views(view_type => 'HostSystem', properties => ['config.product.fullName', 'name']);
for my $host ( sort { $a->name cmp $b->name } @$esxhost_view ) {
print $host->name . "\t" . $host->{'config.product.fullName'} . "\n" ; }
Util::disconnect();
$ time perl hostinfo
....
real 0m1.507s
user 0m0.431s
sys 0m0.037s
Awesome. Glad I was wrong. Thanks for the tip.
