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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Thu May 12 15:24:52 UTC 2016


 loolwsd/Common.hpp  |    2 +-
 loolwsd/LOOLWSD.cpp |   24 +++++++++++++-----------
 2 files changed, 14 insertions(+), 12 deletions(-)

New commits:
commit de5f77c00fca275361a403f222e8025eaa3b346c
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu May 12 10:43:13 2016 -0400

    loolwsd: better child management
    
    Change-Id: I0de190619008834f096517bd1cfafcdc83261f47
    Reviewed-on: https://gerrit.libreoffice.org/24933
    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 caa3ce0..f0be984 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -17,7 +17,7 @@ constexpr int MAX_SESSIONS = 1024;
 constexpr int DEFAULT_CLIENT_PORT_NUMBER = 9980;
 constexpr int DEFAULT_MASTER_PORT_NUMBER = 9981;
 constexpr int WSD_SLEEP_SECS = 2;
-constexpr int CHILD_TIMEOUT_SECS = 10;
+constexpr int CHILD_TIMEOUT_SECS = 4;
 constexpr int POLL_TIMEOUT_MS = 1000;
 constexpr int COMMAND_TIMEOUT_MS = 5000;
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f2b47ad..bf8b674 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -149,7 +149,7 @@ static bool NoCapsForKit = false;
 static std::vector<std::shared_ptr<ChildProcess>> newChildren;
 static std::mutex newChildrenMutex;
 static std::condition_variable newChildrenCV;
-static std::chrono::steady_clock::time_point lastForkRequestTime;
+static std::chrono::steady_clock::time_point lastForkRequestTime = std::chrono::steady_clock::now();
 static std::map<std::string, std::shared_ptr<DocumentBroker>> docBrokers;
 static std::mutex docBrokersMutex;
 // Sessions to pre-spawned child processes that have connected but are not yet assigned a
@@ -194,13 +194,7 @@ static void prespawnChildren()
         return;
     }
 
-    const auto duration = (std::chrono::steady_clock::now() - lastForkRequestTime);
-    if (std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() <= CHILD_TIMEOUT_SECS * 1000)
-    {
-        // Not enough time passed to balance children.
-        return;
-    }
-
+    // Do the cleanup first.
     for (int i = newChildren.size() - 1; i >= 0; --i)
     {
         if (!newChildren[i]->isAlive())
@@ -209,6 +203,13 @@ static void prespawnChildren()
         }
     }
 
+    const auto duration = (std::chrono::steady_clock::now() - lastForkRequestTime);
+    if (std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() <= CHILD_TIMEOUT_SECS * 1000)
+    {
+        // Not enough time passed to balance children.
+        return;
+    }
+
     const int available = newChildren.size();
     int balance = LOOLWSD::NumPreSpawnedChildren;
     balance -= available;
@@ -263,11 +264,11 @@ static std::shared_ptr<ChildProcess> getNewChild()
                 Log::debug("getNewChild: Returning new child [" + std::to_string(child->getPid()) + "].");
                 return child;
             }
-
-            Log::debug("getNewChild: No live child, forking more.");
         }
+
+        Log::debug("getNewChild: No live child, forking more.");
     }
-    while (chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - startTime).count() < CHILD_TIMEOUT_SECS * 2000);
+    while (chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - startTime).count() < CHILD_TIMEOUT_SECS * 4000);
 
     Log::debug("getNewChild: Timed out while waiting for new child.");
     return nullptr;
@@ -1452,6 +1453,7 @@ Process::PID LOOLWSD::createForKit()
     Log::info("Launching forkit process: " + forKitPath + " " +
               Poco::cat(std::string(" "), args.begin(), args.end()));
 
+    lastForkRequestTime = std::chrono::steady_clock::now();
     ProcessHandle child = Process::launch(forKitPath, args);
 
     return child.id();


More information about the Libreoffice-commits mailing list