From: MORITA Kazutaka <morita.kazut...@lab.ntt.co.jp>

Currently, even if the number of nodes is increased, the dynamic work
queue doesn't create worker threads until new work is added to the
queue.  This tries to create threads just after the work queue detect
that the cluster is expanded.

Signed-off-by: MORITA Kazutaka <morita.kazut...@lab.ntt.co.jp>
---
 lib/work.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/lib/work.c b/lib/work.c
index a68eabd..f457cd7 100644
--- a/lib/work.c
+++ b/lib/work.c
@@ -174,15 +174,29 @@ static void worker_thread_request_done(int fd, int 
events, void *data)
        struct work *work;
        eventfd_t value;
        LIST_HEAD(list);
+       bool cluster_is_expanded = false;
 
-       if (wq_get_nr_nodes)
-               nr_nodes = wq_get_nr_nodes();
+       if (wq_get_nr_nodes) {
+               size_t cur_nr_nodes = wq_get_nr_nodes();
+               if (nr_nodes < cur_nr_nodes)
+                       cluster_is_expanded = true;
+               nr_nodes = cur_nr_nodes;
+       }
 
        ret = eventfd_read(fd, &value);
        if (ret < 0)
                return;
 
        list_for_each_entry(wi, &worker_info_list, worker_info_siblings) {
+               if (cluster_is_expanded) {
+                       pthread_mutex_lock(&wi->pending_lock);
+
+                       if (wq_need_grow(wi))
+                               /* double the thread pool size */
+                               create_worker_threads(wi, wi->nr_threads * 2);
+
+                       pthread_mutex_unlock(&wi->pending_lock);
+               }
                pthread_mutex_lock(&wi->finished_lock);
                list_splice_init(&wi->finished_list, &list);
                pthread_mutex_unlock(&wi->finished_lock);
-- 
1.7.9.5

-- 
sheepdog mailing list
sheepdog@lists.wpkg.org
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to