From: Rishabh Dave Date: Wed, 18 Sep 2024 05:20:01 +0000 (+0530) Subject: mgr/vol: add helpers to spawn all threads and more threads X-Git-Tag: testing/wip-vshankar-testing-20241029.045257-debug~17^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=a9824956d4360862aa9f5e33864984218e0f057d;p=ceph-ci.git 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 --- diff --git a/src/pybind/mgr/volumes/fs/async_job.py b/src/pybind/mgr/volumes/fs/async_job.py index 0f63889cd53..9ed6d8dedad 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):