Change in vdsm[master]: vm: restore unresponsive on timeout when sampling

fromani at redhat.com fromani at redhat.com
Mon Feb 23 12:35:06 UTC 2015


Francesco Romani has uploaded a new change for review.

Change subject: vm: restore unresponsive on timeout when sampling
......................................................................

vm: restore unresponsive on timeout when sampling

For quite obscure historical reasons, VDSM marks
a VM as unresponsive if stats are unavailable for too long.

The benefit of this behaviour is questionable, but it was
broken as side effect of the transition of new periodic,
bulk sampling.

This patch restores the former behaviour, until we decide
to get rid of it.

Change-Id: Id8cd75631c328aa380c10f1f6dd1a8075b2fe0ed
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/virt/sampling.py
M vdsm/virt/vm.py
2 files changed, 44 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/66/38066/1

diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py
index f8063c4..508f3c1 100644
--- a/vdsm/virt/sampling.py
+++ b/vdsm/virt/sampling.py
@@ -22,7 +22,7 @@
 Support for VM and host statistics sampling.
 """
 
-from collections import deque
+from collections import defaultdict, deque
 import errno
 import logging
 import os
@@ -365,6 +365,18 @@
         _, last_sample = self._samples[-1]
         return last_sample
 
+    def values(self):
+        """
+        TODO
+        """
+        if len(self._samples) < 2:
+            return None, 0, None, 0
+
+        first_timestamp, first_sample = self._samples[0]
+        last_timestamp, last_sample = self._samples[-1]
+        return (first_sample, first_timestamp,
+                last_sample, last_timestamp)
+
 
 class AdvancedStatsFunction(object):
     """
@@ -409,18 +421,25 @@
                      logging.getLogger("sampling.VmStats"))
         self._samples = SampleWindow(2)
         self._last_sample_time = 0
+        self._vm_last_timestamp = defaultdict(int)
 
     def get(self, vmid):
-        first_batch, last_batch, interval = self._samples.stats()
-        if first_batch is None:
-            first_sample = None
-        else:
-            first_sample = first_batch.get(vmid)
-        if last_batch is None:
-            last_sample = None
-        else:
-            last_sample = last_batch.get(vmid)
-        return (first_sample, last_sample, interval)
+        (first_batch, first_batch_timestamp,
+         last_batch, last_batch_timestamp) = self._samples.values()
+
+        first_sample, first_timestamp = self._fetch(
+            vmid, first_batch, first_batch_timestamp)
+
+        last_sample, last_timestamp = self._fetch(
+            vmid, last_batch, last_batch_timestamp)
+
+        self._vm_last_timestamp[vmid] = max(
+            self._vm_last_timestamp[vmid], first_timestamp, last_timestamp)
+
+        elapsed_time = last_timestamp - first_timestamp
+        stats_age = utils.monotonic_time() - self._vm_last_timestamp[vmid]
+
+        return (first_sample, last_sample, elapsed_time, stats_age)
 
     def put(self, bulk_stats, monotonic_ts):
         if monotonic_ts >= self._last_sample_time:
@@ -429,6 +448,17 @@
         else:
             self._log.warning('dropped stale old sample')
 
+    def _fetch(self, vmid, batch, timestamp):
+        if batch is None:
+            sample = None
+        else:
+            sample = batch.get(vmid)
+
+        if sample is None:
+            return None, 0
+        else:
+            return sample, timestamp
+
 
 vmstats = VmStats()
 
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 070ebaa..e876c4b 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -1264,10 +1264,11 @@
 
         decStats = {}
         try:
-            first_sample, last_sample, interval = sampling.vmstats.get(self.id)
+            (first_sample, last_sample,
+             interval, stats_age) = sampling.vmstats.get(self.id)
             decStats = vmstats.produce(self,
                                        first_sample, last_sample, interval)
-            self._setUnresponsiveIfTimeout(stats, interval)
+            self._setUnresponsiveIfTimeout(stats, stats_age)
         except Exception:
             self.log.exception("Error fetching vm stats")
         for var in decStats:


-- 
To view, visit http://gerrit.ovirt.org/38066
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id8cd75631c328aa380c10f1f6dd1a8075b2fe0ed
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list