[Libreoffice-commits] online.git: loolwsd/Common.hpp loolwsd/LOOLWSD.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun Jan 31 21:06:53 PST 2016


 loolwsd/Common.hpp  |    3 +++
 loolwsd/LOOLWSD.cpp |   34 ++++++++++++++++------------------
 2 files changed, 19 insertions(+), 18 deletions(-)

New commits:
commit 6f5afd92baa481fb27aaebe769d283fb5382fd84
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Jan 31 22:34:18 2016 -0500

    loolwsd: fixed server thread-pool
    
    TCPServer doesn't use the custom ThreadPool passed to it
    to dispatch connections. This leads to starvation
    when too many connections are initiated together.
    
    Because we open an internal socket back to master, we
    need to be able to dispatch two connections (two threads)
    for each client connection.
    
    Therefore, the default ThreadPool needs to have sufficient
    capacity to grow. A new constant is added to define this
    capacity and it is used to configure both the TCPServer
    (which configures the default ThreadPool) and the customer
    ThreadPool (used to host the actuall connection handler).
    
    Change-Id: I49adc039aa99e9350b0defc4a5e141b77524992e
    Reviewed-on: https://gerrit.libreoffice.org/21976
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index f85f76d..57903f2 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -13,6 +13,9 @@
 
 #include <string>
 
+// The maximum number of client connections we can accept.
+constexpr int MAX_SESSIONS = 1024;
+
 constexpr int DEFAULT_CLIENT_PORT_NUMBER = 9980;
 constexpr int MASTER_PORT_NUMBER = 9981;
 constexpr int INTERVAL_PROBES = 10;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 83d4341..da474c9 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -959,18 +959,28 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
     dropCapability();
 #endif
 
+    // Configure the Server.
+    // Note: TCPServer internally uses the default
+    // ThreadPool to dispatch connections.
+    // The capacity of the default ThreadPool
+    // is increased to match MaxThreads.
+    // We must have sufficient available threads
+    // in the default ThreadPool to dispatch
+    // connections, otherwise we will deadlock.
+    auto params = new HTTPServerParams();
+    params->setMaxThreads(MAX_SESSIONS);
+
     // Start a server listening on the port for clients
-    ServerSocket svs(ClientPortNumber, NumPreSpawnedChildren*10);
-    ThreadPool threadPool(NumPreSpawnedChildren*2, NumPreSpawnedChildren*5);
-    HTTPServer srv(new RequestHandlerFactory<ClientRequestHandler>(), threadPool, svs, new HTTPServerParams);
+    ServerSocket svs(ClientPortNumber);
+    ThreadPool threadPool(NumPreSpawnedChildren*6, MAX_SESSIONS * 2);
+    HTTPServer srv(new RequestHandlerFactory<ClientRequestHandler>(), threadPool, svs, params);
 
     srv.start();
 
     // And one on the port for child processes
     SocketAddress addr2("127.0.0.1", MASTER_PORT_NUMBER);
-    ServerSocket svs2(addr2, NumPreSpawnedChildren);
-    ThreadPool threadPool2(NumPreSpawnedChildren*2, NumPreSpawnedChildren*5);
-    HTTPServer srv2(new RequestHandlerFactory<PrisonerRequestHandler>(), threadPool2, svs2, new HTTPServerParams);
+    ServerSocket svs2(addr2);
+    HTTPServer srv2(new RequestHandlerFactory<PrisonerRequestHandler>(), threadPool, svs2, params);
 
     srv2.start();
 
@@ -990,19 +1000,8 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
 
     int status = 0;
     unsigned timeoutCounter = 0;
-    std::chrono::steady_clock::time_point lastPoolTime = std::chrono::steady_clock::now();
-
     while (!TerminationFlag && !LOOLWSD::DoTest)
     {
-        const auto duration = (std::chrono::steady_clock::now() - lastPoolTime);
-        if (duration >= std::chrono::seconds(10))
-        {
-            if (threadPool.available() ==  0)
-                Log::warn("The thread pool is full, no more connections are accepted.");
-
-            lastPoolTime = std::chrono::steady_clock::now();
-        }
-
         const pid_t pid = waitpid(-1, &status, WUNTRACED | WNOHANG);
         if (pid > 0)
         {
@@ -1070,7 +1069,6 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
 
     // close all websockets
     threadPool.joinAll();
-    threadPool2.joinAll();
 
     // Terminate child processes
     Util::writeFIFO(LOOLWSD::BrokerWritePipe, "eof\r\n");


More information about the Libreoffice-commits mailing list