mirror of
https://github.com/nicolargo/glances.git
synced 2024-12-23 09:11:49 +03:00
Merge pull request #2396 from nicolargo/issue2390
Reduce CPU usage of containers plugin (podman)
This commit is contained in:
commit
67503f30a9
@ -91,7 +91,7 @@ class PodmanPodStatsFetcher:
|
||||
# Threaded Streamer
|
||||
# Temporary patch to get podman extension working
|
||||
stats_iterable = (pod_manager.stats(decode=True) for _ in iter(int, 1))
|
||||
self._streamer = StatsStreamer(stats_iterable, initial_stream_value={})
|
||||
self._streamer = StatsStreamer(stats_iterable, initial_stream_value={}, sleep_duration=2)
|
||||
|
||||
def _log_debug(self, msg, exception=None):
|
||||
logger.debug("containers (Podman): Pod Manager - {} ({})".format(msg, exception))
|
||||
|
@ -19,7 +19,7 @@ class StatsStreamer:
|
||||
Use `StatsStreamer.stats` to access the latest streamed results
|
||||
"""
|
||||
|
||||
def __init__(self, iterable, initial_stream_value=None):
|
||||
def __init__(self, iterable, initial_stream_value=None, sleep_duration=0.1):
|
||||
"""
|
||||
iterable: an Iterable instance that needs to be streamed
|
||||
"""
|
||||
@ -34,6 +34,8 @@ class StatsStreamer:
|
||||
self.result_lock = threading.Lock()
|
||||
# Last result streamed time (initial val 0)
|
||||
self._last_update_time = 0
|
||||
# Time to sleep before next iteration
|
||||
self._sleep_duration = sleep_duration
|
||||
|
||||
self._thread.start()
|
||||
|
||||
@ -56,7 +58,7 @@ class StatsStreamer:
|
||||
self._raw_result = res
|
||||
self._post_update_hook()
|
||||
|
||||
time.sleep(0.1)
|
||||
time.sleep(self._sleep_duration)
|
||||
if self.stopped():
|
||||
break
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user