Don't hardcode thread limit in ServerBootstrap
authorSara Golemon <sgolemon@fb.com>
Wed, 24 Jun 2015 17:48:20 +0000 (10:48 -0700)
committerSara Golemon <sgolemon@fb.com>
Wed, 24 Jun 2015 18:06:13 +0000 (11:06 -0700)
Summary: This was set to 32 which probably works fine for the
majority of FB servers, but not everyone's system is so endowed.

Closes #119

Reviewed By: @fredemmott

Differential Revision: D2187008

folly/wangle/bootstrap/ServerBootstrap.h

index 3b7f6b0ada1198847b94ae12cca4884780eb16a3..2c2a6b47dcafd5b0f2ad13f3a046c8789b173587 100644 (file)
@@ -120,8 +120,13 @@ class ServerBootstrap {
         1, std::make_shared<wangle::NamedThreadFactory>("Acceptor Thread"));
     }
     if (!io_group) {
         1, std::make_shared<wangle::NamedThreadFactory>("Acceptor Thread"));
     }
     if (!io_group) {
+      auto threads = std::thread::hardware_concurrency();
+      if (threads <= 0) {
+        // Reasonable mid-point for concurrency when actual value unknown
+        threads = 8;
+      }
       io_group = std::make_shared<folly::wangle::IOThreadPoolExecutor>(
       io_group = std::make_shared<folly::wangle::IOThreadPoolExecutor>(
-        32, std::make_shared<wangle::NamedThreadFactory>("IO Thread"));
+        threads, std::make_shared<wangle::NamedThreadFactory>("IO Thread"));
     }
 
     // TODO better config checking
     }
 
     // TODO better config checking