From: Adam King Date: Thu, 7 Oct 2021 14:09:12 +0000 (-0400) Subject: cephadm: agent: subtract average time of previous iterations off wait time X-Git-Tag: v17.1.0~726^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=b50401261400a7667a214172d6e0daabd67e5f1e;p=ceph-ci.git 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 --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 17b7fcfc333..d1bf2972437 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: