]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/vol: add helpers to spawn all threads and more threads
authorRishabh Dave <ridave@redhat.com>
Wed, 18 Sep 2024 05:20:01 +0000 (10:50 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 24 Oct 2024 13:51:35 +0000 (19:21 +0530)
Also add log messages for in these helper methods to allow tracking when
and why more threads were spawned.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/pybind/mgr/volumes/fs/async_job.py

index 0f63889cd532850c6feee4e37b87127761cf77f5..9ed6d8dedad40d2b96441d682bfe0f332a64d809 100644 (file)
@@ -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):