e7a346
From 1183db5268c3957975cdc6ad882113bfff7a8f32 Mon Sep 17 00:00:00 2001
e7a346
From: Milind Changire <mchangir@redhat.com>
e7a346
Date: Mon, 21 May 2018 12:17:06 +0530
e7a346
Subject: [PATCH 280/282] Revert "rpcsvc: scale rpcsvc_request_handler threads"
e7a346
e7a346
This reverts commit 8503ed9b94777d47352f19ebfa844e151352b87f.
e7a346
e7a346
> Reviewed-on: https://code.engineering.redhat.com/gerrit/131596
e7a346
Change-Id: I537a40d29b027a7e06babb775b39bb111f0d0e3f
e7a346
BUG: 1558989
e7a346
Signed-off-by: Milind Changire <mchangir@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/139308
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 glusterfsd/src/Makefile.am           |   1 -
e7a346
 glusterfsd/src/glusterfsd-mgmt.c     |  16 +----
e7a346
 glusterfsd/src/glusterfsd.h          |   2 +-
e7a346
 libglusterfs/src/event-poll.c        |   7 --
e7a346
 rpc/rpc-lib/src/rpcsvc.c             | 129 ++++-------------------------------
e7a346
 rpc/rpc-lib/src/rpcsvc.h             |   8 ---
e7a346
 xlators/protocol/server/src/server.c |  11 +--
e7a346
 7 files changed, 20 insertions(+), 154 deletions(-)
e7a346
e7a346
diff --git a/glusterfsd/src/Makefile.am b/glusterfsd/src/Makefile.am
e7a346
index 8ab585c..0196204 100644
e7a346
--- a/glusterfsd/src/Makefile.am
e7a346
+++ b/glusterfsd/src/Makefile.am
e7a346
@@ -22,7 +22,6 @@ AM_CPPFLAGS = $(GF_CPPFLAGS) \
e7a346
 	-I$(top_srcdir)/rpc/xdr/src \
e7a346
 	-I$(top_builddir)/rpc/xdr/src \
e7a346
 	-I$(top_srcdir)/xlators/nfs/server/src \
e7a346
-	-I$(top_srcdir)/xlators/protocol/server/src \
e7a346
 	-I$(top_srcdir)/api/src
e7a346
 
e7a346
 AM_CFLAGS = -Wall $(GF_CFLAGS)
e7a346
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
e7a346
index 3b9671c..665b62c 100644
e7a346
--- a/glusterfsd/src/glusterfsd-mgmt.c
e7a346
+++ b/glusterfsd/src/glusterfsd-mgmt.c
e7a346
@@ -33,7 +33,6 @@
e7a346
 #include "syncop.h"
e7a346
 #include "xlator.h"
e7a346
 #include "syscall.h"
e7a346
-#include "server.h"
e7a346
 
e7a346
 static gf_boolean_t is_mgmt_rpc_reconnect = _gf_false;
e7a346
 int need_emancipate = 0;
e7a346
@@ -186,15 +185,12 @@ glusterfs_terminate_response_send (rpcsvc_request_t *req, int op_ret)
e7a346
 }
e7a346
 
e7a346
 void
e7a346
-glusterfs_autoscale_threads (glusterfs_ctx_t *ctx, int incr, xlator_t *this)
e7a346
+glusterfs_autoscale_threads (glusterfs_ctx_t *ctx, int incr)
e7a346
 {
e7a346
         struct event_pool       *pool           = ctx->event_pool;
e7a346
-        server_conf_t           *conf           = this->private;
e7a346
-        int                      thread_count   = pool->eventthreadcount;
e7a346
 
e7a346
         pool->auto_thread_count += incr;
e7a346
-        (void) event_reconfigure_threads (pool, thread_count+incr);
e7a346
-        rpcsvc_ownthread_reconf (conf->rpc, pool->eventthreadcount);
e7a346
+        (void) event_reconfigure_threads (pool, pool->eventthreadcount+incr);
e7a346
 }
e7a346
 
e7a346
 static int
e7a346
@@ -964,7 +960,6 @@ glusterfs_handle_attach (rpcsvc_request_t *req)
e7a346
         xlator_t                *nextchild      = NULL;
e7a346
         glusterfs_graph_t       *newgraph       = NULL;
e7a346
         glusterfs_ctx_t         *ctx            = NULL;
e7a346
-        xlator_t                *protocol_server = NULL;
e7a346
 
e7a346
         GF_ASSERT (req);
e7a346
         this = THIS;
e7a346
@@ -1002,12 +997,7 @@ glusterfs_handle_attach (rpcsvc_request_t *req)
e7a346
                                                 nextchild->name);
e7a346
                                         goto out;
e7a346
                                 }
e7a346
-                                /* we need a protocol/server xlator as
e7a346
-                                 * nextchild
e7a346
-                                 */
e7a346
-                                protocol_server = this->ctx->active->first;
e7a346
-                                glusterfs_autoscale_threads (this->ctx, 1,
e7a346
-                                                             protocol_server);
e7a346
+                                glusterfs_autoscale_threads (this->ctx, 1);
e7a346
                         }
e7a346
                 } else {
e7a346
                         gf_log (this->name, GF_LOG_WARNING,
e7a346
diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h
e7a346
index a72acc8..f66947b 100644
e7a346
--- a/glusterfsd/src/glusterfsd.h
e7a346
+++ b/glusterfsd/src/glusterfsd.h
e7a346
@@ -124,7 +124,7 @@ int glusterfs_volume_top_read_perf (uint32_t blk_size, uint32_t blk_count,
e7a346
                                     char *brick_path, double *throughput,
e7a346
                                     double *time);
e7a346
 void
e7a346
-glusterfs_autoscale_threads (glusterfs_ctx_t *ctx, int incr, xlator_t *this);
e7a346
+glusterfs_autoscale_threads (glusterfs_ctx_t *ctx, int incr);
e7a346
 
e7a346
 void
e7a346
 xlator_mem_cleanup (xlator_t *this);
e7a346
diff --git a/libglusterfs/src/event-poll.c b/libglusterfs/src/event-poll.c
e7a346
index b1aca82..3bffc47 100644
e7a346
--- a/libglusterfs/src/event-poll.c
e7a346
+++ b/libglusterfs/src/event-poll.c
e7a346
@@ -173,13 +173,6 @@ event_pool_new_poll (int count, int eventthreadcount)
e7a346
                         "thread count (%d) ignored", eventthreadcount);
e7a346
         }
e7a346
 
e7a346
-        /* although, eventhreadcount for poll implementaiton is always
e7a346
-         * going to be 1, eventthreadcount needs to be set to 1 so that
e7a346
-         * rpcsvc_request_handler() thread scaling works flawlessly in
e7a346
-         * both epoll and poll models
e7a346
-         */
e7a346
-        event_pool->eventthreadcount = 1;
e7a346
-
e7a346
         return event_pool;
e7a346
 }
e7a346
 
e7a346
diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c
e7a346
index 31b5eb5..68e27ab 100644
e7a346
--- a/rpc/rpc-lib/src/rpcsvc.c
e7a346
+++ b/rpc/rpc-lib/src/rpcsvc.c
e7a346
@@ -1877,105 +1877,39 @@ rpcsvc_request_handler (void *arg)
e7a346
                                 goto unlock;
e7a346
                         }
e7a346
 
e7a346
-                        while (list_empty (&program->request_queue) &&
e7a346
-                               (program->threadcount <=
e7a346
-                                        program->eventthreadcount)) {
e7a346
+                        while (list_empty (&program->request_queue))
e7a346
                                 pthread_cond_wait (&program->queue_cond,
e7a346
                                                    &program->queue_lock);
e7a346
-                        }
e7a346
 
e7a346
-                        if (program->threadcount > program->eventthreadcount) {
e7a346
-                                done = 1;
e7a346
-                                program->threadcount--;
e7a346
-
e7a346
-                                gf_log (GF_RPCSVC, GF_LOG_INFO,
e7a346
-                                        "program '%s' thread terminated; "
e7a346
-                                        "total count:%d",
e7a346
-                                        program->progname,
e7a346
-                                        program->threadcount);
e7a346
-                        } else if (!list_empty (&program->request_queue)) {
e7a346
-                                req = list_entry (program->request_queue.next,
e7a346
-                                                  typeof (*req), request_list);
e7a346
-
e7a346
-                                list_del_init (&req->request_list);
e7a346
-                        }
e7a346
+                        req = list_entry (program->request_queue.next,
e7a346
+                                          typeof (*req), request_list);
e7a346
+
e7a346
+                        list_del_init (&req->request_list);
e7a346
                 }
e7a346
         unlock:
e7a346
                 pthread_mutex_unlock (&program->queue_lock);
e7a346
 
e7a346
-                if (req) {
e7a346
-                        THIS = req->svc->xl;
e7a346
-                        actor = rpcsvc_program_actor (req);
e7a346
-                        ret = actor->actor (req);
e7a346
-
e7a346
-                        if (ret != 0) {
e7a346
-                                rpcsvc_check_and_reply_error (ret, NULL, req);
e7a346
-                        }
e7a346
-                        req = NULL;
e7a346
-                }
e7a346
-
e7a346
                 if (done)
e7a346
                         break;
e7a346
-        }
e7a346
 
e7a346
-        return NULL;
e7a346
-}
e7a346
+                THIS = req->svc->xl;
e7a346
 
e7a346
-int
e7a346
-rpcsvc_spawn_threads (rpcsvc_t *svc, rpcsvc_program_t *program)
e7a346
-{
e7a346
-        int                ret  = 0, delta = 0, creates = 0;
e7a346
+                actor = rpcsvc_program_actor (req);
e7a346
 
e7a346
-        if (!program || !svc)
e7a346
-                goto out;
e7a346
-
e7a346
-        pthread_mutex_lock (&program->queue_lock);
e7a346
-        {
e7a346
-                delta = program->eventthreadcount - program->threadcount;
e7a346
-
e7a346
-                if (delta >= 0) {
e7a346
-                        while (delta--) {
e7a346
-                                ret = gf_thread_create (&program->thread, NULL,
e7a346
-                                                        rpcsvc_request_handler,
e7a346
-                                                        program, "rpcrqhnd");
e7a346
-                                if (!ret) {
e7a346
-                                        program->threadcount++;
e7a346
-                                        creates++;
e7a346
-                                }
e7a346
-                        }
e7a346
+                ret = actor->actor (req);
e7a346
 
e7a346
-                        if (creates) {
e7a346
-                                gf_log (GF_RPCSVC, GF_LOG_INFO,
e7a346
-                                        "spawned %d threads for program '%s'; "
e7a346
-                                        "total count:%d",
e7a346
-                                        creates,
e7a346
-                                        program->progname,
e7a346
-                                        program->threadcount);
e7a346
-                        }
e7a346
-                } else {
e7a346
-                        gf_log (GF_RPCSVC, GF_LOG_INFO,
e7a346
-                                "terminating %d threads for program '%s'",
e7a346
-                                -delta, program->progname);
e7a346
-
e7a346
-                        /* this signal is to just wake up the threads so they
e7a346
-                         * test for the change in eventthreadcount and kill
e7a346
-                         * themselves until the program thread count becomes
e7a346
-                         * equal to the event thread count
e7a346
-                         */
e7a346
-                        pthread_cond_broadcast (&program->queue_cond);
e7a346
+                if (ret != 0) {
e7a346
+                        rpcsvc_check_and_reply_error (ret, NULL, req);
e7a346
                 }
e7a346
         }
e7a346
-        pthread_mutex_unlock (&program->queue_lock);
e7a346
 
e7a346
-out:
e7a346
-        return creates;
e7a346
+        return NULL;
e7a346
 }
e7a346
 
e7a346
 int
e7a346
 rpcsvc_program_register (rpcsvc_t *svc, rpcsvc_program_t *program)
e7a346
 {
e7a346
         int               ret                = -1;
e7a346
-        int               creates            = -1;
e7a346
         rpcsvc_program_t *newprog            = NULL;
e7a346
         char              already_registered = 0;
e7a346
 
e7a346
@@ -2023,12 +1957,9 @@ rpcsvc_program_register (rpcsvc_t *svc, rpcsvc_program_t *program)
e7a346
                 newprog->ownthread = _gf_false;
e7a346
 
e7a346
         if (newprog->ownthread) {
e7a346
-                newprog->eventthreadcount = 1;
e7a346
-                creates = rpcsvc_spawn_threads (svc, newprog);
e7a346
-
e7a346
-                if (creates < 1) {
e7a346
-                        goto out;
e7a346
-                }
e7a346
+                gf_thread_create (&newprog->thread, NULL,
e7a346
+                                  rpcsvc_request_handler,
e7a346
+                                  newprog, "rpcsvcrh");
e7a346
         }
e7a346
 
e7a346
         pthread_mutex_lock (&svc->rpclock);
e7a346
@@ -2885,38 +2816,6 @@ out:
e7a346
         return ret;
e7a346
 }
e7a346
 
e7a346
-/* During reconfigure, Make sure to call this function after event-threads are
e7a346
- * reconfigured as programs' threadcount will be made equal to event threads.
e7a346
- */
e7a346
-
e7a346
-int
e7a346
-rpcsvc_ownthread_reconf (rpcsvc_t *svc, int new_eventthreadcount)
e7a346
-{
e7a346
-        int ret = -1;
e7a346
-        rpcsvc_program_t *program = NULL;
e7a346
-
e7a346
-        if (!svc) {
e7a346
-                ret = 0;
e7a346
-                goto out;
e7a346
-        }
e7a346
-
e7a346
-        pthread_rwlock_wrlock (&svc->rpclock);
e7a346
-        {
e7a346
-                list_for_each_entry (program, &svc->programs, program) {
e7a346
-                        if (program->ownthread) {
e7a346
-                                program->eventthreadcount =
e7a346
-                                        new_eventthreadcount;
e7a346
-                                rpcsvc_spawn_threads (svc, program);
e7a346
-                        }
e7a346
-                }
e7a346
-        }
e7a346
-        pthread_rwlock_unlock (&svc->rpclock);
e7a346
-
e7a346
-        ret = 0;
e7a346
-out:
e7a346
-        return ret;
e7a346
-}
e7a346
-
e7a346
 
e7a346
 rpcsvc_actor_t gluster_dump_actors[GF_DUMP_MAXVALUE] = {
e7a346
         [GF_DUMP_NULL]      = {"NULL",     GF_DUMP_NULL,     NULL,        NULL, 0, DRC_NA},
e7a346
diff --git a/rpc/rpc-lib/src/rpcsvc.h b/rpc/rpc-lib/src/rpcsvc.h
e7a346
index 4ae2350..73507b6 100644
e7a346
--- a/rpc/rpc-lib/src/rpcsvc.h
e7a346
+++ b/rpc/rpc-lib/src/rpcsvc.h
e7a346
@@ -412,12 +412,6 @@ struct rpcsvc_program {
e7a346
         pthread_mutex_t         queue_lock;
e7a346
         pthread_cond_t          queue_cond;
e7a346
         pthread_t               thread;
e7a346
-        int                     threadcount;
e7a346
-        /* eventthreadcount is just a readonly copy of the actual value
e7a346
-         * owned by the event sub-system
e7a346
-         * It is used to control the scaling of rpcsvc_request_handler threads
e7a346
-         */
e7a346
-        int                     eventthreadcount;
e7a346
 };
e7a346
 
e7a346
 typedef struct rpcsvc_cbk_program {
e7a346
@@ -629,6 +623,4 @@ rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen);
e7a346
 rpcsvc_vector_sizer
e7a346
 rpcsvc_get_program_vector_sizer (rpcsvc_t *svc, uint32_t prognum,
e7a346
                                  uint32_t progver, int procnum);
e7a346
-extern int
e7a346
-rpcsvc_ownthread_reconf (rpcsvc_t *svc, int new_eventthreadcount);
e7a346
 #endif
e7a346
diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c
e7a346
index 79f68e8..bc87a80 100644
e7a346
--- a/xlators/protocol/server/src/server.c
e7a346
+++ b/xlators/protocol/server/src/server.c
e7a346
@@ -685,7 +685,7 @@ unref_transport:
e7a346
                                 UNLOCK (&ctx->volfile_lock);
e7a346
                                 if (victim_found) {
e7a346
                                         xlator_mem_cleanup (travxl);
e7a346
-                                        glusterfs_autoscale_threads (ctx, -1, this);
e7a346
+                                        glusterfs_autoscale_threads (ctx, -1);
e7a346
                                 }
e7a346
                         }
e7a346
                         GF_FREE (xlator_name);
e7a346
@@ -1054,12 +1054,6 @@ do_rpc:
e7a346
 
e7a346
         ret = server_init_grace_timer (this, options, conf);
e7a346
 
e7a346
-        /* rpcsvc thread reconfigure should be after events thread
e7a346
-         * reconfigure
e7a346
-         */
e7a346
-        new_nthread =
e7a346
-        ((struct event_pool *)(this->ctx->event_pool))->eventthreadcount;
e7a346
-        ret = rpcsvc_ownthread_reconf (rpc_conf, new_nthread);
e7a346
 out:
e7a346
         THIS = oldTHIS;
e7a346
         gf_msg_debug ("", 0, "returning %d", ret);
e7a346
@@ -1672,10 +1666,9 @@ notify (xlator_t *this, int32_t event, void *data, ...)
e7a346
 
e7a346
                         glusterfs_mgmt_pmap_signout (ctx,
e7a346
                                                      victim->name);
e7a346
-
e7a346
                         if (!xprt_found && victim_found) {
e7a346
                                 xlator_mem_cleanup (victim);
e7a346
-                                glusterfs_autoscale_threads (ctx, -1, this);
e7a346
+                                glusterfs_autoscale_threads (ctx, -1);
e7a346
                         }
e7a346
                 }
e7a346
                 break;
e7a346
-- 
e7a346
1.8.3.1
e7a346