[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Tue May 3 03:05:54 UTC 2016
loolwsd/LOOLWSD.cpp | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
New commits:
commit 68f24e375afd7ffa36ca4eacd86bc23281dd7fb5
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Mon May 2 22:57:27 2016 -0400
loolwsd: replenish the child reservoir and cleanup dead ones
Change-Id: I705ba01ca6254ff61ddd8ebc1248117b9fec7d20
Reviewed-on: https://gerrit.libreoffice.org/24601
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 3c0bdcb..77bdab1 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -177,6 +177,7 @@ static void forkChildren(const int number)
}
}
+/// Called on startup only.
static void preForkChildren()
{
std::unique_lock<std::mutex> lock(newChildrenMutex);
@@ -186,6 +187,24 @@ static void preForkChildren()
forkChildren(numPreSpawn);
}
+static void prespawnChildren()
+{
+ std::unique_lock<std::mutex> lock(newChildrenMutex);
+
+ for (int i = newChildren.size() - 1; i >= 0; --i)
+ {
+ if (!newChildren[i]->isAlive())
+ {
+ newChildren.erase(newChildren.begin() + i);
+ }
+ }
+
+ const int available = newChildren.size();
+ int balance = LOOLWSD::NumPreSpawnedChildren;
+ balance -= available;
+ forkChildren(balance);
+}
+
static std::shared_ptr<ChildProcess> getNewChild()
{
std::unique_lock<std::mutex> lock(newChildrenMutex);
@@ -203,6 +222,7 @@ static std::shared_ptr<ChildProcess> getNewChild()
else
{
balance -= available - 1; // Minus the one we'll dispatch just now.
+ std::max(balance, 0);
}
Log::debug("getNewChild: Have " + std::to_string(available) + " children, forking " + std::to_string(balance));
@@ -1593,7 +1613,11 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
last30SecCheck = time(nullptr);
}
}
+
sleep(WSD_SLEEP_SECS);
+
+ // Make sure we have sufficient reserves.
+ prespawnChildren();
}
#if ENABLE_DEBUG
if (careerSpanSeconds > 0 && time(nullptr) > startTimeSpan + careerSpanSeconds)
More information about the Libreoffice-commits
mailing list