VMware {code} Community
natxoasenjo
Enthusiast
Enthusiast
Jump to solution

poor performance script

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.

Reply
0 Kudos
1 Solution

Accepted Solutions
stumpr
Virtuoso
Virtuoso
Jump to solution

Yes, if you're finding PowerCLI faster than Perl than you are definitely missing something Smiley Happy  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();

Reuben Stump | http://www.virtuin.com | @ReubenStump

View solution in original post

Reply
0 Kudos
2 Replies
stumpr
Virtuoso
Virtuoso
Jump to solution

Yes, if you're finding PowerCLI faster than Perl than you are definitely missing something Smiley Happy  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();

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos
natxoasenjo
Enthusiast
Enthusiast
Jump to solution

$ time perl hostinfo

....

real    0m1.507s

user    0m0.431s
sys    0m0.037s

:slightly_smiling_face: Awesome. Glad I was wrong. Thanks for the tip.

Reply
0 Kudos