Skip to content

Commit a982495

Browse files
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 <[email protected]>
1 parent 7239588 commit a982495

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/pybind/mgr/volumes/fs/async_job.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ def __init__(self, volume_client, name_pfx, nr_concurrent_jobs):
136136
self.wakeup_timeout = None
137137

138138
self.threads = []
139-
for i in range(self.nr_concurrent_jobs):
140-
self.spawn_new_thread(i)
139+
self.spawn_all_threads()
141140
self.start()
142141

143142
def spawn_new_thread(self, suffix):
@@ -148,6 +147,20 @@ def spawn_new_thread(self, suffix):
148147

149148
self.threads.append(t)
150149

150+
def spawn_all_threads(self):
151+
log.debug(f'spawning {self.nr_concurrent_jobs} to execute more jobs '
152+
'concurrently')
153+
for i in range(self.nr_concurrent_jobs):
154+
self.spawn_new_thread(i)
155+
156+
def spawn_more_threads(self):
157+
c = len(self.threads)
158+
diff = self.nr_concurrent_jobs - c
159+
log.debug(f'spawning {diff} threads to execute more jobs concurrently')
160+
161+
for i in range(c, self.nr_concurrent_jobs):
162+
self.spawn_new_thread(i)
163+
151164
def set_wakeup_timeout(self):
152165
with self.lock:
153166
# not made configurable on purpose
@@ -170,9 +183,7 @@ def run(self):
170183
self.cv.notifyAll()
171184
elif c < self.nr_concurrent_jobs:
172185
# Increase concurrency: create more threads.
173-
log.debug("creating new threads to job increase")
174-
for i in range(c, self.nr_concurrent_jobs):
175-
self.spawn_new_thread(i)
186+
self.spawn_more_threads()
176187
self.cv.wait(timeout=self.wakeup_timeout)
177188

178189
def shutdown(self):

0 commit comments

Comments
 (0)