You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/04/05 01:11:54 UTC

[1/2] mesos git commit: Added `LIBPROCESS_NUM_WORKER_THREADS` environment variable.

Repository: mesos
Updated Branches:
  refs/heads/master c06d95cfe -> 40b84e085


Added `LIBPROCESS_NUM_WORKER_THREADS` environment variable.

This variable controls the number of libprocess worker threads.

Review: https://reviews.apache.org/r/43144/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d1d24917
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d1d24917
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d1d24917

Branch: refs/heads/master
Commit: d1d249171f2cf3377e0d864f72861ec8352b896d
Parents: c06d95c
Author: Maged Michael <ma...@gmail.com>
Authored: Mon Apr 4 19:04:55 2016 -0400
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Apr 4 19:10:31 2016 -0400

----------------------------------------------------------------------
 3rdparty/libprocess/src/process.cpp | 43 ++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d1d24917/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index feaffa4..d2c458e 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -843,7 +843,7 @@ void initialize(const Option<string>& delegate)
   EventLoop::initialize();
 
   // Setup processing threads.
-  long cpus = process_manager->init_threads();
+  long num_worker_threads = process_manager->init_threads();
 
   Clock::initialize(lambda::bind(&timedout, lambda::_1));
 
@@ -983,8 +983,8 @@ void initialize(const Option<string>& delegate)
 
   new Route("/__processes__", None(), __processes__);
 
-  VLOG(1) << "libprocess is initialized on " << address() << " for " << cpus
-          << " cpus";
+  VLOG(1) << "libprocess is initialized on " << address() << " with "
+          << num_worker_threads << " worker threads";
 }
 
 
@@ -2190,11 +2190,40 @@ long ProcessManager::init_threads()
   // Allocating a static number of threads can cause starvation if
   // there are more waiting Processes than the number of worker
   // threads.
-  long cpus = std::max(8L, sysconf(_SC_NPROCESSORS_ONLN));
-  threads.reserve(cpus+1);
+  long num_worker_threads = std::max(8L, sysconf(_SC_NPROCESSORS_ONLN));
+
+  // We allow the operator to set the number of libprocess worker
+  // threads, using an environment variable. The motivation is that
+  // for machines with a large number of cores, setting the number of
+  // worker threads to sysconf(_SC_NPROCESSORS_ONLN) can be very high
+  // and affect performance negatively. Furthermore, libprocess is
+  // widely used in Mesos and there may be a large number of Mesos
+  // processes (e.g., executors) on the same machine.
+  //
+  // See https://issues.apache.org/jira/browse/MESOS-4353.
+  constexpr char env_var[] = "LIBPROCESS_NUM_WORKER_THREADS";
+  Option<string> value = os::getenv(env_var);
+  if (value.isSome()) {
+    constexpr long maxval = 1024;
+    Try<long> number = numify<long>(value.get().c_str());
+    if (number.isSome() && number.get() > 0L && number.get() <= maxval) {
+      VLOG(1) << "Overriding default number of worker threads "
+              << num_worker_threads << ", using the value "
+              <<  env_var << "=" << number.get() << " instead";
+      num_worker_threads = number.get();
+    } else {
+      LOG(WARNING) << "Ignoring invalid value " << value.get()
+                   << " for " << env_var
+                   << ", using default value " << num_worker_threads
+                   << ". Valid values are integers in the range 1 to "
+                   << maxval;
+    }
+  }
+
+  threads.reserve(num_worker_threads + 1);
 
   // Create processing threads.
-  for (long i = 0; i < cpus; i++) {
+  for (long i = 0; i < num_worker_threads; i++) {
     // Retain the thread handles so that we can join when shutting down.
     threads.emplace_back(
         // We pass a constant reference to `joining` to make it clear that this
@@ -2224,7 +2253,7 @@ long ProcessManager::init_threads()
   // Create a thread for the event loop.
   threads.emplace_back(new std::thread(&EventLoop::run));
 
-  return cpus;
+  return num_worker_threads;
 }
 
 


[2/2] mesos git commit: Added documentation of `LIBPROCESS_NUM_WORKER_THREADS`.

Posted by jo...@apache.org.
Added documentation of `LIBPROCESS_NUM_WORKER_THREADS`.

Review: https://reviews.apache.org/r/45496/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/40b84e08
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/40b84e08
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/40b84e08

Branch: refs/heads/master
Commit: 40b84e0859ddd541c274d1cb5c0a676178408e91
Parents: d1d2491
Author: Maged Michael <ma...@gmail.com>
Authored: Mon Apr 4 19:05:47 2016 -0400
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Apr 4 19:11:23 2016 -0400

----------------------------------------------------------------------
 docs/configuration.md | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/40b84e08/docs/configuration.md
----------------------------------------------------------------------
diff --git a/docs/configuration.md b/docs/configuration.md
index da42eaf..621d272 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -1770,6 +1770,16 @@ isolator. (default: false)
       Examples: `10/1secs`, `100/10secs`, etc.
     </td>
   </tr>
+  <tr>
+    <td>
+      LIBPROCESS_NUM_WORKER_THREADS
+    </td>
+    <td>
+      If set to an integer value in the range 1 to 1024, it overrides
+      the default setting of the number of libprocess worker threads,
+      which is the maximum of 8 and the number of cores on the machine.
+    </td>
+  </tr>
 </table>