From 1c8ad4553b4b8d404f941c5297e3f6e42c9f7e6a Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Sun, 12 Feb 2012 13:34:14 -0500 Subject: Completes fix for LP #928910 - libvirt performance This patch adds the remainder of the recommended fixes from the original bug report: * Modifies methods in the compute manager that relied on the DB power state to be in sync with the virt driver to instead just query the power state of the instance from the virt driver. This enables us to set the periodic tick to 10 for the problematic compute.manager.Manager._sync_power_states() method. * Modifies the _sync_power_states method in the following ways: ** Replace the call to driver.list_instances_detail() to a new, driver-overrideable get_num_instances() call ** For each instance known by the database, call driver.get_info() separately inside the loop instead of calling the expensive list_instances_detail() method that can take a very long time to complete on hosts with lots of instances ** Call greenthread.sleep(0) before each call to update the database power state, enabling other periodic tasks to do work Once again, I left an inefficient default implementation of the new driver.get_num_instances() method in the base driver class. I need help from folks who understand the Xen/VMWare drivers to do an override for get_num_instances() in those drivers that calls the underlying XenAPI or VMWare API. Change-Id: I88002689cdda32124423da320f8c542e286be51b --- nova/virt/driver.py | 13 +++++++++++++ nova/virt/libvirt/connection.py | 4 ++++ 2 files changed, 17 insertions(+) (limited to 'nova/virt') diff --git a/nova/virt/driver.py b/nova/virt/driver.py index f1d382ac4..dff3fbdff 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -122,6 +122,19 @@ class ComputeDriver(object): # TODO(Vek): Need to pass context in for access to auth_token raise NotImplementedError() + def get_num_instances(self): + """Return the total number of virtual machines. + + Return the number of virtual machines that the hypervisor knows + about. + + :note This implementation works for all drivers, but it is + not particularly efficient. Maintainers of the virt drivers are + encouraged to override this method with something more + efficient. + """ + return len(self.list_instances()) + def instance_exists(self, instance_id): """Checks existence of an instance on the host. diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 087dba446..ad547f99c 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -281,6 +281,10 @@ class LibvirtConnection(driver.ComputeDriver): else: return libvirt.openAuth(uri, auth, 0) + def get_num_instances(self): + """Efficient override of base instance_exists method.""" + return self._conn.numOfDomains() + def instance_exists(self, instance_id): """Efficient override of base instance_exists method.""" try: -- cgit