[sheepdog] [PATCH 3/3] work: shrink the number of worker threads dynamically
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Mon Oct 22 06:31:05 CEST 2012
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
sheep/work.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/sheep/work.c b/sheep/work.c
index b197bb2..f1ca162 100644
--- a/sheep/work.c
+++ b/sheep/work.c
@@ -146,6 +146,15 @@ static void *worker_routine(void *arg)
while (!(wi->q.wq_state & WQ_DEAD)) {
pthread_mutex_lock(&wi->pending_lock);
+ if (!wi->ordered && idx == wi->nr_threads - 1 &&
+ NR_MIN_WORKER_THREADS < wi->nr_threads &&
+ wi->nr_pending + wi->nr_running <= idx / 2) {
+ wi->nr_threads--;
+ pthread_mutex_unlock(&wi->pending_lock);
+ pthread_detach(pthread_self());
+ dprintf("destroy thread %s %d\n", wi->name, idx);
+ break;
+ }
retest:
if (list_empty(&wi->q.pending_list)) {
wi->nr_running--;
--
1.7.2.5
More information about the sheepdog
mailing list