]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: agent: subtract average time of previous iterations off wait time 43452/head
authorAdam King <adking@redhat.com>
Thu, 7 Oct 2021 14:09:12 +0000 (10:09 -0400)
committerAdam King <adking@redhat.com>
Thu, 7 Oct 2021 14:09:12 +0000 (10:09 -0400)
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 <adking@redhat.com>
src/cephadm/cephadm

index 17b7fcfc333a59fba1c17945e324e5671e479bdf..d1bf2972437438ae23f30be711f85101db4ce632 100755 (executable)
@@ -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: