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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun Oct 23 21:19:23 UTC 2016


 loolwsd/LOOLWSD.cpp |   27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

New commits:
commit f4b4037f9ed73501159efb359702df2bbb161d25
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Oct 23 16:00:32 2016 -0400

    loolwsd: spawn new children when no forks are outstanding
    
    This avoids always waiting until child spawning times
    out by being smarter about whether or not there are
    any children spawning to wait for.
    
    Change-Id: I96a16ac35f90f70219d4153db9862cf2ee5b6a76
    Reviewed-on: https://gerrit.libreoffice.org/30213
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index a287320..e1c07cb 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -167,6 +167,7 @@ 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 = std::chrono::steady_clock::now();
+static std::atomic<int> OutstandingForks(1); // Forkit always spawns 1.
 static std::map<std::string, std::shared_ptr<DocumentBroker>> DocBrokers;
 static std::mutex DocBrokersMutex;
 
@@ -257,6 +258,8 @@ static void forkChildren(const int number)
         Util::checkDiskSpaceOnRegisteredFileSystems();
         const std::string aMessage = "spawn " + std::to_string(number) + "\n";
         Log::debug("MasterToForKit: " + aMessage.substr(0, aMessage.length() - 1));
+
+        ++OutstandingForks;
         IoUtil::writeToPipe(LOOLWSD::ForKitWritePipe, aMessage);
         LastForkRequestTime = std::chrono::steady_clock::now();
     }
@@ -315,27 +318,29 @@ static void prespawnChildren()
     // Do the cleanup first.
     const bool rebalance = cleanupChildren();
 
-    int balance = LOOLWSD::NumPreSpawnedChildren;
-    balance -= NewChildren.size();
-    if (balance <= 0)
+    const auto duration = (std::chrono::steady_clock::now() - LastForkRequestTime);
+    const auto durationMs = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
+    if (durationMs >= CHILD_TIMEOUT_MS)
     {
-        return;
+        // Children taking too long to spawn.
+        // Forget we had requested any, and request anew.
+        OutstandingForks = 0;
     }
 
-    const auto duration = (std::chrono::steady_clock::now() - LastForkRequestTime);
-    if (!rebalance &&
-        std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() <= CHILD_TIMEOUT_MS)
+    int balance = LOOLWSD::NumPreSpawnedChildren;
+    balance -= NewChildren.size();
+    balance -= OutstandingForks;
+
+    if (rebalance || durationMs >= CHILD_TIMEOUT_MS)
     {
-        // Not enough time passed to balance children.
-        return;
+        forkChildren(balance);
     }
-
-    forkChildren(balance);
 }
 
 static size_t addNewChild(const std::shared_ptr<ChildProcess>& child)
 {
     std::unique_lock<std::mutex> lock(NewChildrenMutex);
+    --OutstandingForks;
     NewChildren.emplace_back(child);
     const auto count = NewChildren.size();
     Log::info() << "Have " << count << " "


More information about the Libreoffice-commits mailing list