MB-20834: Use get_available_cpu_count() for executorpool #threads calculation 93/67493/3
authorDave Rigby <daver@couchbase.com>
Thu, 8 Sep 2016 13:32:45 +0000 (14:32 +0100)
committerDave Rigby <daver@couchbase.com>
Wed, 28 Sep 2016 12:21:00 +0000 (12:21 +0000)
Use the new Couchbase::get_available_cpu_count() when calculating how
many executor pool threads to create. get_available_cpu_count()
accounts for the number of logical cores a process is allowed to run
on, which is the mechanism cgroups (and hence Docker) uses to limit
the CPUs available to a container.

This fixes the problem of us creating "too many" executorpool threads
under Docker containers which have the --cpuset-cpus option set.

Change-Id: I3e3b91eecc51aea298ae9aceb9e8c6d3f16b7612
Reviewed-on: http://review.couchbase.org/67493
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Reviewed-by: Manu Dhundi <manu@couchbase.com>
Well-Formed: buildbot <build@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
src/executorpool.cc
src/executorpool.h

index d1dddc1..960bf80 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <algorithm>
 #include <platform/checked_snprintf.h>
+#include <platform/sysinfo.h>
 #include <queue>
 #include <sstream>
 
@@ -42,19 +43,6 @@ static const size_t EP_MAX_WRITER_THREADS = 8;
 static const size_t EP_MAX_AUXIO_THREADS  = 8;
 static const size_t EP_MAX_NONIO_THREADS  = 8;
 
-size_t ExecutorPool::getNumCPU(void) {
-    size_t numCPU;
-#ifdef WIN32
-    SYSTEM_INFO sysinfo;
-    GetSystemInfo(&sysinfo);
-    numCPU = (size_t)sysinfo.dwNumberOfProcessors;
-#else
-    numCPU = (size_t)sysconf(_SC_NPROCESSORS_ONLN);
-#endif
-
-    return (numCPU < 256) ? numCPU : 0;
-}
-
 size_t ExecutorPool::getNumNonIO(void) {
     // 1. compute: 30% of total threads
     size_t count = maxGlobalThreads * 0.3;
@@ -167,7 +155,7 @@ ExecutorPool::ExecutorPool(size_t maxThreads, size_t nTaskSets,
                   numTaskSets(nTaskSets), totReadyTasks(0),
                   isHiPrioQset(false), isLowPrioQset(false), numBuckets(0),
                   numSleepers(0) {
-    size_t numCPU = getNumCPU();
+    size_t numCPU = Couchbase::get_available_cpu_count();
     size_t numThreads = (size_t)((numCPU * 3)/4);
     numThreads = (numThreads < EP_MIN_NUM_THREADS) ?
                         EP_MIN_NUM_THREADS : numThreads;
index e5f75f2..557ba0f 100644 (file)
@@ -133,8 +133,6 @@ public:
 
     size_t getNumWorkersStat(void) { return threadQ.size(); }
 
-    size_t getNumCPU(void);
-
     size_t getNumReaders(void);
 
     size_t getNumWriters(void);