VMware {code} Community
nileshjais
Enthusiast
Enthusiast

How to improve time to fetch VM from vmhost.

Dear All,

Here is my code  which return VM count in

real0m38.877s
user0m13.869s
sys 0m0.503s

for below code, how do i improve the time to fetch the results.

my $host_name =  Opts::get_option('vmhost');

my $host_view = Vim::find_entity_view(view_type => 'HostSystem', filter => {'name' => $host_name});

&listVMs($host_view);

    sub listVMs {

    # Prints a list of registered VM on the screen.

    # Does not log it's use.

    #

        my ($host_view) = @_;

        my $vms = Vim::get_views(mo_ref_array => $host_view->vm, properties => ['name','runtime.powerState','guest.toolsRunningStatus']);

        my $totalVMs = 0;

        foreach(@$vms) {

            $totalVMs += 1;

            print "VM: ".$_->{'name'}.", ".$_->{'runtime.powerState'}->val.", "

                   .$_->{'guest.toolsRunningStatus'}.", ".$_->{'mo_ref'}->value."\n";

        }

        print "\nTotal ".$totalVMs." VMs found.\n\n"

    }

0 Kudos
1 Reply
stumpr
Virtuoso
Virtuoso

Add 'properties => ['name', 'vm']' to your $host_view get_view() call to reduce the host overhead. 

The only other overhead I can for see would be your script load time....you could compile your perl into an EXE or write a simple C++ program that does the same if that's the case.

But try the host property reduction first, the host objects are actually quite large.

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