loolwsd/LOOLBroker.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
New commits: commit 75ede04cd7fd88e1113625f6497c00e485fa28dc Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sun Jan 24 14:49:45 2016 -0500 loolwsd: improved child forking Change-Id: Ic05b412bb9c467659c24cba12f385ed9c0c67b84 Reviewed-on: https://gerrit.libreoffice.org/21758 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp index ae2a5a7..77e8708 100644 --- a/loolwsd/LOOLBroker.cpp +++ b/loolwsd/LOOLBroker.cpp @@ -318,7 +318,7 @@ public: if ( nBytes < 0 ) { Log::error("Error sending search message to child pipe: " + std::to_string(it->first) + ". Terminating."); - removeChild(it->second); + removeChild(it->first); it = _childProcesses.cbegin(); continue; } @@ -329,7 +329,7 @@ public: if ( nBytes < 0 ) { Log::error("Error reading response to search message from child [" + std::to_string(it->first) + "]. Terminating."); - removeChild(it->second); + removeChild(it->first); it = _childProcesses.cbegin(); continue; } @@ -591,7 +591,7 @@ static int createLibreOfficeKit(const bool sharePages, Log::info() << "Adding Kit #" << childCounter << ", PID: " << child << Log::end; _childProcesses[child] = nFIFOWriter; - ++forkCounter; + --forkCounter; return child; } @@ -847,17 +847,24 @@ int main(int argc, char** argv) { std::lock_guard<std::recursive_mutex> lock(forkMutex); + pipeHandler.verifyChilds(); + // Figure out how many children we need. const signed total = _childProcesses.size(); const signed used = _cacheURL.size(); const signed extra = total - used; - if (extra < numPreSpawnedChildren) + signed spawn = std::min(static_cast<int>(forkCounter), numPreSpawnedChildren); + Log::debug() << "Spawning " << spawn << " children. Current Total: " << total + << ", used: " << used << ", extra: " << extra << Log::end; + do { if (createLibreOfficeKit(sharePages, loSubPath, jailId) < 0) Log::error("Error: fork failed."); } - else - forkCounter = 0; + while (--spawn > 0); + + // We've done our best. If need more, retrying will bump the counter. + forkCounter = 0; } int status; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits