From 3430395c852b95914891fda08e0550dce29044ed Mon Sep 17 00:00:00 2001 From: Tony Asleson Date: Wed, 27 Mar 2024 11:49:05 -0500 Subject: [PATCH] lvmdbusd: Exit faster Add a global timeout value to be used for the threads to end waiting for whatever it is they are blocked on. The values varied from 2-5 seconds, which is way longer than needed. Value of 0.5 shows no CPU load when service is running and is idle. --- daemons/lvmdbusd/cfg.py | 2 ++ daemons/lvmdbusd/cmdhandler.py | 2 +- daemons/lvmdbusd/fetch.py | 4 ++-- daemons/lvmdbusd/lvm_shell_proxy.py.in | 2 +- daemons/lvmdbusd/main.py | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/daemons/lvmdbusd/cfg.py b/daemons/lvmdbusd/cfg.py index 9f4360100..7f9844bad 100644 --- a/daemons/lvmdbusd/cfg.py +++ b/daemons/lvmdbusd/cfg.py @@ -50,6 +50,8 @@ worker_q = queue.Queue() # Main event loop loop = None +G_LOOP_TMO = 0.5 + # Used to instruct the daemon if we should ignore SIGTERM ignore_sigterm = False diff --git a/daemons/lvmdbusd/cmdhandler.py b/daemons/lvmdbusd/cmdhandler.py index cf9803e76..d79db99ae 100644 --- a/daemons/lvmdbusd/cmdhandler.py +++ b/daemons/lvmdbusd/cmdhandler.py @@ -136,7 +136,7 @@ def call_lvm(command, debug=False, line_cb=None, while True and cfg.run.value != 0: try: rd_fd = [process.stdout.fileno(), process.stderr.fileno()] - ready = select.select(rd_fd, [], [], 2) + ready = select.select(rd_fd, [], [], cfg.G_LOOP_TMO) for r in ready[0]: if r == process.stdout.fileno(): diff --git a/daemons/lvmdbusd/fetch.py b/daemons/lvmdbusd/fetch.py index 9807da934..6180566fe 100644 --- a/daemons/lvmdbusd/fetch.py +++ b/daemons/lvmdbusd/fetch.py @@ -183,9 +183,9 @@ class StateUpdate(object): obj.deferred = False if len(queued_requests) == 0 and wait: - # Note: If we don't have anything for 2 seconds we will + # Note: If we don't have anything for N seconds we will # get a queue.Empty exception raised here - queued_requests.append(obj.queue.get(block=True, timeout=2)) + queued_requests.append(obj.queue.get(block=True, timeout=cfg.G_LOOP_TMO)) # Ok we have one or the deferred queue has some, # check if any others and grab them too diff --git a/daemons/lvmdbusd/lvm_shell_proxy.py.in b/daemons/lvmdbusd/lvm_shell_proxy.py.in index 02a776e1d..41adc3196 100644 --- a/daemons/lvmdbusd/lvm_shell_proxy.py.in +++ b/daemons/lvmdbusd/lvm_shell_proxy.py.in @@ -66,7 +66,7 @@ class LVMShellProxy(object): self.parent_stdout_fd, self.report_stream.fileno(), self.parent_stderr_fd] - ready = select.select(rd_fd, [], [], 2) + ready = select.select(rd_fd, [], [], cfg.G_LOOP_TMO) for r in ready[0]: if r == self.parent_stdout_fd: diff --git a/daemons/lvmdbusd/main.py b/daemons/lvmdbusd/main.py index e07710a5e..ee061246c 100644 --- a/daemons/lvmdbusd/main.py +++ b/daemons/lvmdbusd/main.py @@ -41,7 +41,7 @@ def process_request(): while cfg.run.value != 0: # noinspection PyBroadException try: - req = cfg.worker_q.get(True, 5) + req = cfg.worker_q.get(True, cfg.G_LOOP_TMO) log_debug( "Method start: %s with args %s (callback = %s)" % (str(req.method), str(req.arguments), str(req.cb)))