[Users] Python SDK list vms slow, excessive cpu usage

Sander Grendelman sander at grendelman.com
Tue Dec 17 14:04:21 UTC 2013

Fetching the list of vms through the API with the python SDK
takes several seconds[1] with 100% cpu usage in the python script.

When I look at the engine log there is only one (fast) fetch from
the API. The rest of the time is spent in the SDK processing a
relatively small bit of XML data (only 26 VMs in my environment).

This seems an excessive amount of CPU for processing ~6KB of XML.

I've included some sample code [2] and output [3].
Attached is the cProfile output for this call and a visualization.

[1] ~6,5 seconds on an oVirt VM with 1 vcpu on older hardware,
    ~3,5 seconds on a fast physical machine with an i5 cpu.

[2] Sample code, add your own url/credentials/certificate:

"""Get ovirt VM names"""

import time

from ovirtsdk.api import API
from ovirtsdk.xml import params

def print_elapsed(logString):
    elapsed = time.time() - startTime
    print "%fs %s" % (elapsed, logString)

startTime = time.time()

print_elapsed("before connect")
api = API(
        username="user at domain",
print_elapsed("after connect")

print_elapsed("before fetch list")
vmList = api.vms.list()
print_elapsed("after fetch list")

print_elapsed("before use list")
count = 0
for vm in vmList:
  vmName = vm.get_name()
  count += 1

print "\t number of VMs %d" % count

[3] Example of output:

[grendelmans at bungee src]$ /usr/bin/time ./vm_list_test.py
0.000003s before connect
0.338248s after connect
0.338299s before fetch list
6.795967s after fetch list
6.796041s before use list
     number of VMs 26
6.796181s after use list
7.28user 0.05system 0:07.64elapsed 96%CPU (0avgtext+0avgdata 84624maxresident)k
0inputs+0outputs (0major+5605minor)pagefaults 0swaps
[grendelmans at bungee src]$
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vm_list_test.svg
Type: image/svg+xml
Size: 146842 bytes
Desc: not available
URL: <http://lists.ovirt.org/pipermail/users/attachments/20131217/0e00782f/attachment-0001.svg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vm_list_test.pstat
Type: application/octet-stream
Size: 346878 bytes
Desc: not available
URL: <http://lists.ovirt.org/pipermail/users/attachments/20131217/0e00782f/attachment-0001.obj>

More information about the Users mailing list