[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp

Jan Holesovsky kendy at collabora.com
Fri Jan 22 16:03:37 PST 2016


 loolwsd/LOOLSession.cpp |    2 +-
 loolwsd/LOOLWSD.cpp     |   36 +++++++++++++++++++++++++-----------
 loolwsd/LOOLWSD.hpp     |    6 ++++--
 3 files changed, 30 insertions(+), 14 deletions(-)

New commits:
commit 59be0d108453db81f25c95da15c4f18f803fd509
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Sat Jan 23 00:59:02 2016 +0100

    loolwsd: Improve handling of pre-spawns.
    
    Make sure there are always --numprespawns children pre-spawned.  When we are
    over the limit, start only one new child.

diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 430e9fa..9da15b0 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -708,7 +708,7 @@ void MasterProcessSession::dispatchChild()
     {
         LOOLWSD::_namedMutexLOOL.lock();
         std::cout << Util::logPrefix() << "No available child sessions, queue new child session" << std::endl;
-        LOOLWSD::_sharedForkChild.begin()[0] = LOOLWSD::_numPreSpawnedChildren;
+        ++reinterpret_cast<size_t*>(LOOLWSD::_sharedForkChild.begin())[0];
         LOOLWSD::_namedMutexLOOL.unlock();
     }
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index eb6794e..0440430 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -481,9 +481,13 @@ public:
                 while (!LOOLWSD::isShutDown &&
                         (!pollTimeout || (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)));
 
+                Application::instance().logger().information(Util::logPrefix() + "Finished the websocket handling.");
+
                 queue.clear();
                 queue.put("eof");
                 queueHandlerThread.join();
+
+                Application::instance().logger().information(Util::logPrefix() + "queueHandlerThread joined.");
             }
             catch (WebSocketException& exc)
             {
@@ -632,9 +636,9 @@ std::string LOOLWSD::jail;
 std::mutex LOOLWSD::_rngMutex;
 Random LOOLWSD::_rng;
 Poco::NamedMutex LOOLWSD::_namedMutexLOOL("loolwsd");
-Poco::SharedMemory LOOLWSD::_sharedForkChild("loolwsd", sizeof(bool), Poco::SharedMemory::AM_WRITE);
+Poco::SharedMemory LOOLWSD::_sharedForkChild("loolwsd", sizeof(size_t), Poco::SharedMemory::AM_WRITE);
 
-int LOOLWSD::_numPreSpawnedChildren = 10;
+size_t LOOLWSD::_numPreSpawnedChildren = 10;
 bool LOOLWSD::doTest = false;
 volatile bool LOOLWSD::isShutDown = false;
 #if ENABLE_DEBUG
@@ -1175,13 +1179,14 @@ int LOOLWSD::createComponent()
     return Application::EXIT_OK;
 }
 
-void LOOLWSD::startupComponent(int nComponents)
+bool LOOLWSD::startupComponent(int nComponents)
 {
     for (int nCntr = nComponents; nCntr; nCntr--)
     {
         if (createComponent() < 0)
-            break;
+            return false;
     }
+    return true;
 }
 
 void LOOLWSD::desktopMain()
@@ -1204,7 +1209,7 @@ void LOOLWSD::desktopMain()
         {
             if ( MasterProcessSession::_childProcesses.find(pid) != MasterProcessSession::_childProcesses.end() )
             {
-                if ((WIFEXITED(status) || WIFSIGNALED(status) || WTERMSIG(status) ) )
+                if ((WIFEXITED(status) || WIFSIGNALED(status)))
                 {
                     std::cout << Util::logPrefix() << "One of our known child processes died :" << std::to_string(pid)  << std::endl;
                     // remove chroot child
@@ -1236,14 +1241,23 @@ void LOOLWSD::desktopMain()
         else if (pid < 0)
             std::cout << Util::logPrefix() << "Child error: " << strerror(errno);
 
-        if (!LOOLWSD::isShutDown && _sharedForkChild.begin()[0] > 0 )
+        // spawn or pre-spawn new children
+        if (!LOOLWSD::isShutDown)
         {
             _namedMutexLOOL.lock();
-            _sharedForkChild.begin()[0] = _sharedForkChild.begin()[0] - 1;
-            std::cout << Util::logPrefix() << "Create child session, fork new one" << std::endl;
+            size_t toSpawn = reinterpret_cast<size_t*>(_sharedForkChild.begin())[0];
+            reinterpret_cast<size_t*>(_sharedForkChild.begin())[0] = 0;
             _namedMutexLOOL.unlock();
-            if (createComponent() < 0 )
-                break;
+
+            if (MasterProcessSession::_childProcesses.size() + toSpawn < _numPreSpawnedChildren)
+                toSpawn = _numPreSpawnedChildren - MasterProcessSession::_childProcesses.size();
+
+            if (toSpawn > 0)
+            {
+                std::cout << Util::logPrefix() << "Create child session, fork new ones: " << toSpawn << std::endl;
+                if (!startupComponent(toSpawn))
+                    break;
+            }
         }
 
         ++timeoutCounter;
@@ -1377,7 +1391,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
         {
             if ( MasterProcessSession::_childProcesses.find(pid) != MasterProcessSession::_childProcesses.end() )
             {
-                if ((WIFEXITED(status) || WIFSIGNALED(status) || WTERMSIG(status) ) )
+                if ((WIFEXITED(status) || WIFSIGNALED(status)))
                 {
                     std::cout << Util::logPrefix() << "One of our known child processes died :" << std::to_string(pid)  << std::endl;
                     MasterProcessSession::_childProcesses.erase(pid);
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 62e4c32..f58917a 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -32,7 +32,7 @@ public:
     // statics
     static int portNumber;
     static int timeoutCounter;
-    static int _numPreSpawnedChildren;
+    static size_t _numPreSpawnedChildren;
     static bool doTest;
     static bool volatile isShutDown;
     static std::string cache;
@@ -69,7 +69,9 @@ private:
     void displayHelp();
     void componentMain();
     void desktopMain();
-    void startupComponent(int nComponents);
+
+    /// Call createComponent() nComponents-times.
+    bool startupComponent(int nComponents);
     void startupDesktop(int nDesktop);
     int  createComponent();
     int  createDesktop();


More information about the Libreoffice-commits mailing list