The existing method in _check_instance_not_already_created() of looking for a supplied instance name by looping over the return from driver.list_instances() is horribly inefficient.
Run the attached script to show how inefficient it is...
On a host with just 10 tiny instances running, doing a simple libvirt.connection.lookupByName(XXX) is an order of magnitude faster than looping through the results of listDomainsID() and looking up the name of the instance using lookupByID():
jpipes@librebox:~/repos/junk$ python test_check_instance_name.py
Num running domains: 10
name in [conn.lookupByID(i).name()
for i in conn.listDomainsID()]
Found: False
took 0.00712 seconds
try: conn.lookupByName(x)
found = True
except libvirt.libvirtError:
found = False
libvir: QEMU error : Domain not found: no domain with matching name 'instance-1234567'
Found: False
took 0.00083 seconds
The existing method in _check_ instance_ not_already_ created( ) of looking for a supplied instance name by looping over the return from driver. list_instances( ) is horribly inefficient.
Run the attached script to show how inefficient it is...
On a host with just 10 tiny instances running, doing a simple libvirt. connection. lookupByName( XXX) is an order of magnitude faster than looping through the results of listDomainsID() and looking up the name of the instance using lookupByID():
jpipes@ librebox: ~/repos/ junk$ python test_check_ instance_ name.py
Num running domains: 10
name in [conn.lookupByI D(i).name( ) sID()]
for i in conn.listDomain
Found: False
took 0.00712 seconds
try: conn.lookupByNa me(x) libvirtError:
found = True
except libvirt.
found = False
libvir: QEMU error : Domain not found: no domain with matching name 'instance-1234567'
Found: False
took 0.00083 seconds