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

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


 loolwsd/LOOLWSD.cpp |   38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)

New commits:
commit 785fd972f4ffb97b0d99b5cbe3d65e9e3f5ee7e2
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Oct 22 11:42:57 2016 -0400

    loolwsd: cleanup dead children before balancing
    
    Change-Id: I782080bb83973a795e2c967d91b152095678a93e
    Reviewed-on: https://gerrit.libreoffice.org/30203
    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 c4f5368..a526829 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -228,6 +228,25 @@ static void forkChildren(const int number)
     }
 }
 
+/// Cleans up dead children.
+/// Returns true if removed at least one.
+static bool cleanupChildren()
+{
+    bool removed = false;
+    for (int i = NewChildren.size() - 1; i >= 0; --i)
+    {
+        if (!NewChildren[i]->isAlive())
+        {
+            Log::warn() << "Removing unused dead child [" << NewChildren[i]->getPid()
+                         << "]." << Log::end;
+            NewChildren.erase(NewChildren.begin() + i);
+            removed = true;
+        }
+    }
+
+    return removed;
+}
+
 /// Called on startup only.
 static void preForkChildren()
 {
@@ -240,6 +259,8 @@ static void preForkChildren()
     forkChildren(numPreSpawn);
 }
 
+/// Proatively spawn children processes
+/// to load documents with alacrity.
 static void prespawnChildren()
 {
     std::unique_lock<std::mutex> lock(NewChildrenMutex, std::defer_lock);
@@ -250,19 +271,7 @@ static void prespawnChildren()
     }
 
     // Do the cleanup first.
-    bool rebalance = false;
-    for (int i = NewChildren.size() - 1; i >= 0; --i)
-    {
-        if (!NewChildren[i]->isAlive())
-        {
-            Log::warn() << "Removing unused dead child [" << NewChildren[i]->getPid()
-                         << "]." << Log::end;
-            NewChildren.erase(NewChildren.begin() + i);
-
-            // Rebalance after cleanup.
-            rebalance = true;
-        }
-    }
+    const bool rebalance = cleanupChildren();
 
     int balance = LOOLWSD::NumPreSpawnedChildren;
     balance -= NewChildren.size();
@@ -303,6 +312,9 @@ static std::shared_ptr<ChildProcess> getNewChild()
     const auto startTime = chrono::steady_clock::now();
     do
     {
+        // Do the cleanup first.
+        cleanupChildren();
+
         const int available = NewChildren.size();
         int balance = LOOLWSD::NumPreSpawnedChildren;
         if (available == 0)


More information about the Libreoffice-commits mailing list