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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Apr 4 04:07:45 UTC 2016


 loolwsd/LOOLBroker.cpp |    6 ++++++
 loolwsd/LOOLWSD.cpp    |   31 +++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

New commits:
commit f4b80e630a0dce207bab9d993353a9243e3511b3
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Apr 3 19:00:37 2016 -0400

    loolwsd: consume new child from wsd
    
    And spawn new child instances.
    
    Change-Id: I51886f4645a1c8944ccde2e0fae415afc7c8fc24
    Reviewed-on: https://gerrit.libreoffice.org/23788
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index a529316..5231eab 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -268,6 +268,12 @@ private:
             Process::PID nPid = static_cast<Process::PID>(std::stoi(tokens[1]));
             removeChild(nPid, true);
         }
+        else if (tokens[0] == "spawn" && tokens.count() == 2)
+        {
+            const auto count = std::stoi(tokens[1]);
+            Log::info("Spawning " + tokens[1] + " childs per request.");
+            ForkCounter = count;
+        }
     }
 
 private:
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f4224be..ded9089 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -183,6 +183,8 @@ public:
     {
     }
 
+    /// pid is the process ID of the child.
+    /// ws is the control WebSocket to the child.
     ChildProcess(const Poco::Process::PID pid, const std::shared_ptr<Poco::Net::WebSocket>& ws) :
         _pid(pid),
         _ws(ws)
@@ -247,6 +249,35 @@ static std::mutex newChildsMutex;
 static std::map<std::string, std::shared_ptr<DocumentBroker>> docBrokers;
 static std::mutex docBrokersMutex;
 
+std::shared_ptr<ChildProcess> getNewChild()
+{
+    std::unique_lock<std::mutex> lock(newChildsMutex);
+
+    const signed available = newChilds.size();
+    signed balance = LOOLWSD::NumPreSpawnedChildren;
+    if (available == 0)
+    {
+        Log::error("No available child. Sending spawn request to Broker and failing.");
+    }
+    else
+    {
+        balance -= available - 1;
+    }
+
+    const std::string aMessage = "spawn " + std::to_string(balance) + "\n";
+    Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 1));
+    IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
+
+    if (available > 0)
+    {
+        auto child = newChilds.back();
+        newChilds.pop_back();
+        return child;
+    }
+
+    return nullptr;
+}
+
 /// Handles the filename part of the convert-to POST request payload.
 class ConvertToPartHandler : public PartHandler
 {


More information about the Libreoffice-commits mailing list