[Kimchi-devel] [PATCH] Stop collecting background stats
Christy Perez
christy at linux.vnet.ibm.com
Mon Feb 16 23:36:30 UTC 2015
Kimchi was taking up CPU cycles when no one was using it. In order
to reduce CPU overhead, only collect information when someone has
called the get_list function.
Signed-off-by: Christy Perez <christy at linux.vnet.ibm.com>
---
src/kimchi/model/vms.py | 39 ++++++++++++++++++++-------------------
1 file changed, 20 insertions(+), 19 deletions(-)
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
index b5fdb12..0117fb0 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -81,16 +81,12 @@ def __init__(self, **kargs):
self.conn = kargs['conn']
self.objstore = kargs['objstore']
self.caps = CapabilitiesModel(**kargs)
- self.guests_stats_thread = BackgroundTask(GUESTS_STATS_INTERVAL,
- self._update_guests_stats)
- self.guests_stats_thread.start()
-
- def _update_guests_stats(self):
- vm_list = self.get_list()
-
- for name in vm_list:
+
+ @staticmethod
+ def _update_guests_stats(names, conn):
+ for name in names:
try:
- dom = VMModel.get_vm(name, self.conn)
+ dom = VMModel.get_vm(name, conn)
vm_uuid = dom.UUIDString()
info = dom.info()
@@ -108,16 +104,17 @@ def _update_guests_stats(self):
seconds = timestamp - prevStats.get('timestamp', 0)
stats[vm_uuid].update({'timestamp': timestamp})
- self._get_percentage_cpu_usage(vm_uuid, info, seconds)
- self._get_network_io_rate(vm_uuid, dom, seconds)
- self._get_disk_io_rate(vm_uuid, dom, seconds)
+ VMsModel._get_percentage_cpu_usage(vm_uuid, info, seconds)
+ VMsModel._get_network_io_rate(vm_uuid, dom, seconds)
+ VMsModel._get_disk_io_rate(vm_uuid, dom, seconds)
except Exception as e:
# VM might be deleted just after we get the list.
# This is OK, just skip.
kimchi_log.debug('Error processing VM stats: %s', e.message)
continue
- def _get_percentage_cpu_usage(self, vm_uuid, info, seconds):
+ @staticmethod
+ def _get_percentage_cpu_usage(vm_uuid, info, seconds):
prevCpuTime = stats[vm_uuid].get('cputime', 0)
cpus = info[3]
@@ -128,7 +125,8 @@ def _get_percentage_cpu_usage(self, vm_uuid, info, seconds):
stats[vm_uuid].update({'cputime': info[4], 'cpu': percentage})
- def _get_network_io_rate(self, vm_uuid, dom, seconds):
+ @staticmethod
+ def _get_network_io_rate(vm_uuid, dom, seconds):
prevNetRxKB = stats[vm_uuid].get('netRxKB', 0)
prevNetTxKB = stats[vm_uuid].get('netTxKB', 0)
currentMaxNetRate = stats[vm_uuid].get('max_net_io', 100)
@@ -155,7 +153,8 @@ def _get_network_io_rate(self, vm_uuid, dom, seconds):
stats[vm_uuid].update({'net_io': rate, 'max_net_io': max_net_io,
'netRxKB': netRxKB, 'netTxKB': netTxKB})
- def _get_disk_io_rate(self, vm_uuid, dom, seconds):
+ @staticmethod
+ def _get_disk_io_rate(vm_uuid, dom, seconds):
prevDiskRdKB = stats[vm_uuid].get('diskRdKB', 0)
prevDiskWrKB = stats[vm_uuid].get('diskWrKB', 0)
currentMaxDiskRate = stats[vm_uuid].get('max_disk_io', 100)
@@ -249,13 +248,15 @@ def create(self, params):
return name
def get_list(self):
- return self.get_vms(self.conn)
+ return VMsModel.get_vms(self.conn)
@staticmethod
def get_vms(conn):
- conn = conn.get()
- names = [dom.name().decode('utf-8') for dom in conn.listAllDomains(0)]
- return sorted(names, key=unicode.lower)
+ conn_ = conn.get()
+ names = [dom.name().decode('utf-8') for dom in conn_.listAllDomains(0)]
+ names = sorted(names, key=unicode.lower)
+ VMsModel._update_guests_stats(names, conn)
+ return names
class VMModel(object):
--
2.1.0
More information about the Kimchi-devel
mailing list