[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLWSD.cpp
Michael Meeks
michael.meeks at collabora.com
Tue Apr 5 11:21:36 UTC 2016
loolwsd/LOOLBroker.cpp | 19 +++----------------
loolwsd/LOOLWSD.cpp | 24 ++++++++++++++++++------
2 files changed, 21 insertions(+), 22 deletions(-)
New commits:
commit 0278743fb271acd1f6fadc5f214a1dcf85e5bf4b
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Mon Apr 4 15:17:03 2016 +0100
Move pre-forking of children from loolbroker to WSD.
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index ca96cba..6dae2bd 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -59,9 +59,8 @@ static const std::string BROKER_PREFIX = "lokit";
static int WriterNotify = -1;
static int ReaderBroker = -1;
-static std::atomic<unsigned> ForkCounter;
+static std::atomic<unsigned> ForkCounter( 0 );
static unsigned int ChildCounter = 0;
-static int NumPreSpawnedChildren = 1;
using namespace LOOLProtocol;
@@ -1278,9 +1277,6 @@ static void printArgumentHelp()
std::cout << " --lotemplate=<path> path of libreoffice template to pre-populate chroot with." << std::endl;
std::cout << " --pipe=<path> path of loolwsd pipe to connect to on startup." << std::endl;
std::cout << " --losubpath=<path> path to libreoffice install" << std::endl;
- std::cout << "" << std::endl;
- std::cout << " Some paramaters are optional:" << std::endl;
- std::cout << " --numprespawns=<number> pre-fork at least <number> processes [1]" << std::endl;
}
void setupPipes(const std::string &childRoot)
@@ -1348,11 +1344,6 @@ int main(int argc, char** argv)
eq = std::strchr(cmd, '=');
childRoot = std::string(eq+1);
}
- else if (std::strstr(cmd, "--numprespawns=") == cmd)
- {
- eq = std::strchr(cmd, '=');
- NumPreSpawnedChildren = std::stoi(std::string(eq+1));
- }
else if (std::strstr(cmd, "--clientport=") == cmd)
{
eq = std::strchr(cmd, '=');
@@ -1361,8 +1352,7 @@ int main(int argc, char** argv)
}
if (loSubPath.empty() || sysTemplate.empty() ||
- loTemplate.empty() || childRoot.empty() ||
- NumPreSpawnedChildren < 1)
+ loTemplate.empty() || childRoot.empty())
{
printArgumentHelp();
return 1;
@@ -1381,16 +1371,13 @@ int main(int argc, char** argv)
Log::info("Preinit stage OK.");
- // We must have at least one child, more is created dynamically.
+ // We must have at least one child, more are created dynamically.
if (createLibreOfficeKit(childRoot, sysTemplate, loTemplate, loSubPath) < 0)
{
Log::error("Error: failed to create children.");
std::exit(Application::EXIT_SOFTWARE);
}
- if (NumPreSpawnedChildren > 1)
- ForkCounter = NumPreSpawnedChildren - 1;
-
ChildDispatcher childDispatcher;
Log::info("loolbroker is ready.");
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 93e65ee..9b91c85 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -179,6 +179,21 @@ static std::condition_variable newChildsCV;
static std::map<std::string, std::shared_ptr<DocumentBroker>> docBrokers;
static std::mutex docBrokersMutex;
+void forkChildren(int number)
+{
+ assert(!newChildsMutex.try_lock()); // check it is held.
+
+ const std::string aMessage = "spawn " + std::to_string(number) + "\n";
+ Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 1));
+ IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
+}
+
+void preForkChildren()
+{
+ std::unique_lock<std::mutex> lock(newChildsMutex);
+ forkChildren(LOOLWSD::NumPreSpawnedChildren);
+}
+
std::shared_ptr<ChildProcess> getNewChild()
{
std::unique_lock<std::mutex> lock(newChildsMutex);
@@ -195,11 +210,7 @@ std::shared_ptr<ChildProcess> getNewChild()
}
if (balance > 0)
- {
- const std::string aMessage = "spawn " + std::to_string(balance) + "\n";
- Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 1));
- IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
- }
+ forkChildren(balance);
const auto timeout = std::chrono::milliseconds(CHILD_TIMEOUT_SECS * 1000);
if (newChildsCV.wait_for(lock, timeout, [](){ return !newChilds.empty(); }))
@@ -1149,7 +1160,6 @@ Process::PID LOOLWSD::createBroker()
args.push_back("--systemplate=" + SysTemplate);
args.push_back("--lotemplate=" + LoTemplate);
args.push_back("--childroot=" + ChildRoot);
- args.push_back("--numprespawns=" + std::to_string(NumPreSpawnedChildren));
args.push_back("--clientport=" + std::to_string(ClientPortNumber));
const std::string brokerPath = Path(Application::instance().commandPath()).parent().toString() + "loolbroker";
@@ -1316,6 +1326,8 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
waitForTerminationRequest();
}
+ preForkChildren();
+
time_t last30SecCheck = time(NULL);
time_t lastFiveMinuteCheck = time(NULL);
More information about the Libreoffice-commits
mailing list