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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun Oct 16 22:11:36 UTC 2016


 loolwsd/LOOLForKit.cpp  |    9 ++++-----
 loolwsd/LOOLSession.hpp |    1 +
 loolwsd/LOOLWSD.cpp     |   19 +++++++++++++++----
 3 files changed, 20 insertions(+), 9 deletions(-)

New commits:
commit de7cda7891fff43992df61a1b2702608ed579549
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Oct 15 17:08:55 2016 -0400

    loolwsd: improve child cleanup and forking
    
    Change-Id: I437216d87b6fa15e567e102ed875b22ef03351b2
    Reviewed-on: https://gerrit.libreoffice.org/29948
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp
index 7f95ef2..c23141b 100644
--- a/loolwsd/LOOLForKit.cpp
+++ b/loolwsd/LOOLForKit.cpp
@@ -180,7 +180,7 @@ static void cleanupChildren()
 {
     Process::PID exitedChildPid;
     int status;
-    while ((exitedChildPid = waitpid(-1, &status, WNOHANG)) > 0)
+    while ((exitedChildPid = waitpid(-1, &status, WUNTRACED | WNOHANG)) > 0)
     {
         if (childJails.find(exitedChildPid) != childJails.end())
         {
@@ -415,10 +415,9 @@ int main(int argc, char** argv)
             // If we need to spawn more, retry later.
             ForkCounter = (newInstances >= ForkCounter ? 0 : ForkCounter - newInstances);
         }
-        else
-        {
-            cleanupChildren();
-        }
+
+        // We virtually always fork when a child exits.
+        cleanupChildren();
     }
 
     int returnValue = Application::EXIT_OK;
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index 11390cc..ff82de9 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -63,6 +63,7 @@ public:
     {
         if (_ws)
         {
+            Log::trace("Shutting down WS [" + getName() + "].");
             _ws->shutdown(statusCode);
         }
     }
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 37660c3..59f90c5 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -251,24 +251,35 @@ 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;
         }
     }
 
+    int balance = LOOLWSD::NumPreSpawnedChildren;
+    balance -= newChildren.size();
+    if (balance <= 0)
+    {
+        return;
+    }
+
     const auto duration = (std::chrono::steady_clock::now() - lastForkRequestTime);
-    if (std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() <= CHILD_TIMEOUT_MS)
+    if (!rebalance &&
+        std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() <= CHILD_TIMEOUT_MS)
     {
         // Not enough time passed to balance children.
         return;
     }
 
-    const int available = newChildren.size();
-    int balance = LOOLWSD::NumPreSpawnedChildren;
-    balance -= available;
     forkChildren(balance);
 }
 


More information about the Libreoffice-commits mailing list