From b50401261400a7667a214172d6e0daabd67e5f1e Mon Sep 17 00:00:00 2001 From: Adam King Date: Thu, 7 Oct 2021 10:09:12 -0400 Subject: [PATCH] cephadm: agent: subtract average time of previous iterations off wait time We want the agent to actually report metadata at the rate we set it for. Before this, that rate was just being used as the wait time between iterations so the actual time between iterations was the given interval plus the time to gather metadata. Now the time between reports should actually be roughly the given interval. Signed-off-by: Adam King --- src/cephadm/cephadm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 17b7fcfc333a5..d1bf297243743 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -3526,6 +3526,8 @@ class CephadmAgent(): self.event = Event() self.mgr_listener = MgrListener(self) self.device_enhanced_scan = False + self.recent_iteration_run_times: List[float] = [0.0, 0.0, 0.0] + self.recent_iteration_index: int = 0 def deploy_daemon_unit(self, config: Dict[str, str] = {}) -> None: if not config: @@ -3635,6 +3637,7 @@ WantedBy=ceph-{fsid}.target ssl_ctx.load_verify_locations(self.ca_path) while not self.stop: + start_time = time.monotonic() ack = self.ack try: volume = self._ceph_volume(self.device_enhanced_scan) @@ -3667,7 +3670,13 @@ WantedBy=ceph-{fsid}.target except Exception as e: logger.error(f'Failed to send metadata to mgr: {e}') - self.event.wait(self.loop_interval) + end_time = time.monotonic() + run_time = datetime.timedelta(seconds=(end_time - start_time)) + self.recent_iteration_run_times[self.recent_iteration_index] = run_time.total_seconds() + self.recent_iteration_index = (self.recent_iteration_index + 1) % 3 + run_time_average = sum(self.recent_iteration_run_times, 0.0) / len([t for t in self.recent_iteration_run_times if t]) + + self.event.wait(max(self.loop_interval - int(run_time_average), 0)) self.event.clear() def _ceph_volume(self, enhanced: bool = False) -> str: -- 2.39.5