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