From 32e88e580b42f698f5540a44aacd2698093c9bca Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Fri, 18 Mar 2022 10:41:33 -0400 Subject: [PATCH] switch to a deque this makes more of the data structure someone else's responsibility and probably improves performance too (but I didn't measure) --- src/allmydata/stats.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/allmydata/stats.py b/src/allmydata/stats.py index b893be6ff..a123ff1d8 100644 --- a/src/allmydata/stats.py +++ b/src/allmydata/stats.py @@ -1,6 +1,8 @@ """ Ported to Python 3. """ + +from collections import deque from time import process_time import time @@ -26,7 +28,7 @@ class CPUUsageMonitor(service.MultiService): # up. self.initial_cpu = 0.0 # just in case eventually(self._set_initial_cpu) - self.samples = [] + self.samples: list[tuple[float, float]] = deque([], self.HISTORY_LENGTH) # we provide 1min, 5min, and 15min moving averages TimerService(self.POLL_INTERVAL, self.check).setServiceParent(self) @@ -37,8 +39,6 @@ class CPUUsageMonitor(service.MultiService): now_wall = time.time() now_cpu = process_time() self.samples.append( (now_wall, now_cpu) ) - while len(self.samples) > self.HISTORY_LENGTH+1: - self.samples.pop(0) def _average_N_minutes(self, size): if len(self.samples) < size+1: