kit/ForKit.cpp | 9 ++++++--- kit/Kit.cpp | 9 +++++---- kit/Kit.hpp | 5 +++-- test/test.cpp | 22 ++++++++++++++++------ test/test.hpp | 7 ++++++- wsd/LOOLWSD.cpp | 2 +- 6 files changed, 37 insertions(+), 17 deletions(-)
New commits: commit 720c26176a09d8622cb7a8414b555b6f4f986d58 Author: Ashod Nakashian <[email protected]> AuthorDate: Sat Sep 21 14:39:32 2019 -0400 Commit: Ashod Nakashian <[email protected]> CommitDate: Sun Sep 22 20:23:27 2019 +0200 wsd: improved kit thread naming Now the wsd docbroker thread and its peer kit thread are trivial to match, since they are called docbroker_xxx and kitbroker_xxx (where xxx is the instance ID) respectively. Also, label spare kit instances as kit_spare_xxx to differentiate from ones with actual documents, where xxx is a running counter to differentiate spare instances from one another. Now we are able to easily see (and count) the number of spare kit instances, and match wsd and kit threads handling a given document. Unit-test logic updated to reflect the new thread naming scheme. Change-Id: I154dc8f200fbe0e65f3f5984e6dad2cef1b52e22 Reviewed-on: https://gerrit.libreoffice.org/79328 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp index 81bff060e..2eea47725 100644 --- a/kit/ForKit.cpp +++ b/kit/ForKit.cpp @@ -250,7 +250,10 @@ static int createLibreOfficeKit(const std::string& childRoot, // Generate a jail ID to be used for in the jail path. const std::string jailId = Util::rng::getFilename(16); - LOG_DBG("Forking a loolkit process with jailId: " << jailId << "."); + // Used to label the spare kit instances + static size_t spareKitId = 0; + ++spareKitId; + LOG_DBG("Forking a loolkit process with jailId: " << jailId << " as spare loolkit #" << spareKitId << "."); const Process::PID pid = fork(); if (!pid) @@ -277,9 +280,9 @@ static int createLibreOfficeKit(const std::string& childRoot, } #ifndef KIT_IN_PROCESS - lokit_main(childRoot, jailId, sysTemplate, loTemplate, loSubPath, NoCapsForKit, NoSeccomp, queryVersion, DisplayVersion); + lokit_main(childRoot, jailId, sysTemplate, loTemplate, loSubPath, NoCapsForKit, NoSeccomp, queryVersion, DisplayVersion, spareKitId); #else - lokit_main(childRoot, jailId, sysTemplate, loTemplate, loSubPath, true, true, queryVersion, DisplayVersion); + lokit_main(childRoot, jailId, sysTemplate, loTemplate, loSubPath, true, true, queryVersion, DisplayVersion, spareKitId); #endif } else diff --git a/kit/Kit.cpp b/kit/Kit.cpp index beebb8aa2..b2a4a8b23 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -490,7 +490,6 @@ public: // Shrink cache when we exceed the size to maximize // the chance of hitting these entries in the future. _cacheSize -= it->second.getData()->size(); - it = _cache.erase(it); } else @@ -2262,6 +2261,7 @@ protected: std::string url; URI::decode(docKey, url); LOG_INF("New session [" << sessionId << "] request on url [" << url << "]."); + Util::setThreadName("kitbroker_" + docId); if (!document) document = std::make_shared<Document>(_loKit, _jailId, docKey, docId, url, _queue, shared_from_this()); @@ -2428,11 +2428,12 @@ void lokit_main( bool noCapabilities, bool noSeccomp, bool queryVersion, - bool displayVersion + bool displayVersion, #else const std::string& documentUri, - int docBrokerSocket + int docBrokerSocket, #endif + size_t spareKitId ) { #if !MOBILEAPP @@ -2442,7 +2443,7 @@ void lokit_main( SigUtil::setTerminationSignals(); #endif - Util::setThreadName("loolkit"); + Util::setThreadName("kit_spare_" + Util::encodeId(spareKitId, 3)); // Reinitialize logging when forked. const bool logToFile = std::getenv("LOOL_LOGFILE"); diff --git a/kit/Kit.hpp b/kit/Kit.hpp index 0f8d90d6c..5c94c1342 100644 --- a/kit/Kit.hpp +++ b/kit/Kit.hpp @@ -35,11 +35,12 @@ void lokit_main( bool noCapabilities, bool noSeccomp, bool queryVersionInfo, - bool displayVersion + bool displayVersion, #else const std::string& documentUri, - int docBrokerSocket + int docBrokerSocket, #endif + size_t spareKitId ); bool globalPreinit(const std::string& loTemplate); diff --git a/test/test.cpp b/test/test.cpp index f5824b1d1..8df5d1e79 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -181,7 +181,7 @@ std::vector<int> getProcPids(const char* exec_filename) std::vector<int> pids; // Ensure we're in the same group. - int grp = getpgrp(); + const int grp = getpgrp(); // Get all lokit processes. for (auto it = Poco::DirectoryIterator(std::string("/proc")); it != Poco::DirectoryIterator(); ++it) @@ -207,7 +207,7 @@ std::vector<int> getProcPids(const char* exec_filename) std::string statString; Poco::StreamCopier::copyToString(stat, statString); Poco::StringTokenizer tokens(statString, " "); - if (tokens.count() > 6 && tokens[1] == exec_filename) + if (tokens.count() > 6 && tokens[1].find(exec_filename) == 0) { // We could have several make checks running at once. int kidGrp = std::atoi(tokens[4].c_str()); @@ -236,18 +236,28 @@ std::vector<int> getProcPids(const char* exec_filename) return pids; } -std::vector<int> getKitPids() +std::vector<int> getSpareKitPids() { - std::vector<int> pids; + return getProcPids("(kit_spare_"); +} - pids = getProcPids("(loolkit)"); +std::vector<int> getDocKitPids() +{ + return getProcPids("(kitbroker_"); +} + +std::vector<int> getKitPids() +{ + std::vector<int> pids = getSpareKitPids(); + for (int pid : getDocKitPids()) + pids.push_back(pid); return pids; } int getLoolKitProcessCount() { - return getProcPids("(loolkit)").size(); + return getKitPids().size(); } std::vector<int> getForKitPids() diff --git a/test/test.hpp b/test/test.hpp index 2f85cac25..7f907673b 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -20,9 +20,14 @@ bool runClientTests(bool standalone, bool verbose); // ---- Abstraction for standalone vs. WSD ---- -/// Get the list of kit PIDs +/// Get the list of all kit PIDs std::vector<int> getKitPids(); +/// Get the list of spare (unused) kit PIDs +std::vector<int> getSpareKitPids(); +/// Get the list of doc (loaded) kit PIDs +std::vector<int> getDocKitPids(); + /// Get the PID of the forkit std::vector<int> getForKitPids(); diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index bc971eb38..9595eb8aa 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -517,7 +517,7 @@ std::shared_ptr<ChildProcess> getNewChild_Blocks( // Ugly to have that static global, otoh we know there is just one LOOLWSD // object. (Even in real Online.) - lokit_main(uri, LOOLWSD::prisonerServerSocketFD); + lokit_main(uri, LOOLWSD::prisonerServerSocketFD, 1); }).detach(); #endif _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
