Skip to content

Commit

Permalink
Fix XenAPI performance issue
Browse files Browse the repository at this point in the history
This patch implements 'list_instance_uuids' in the xenapi virt driver so
that compute manager's '_get_instances_on_driver' can operate more
efficiently.

Fixes bug 1097980

The cleanup_running_deleted_instances periodic task uses the above call
while context has been modified to be read_deleted='yes'.  Without
list_instance_uuids being implemented in xenapi, there's a fallback to
querying all instances on the host.  Because of read_deleted='yes', this
queries all instances that have ever lived on the host.  In a very busy
environment where instances are repeatedly built and destroyed, one can
end up with thousands of deleted instances.  Now that we are storing
instance_type data in system_metadata and system_metadata is joined with
every instance_get, this results in 10x the number of rows being
returned with sqlalchemy... the fallback doesn't perform well enough.

Change-Id: I4bbfd69c9769807cec813af757665f03d9643460
  • Loading branch information
comstud committed Mar 18, 2013
1 parent f14cd69 commit f9a89b7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions nova/tests/test_xenapi.py
Expand Up @@ -374,6 +374,19 @@ def test_list_instances_0(self):
instances = self.conn.list_instances()
self.assertEquals(instances, [])

def test_list_instance_uuids_0(self):
instance_uuids = self.conn.list_instance_uuids()
self.assertEquals(instance_uuids, [])

def test_list_instance_uuids(self):
uuids = []
for x in xrange(1, 4):
instance = self._create_instance(x)
uuids.append(instance['uuid'])
instance_uuids = self.conn.list_instance_uuids()
self.assertEqual(len(uuids), len(instance_uuids))
self.assertEqual(set(uuids), set(instance_uuids))

def test_get_rrd_server(self):
self.flags(xenapi_connection_url='myscheme://myaddress/')
server_info = vm_utils._get_rrd_server()
Expand Down
6 changes: 6 additions & 0 deletions nova/virt/xenapi/driver.py
Expand Up @@ -164,6 +164,12 @@ def list_instances(self):
"""List VM instances."""
return self._vmops.list_instances()

def list_instance_uuids(self):
"""Get the list of nova instance uuids for VMs found on the
hypervisor.
"""
return self._vmops.list_instance_uuids()

def spawn(self, context, instance, image_meta, injected_files,
admin_password, network_info=None, block_device_info=None):
"""Create VM instance."""
Expand Down
12 changes: 12 additions & 0 deletions nova/virt/xenapi/vmops.py
Expand Up @@ -190,6 +190,18 @@ def list_instances(self):

return name_labels

def list_instance_uuids(self):
"""Get the list of nova instance uuids for VMs found on the
hypervisor.
"""
nova_uuids = []
for vm_ref, vm_rec in vm_utils.list_vms(self._session):
other_config = vm_rec['other_config']
nova_uuid = other_config.get('nova_uuid')
if nova_uuid:
nova_uuids.append(nova_uuid)
return nova_uuids

def confirm_migration(self, migration, instance, network_info):
name_label = self._get_orig_vm_name_label(instance)
vm_ref = vm_utils.lookup(self._session, name_label)
Expand Down

0 comments on commit f9a89b7

Please sign in to comment.