From a9824956d4360862aa9f5e33864984218e0f057d Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Wed, 18 Sep 2024 10:50:01 +0530 Subject: [PATCH] mgr/vol: add helpers to spawn all threads and more threads Also add log messages for in these helper methods to allow tracking when and why more threads were spawned. Signed-off-by: Rishabh Dave --- src/pybind/mgr/volumes/fs/async_job.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/pybind/mgr/volumes/fs/async_job.py b/src/pybind/mgr/volumes/fs/async_job.py index 0f63889cd5328..9ed6d8dedad40 100644 --- a/src/pybind/mgr/volumes/fs/async_job.py +++ b/src/pybind/mgr/volumes/fs/async_job.py @@ -136,8 +136,7 @@ class AsyncJobs(threading.Thread): self.wakeup_timeout = None self.threads = [] - for i in range(self.nr_concurrent_jobs): - self.spawn_new_thread(i) + self.spawn_all_threads() self.start() def spawn_new_thread(self, suffix): @@ -148,6 +147,20 @@ class AsyncJobs(threading.Thread): self.threads.append(t) + def spawn_all_threads(self): + log.debug(f'spawning {self.nr_concurrent_jobs} to execute more jobs ' + 'concurrently') + for i in range(self.nr_concurrent_jobs): + self.spawn_new_thread(i) + + def spawn_more_threads(self): + c = len(self.threads) + diff = self.nr_concurrent_jobs - c + log.debug(f'spawning {diff} threads to execute more jobs concurrently') + + for i in range(c, self.nr_concurrent_jobs): + self.spawn_new_thread(i) + def set_wakeup_timeout(self): with self.lock: # not made configurable on purpose @@ -170,9 +183,7 @@ class AsyncJobs(threading.Thread): self.cv.notifyAll() elif c < self.nr_concurrent_jobs: # Increase concurrency: create more threads. - log.debug("creating new threads to job increase") - for i in range(c, self.nr_concurrent_jobs): - self.spawn_new_thread(i) + self.spawn_more_threads() self.cv.wait(timeout=self.wakeup_timeout) def shutdown(self): -- 2.39.5