loolwsd/LOOLWSD.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
New commits: commit f4b4037f9ed73501159efb359702df2bbb161d25 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sun Oct 23 16:00:32 2016 -0400 loolwsd: spawn new children when no forks are outstanding This avoids always waiting until child spawning times out by being smarter about whether or not there are any children spawning to wait for. Change-Id: I96a16ac35f90f70219d4153db9862cf2ee5b6a76 Reviewed-on: https://gerrit.libreoffice.org/30213 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index a287320..e1c07cb 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -167,6 +167,7 @@ static std::vector<std::shared_ptr<ChildProcess>> NewChildren; static std::mutex NewChildrenMutex; static std::condition_variable NewChildrenCV; static std::chrono::steady_clock::time_point LastForkRequestTime = std::chrono::steady_clock::now(); +static std::atomic<int> OutstandingForks(1); // Forkit always spawns 1. static std::map<std::string, std::shared_ptr<DocumentBroker>> DocBrokers; static std::mutex DocBrokersMutex; @@ -257,6 +258,8 @@ static void forkChildren(const int number) Util::checkDiskSpaceOnRegisteredFileSystems(); const std::string aMessage = "spawn " + std::to_string(number) + "\n"; Log::debug("MasterToForKit: " + aMessage.substr(0, aMessage.length() - 1)); + + ++OutstandingForks; IoUtil::writeToPipe(LOOLWSD::ForKitWritePipe, aMessage); LastForkRequestTime = std::chrono::steady_clock::now(); } @@ -315,27 +318,29 @@ static void prespawnChildren() // Do the cleanup first. const bool rebalance = cleanupChildren(); - int balance = LOOLWSD::NumPreSpawnedChildren; - balance -= NewChildren.size(); - if (balance <= 0) + const auto duration = (std::chrono::steady_clock::now() - LastForkRequestTime); + const auto durationMs = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(); + if (durationMs >= CHILD_TIMEOUT_MS) { - return; + // Children taking too long to spawn. + // Forget we had requested any, and request anew. + OutstandingForks = 0; } - const auto duration = (std::chrono::steady_clock::now() - LastForkRequestTime); - if (!rebalance && - std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() <= CHILD_TIMEOUT_MS) + int balance = LOOLWSD::NumPreSpawnedChildren; + balance -= NewChildren.size(); + balance -= OutstandingForks; + + if (rebalance || durationMs >= CHILD_TIMEOUT_MS) { - // Not enough time passed to balance children. - return; + forkChildren(balance); } - - forkChildren(balance); } static size_t addNewChild(const std::shared_ptr<ChildProcess>& child) { std::unique_lock<std::mutex> lock(NewChildrenMutex); + --OutstandingForks; NewChildren.emplace_back(child); const auto count = NewChildren.size(); Log::info() << "Have " << count << " " _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits