[Libreoffice-commits] online.git: common/Util.cpp common/Util.hpp loolwsd.xml.in wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp
Michael Meeks (via logerrit)
logerrit at kemper.freedesktop.org
Sat May 2 20:03:55 UTC 2020
common/Util.cpp | 19 ++++++++++++++++---
common/Util.hpp | 3 +++
loolwsd.xml.in | 1 +
wsd/DocumentBroker.cpp | 19 +++++++++++++++++--
wsd/DocumentBroker.hpp | 13 ++++++++++++-
wsd/LOOLWSD.cpp | 9 ++++++---
6 files changed, 55 insertions(+), 9 deletions(-)
New commits:
commit 92eff552a5fcef89a6bd0abadf19570c2f5457b8
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Sat May 2 19:13:14 2020 +0100
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Sat May 2 22:03:36 2020 +0200
Lower convert-to process priorities by default.
Interactive / editing processes should take precedence over batch
thumbnailing processes to keep responsiveness good.
Change-Id: Ib100409e312cb2ca545586a734711a31a92f110c
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/93323
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/common/Util.cpp b/common/Util.cpp
index 0ae624983..881836c34 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -14,9 +14,10 @@
#include <csignal>
#include <sys/poll.h>
#ifdef __linux
-#include <sys/prctl.h>
-#include <sys/syscall.h>
-#include <sys/vfs.h>
+# include <sys/prctl.h>
+# include <sys/syscall.h>
+# include <sys/vfs.h>
+# include <sys/resource.h>
#elif defined IOS
#import <Foundation/Foundation.h>
#endif
@@ -520,6 +521,18 @@ namespace Util
}
return 0;
}
+
+ void setProcessAndThreadPriorities(const pid_t pid, int prio)
+ {
+ int res = setpriority(PRIO_PROCESS, pid, prio);
+ LOG_TRC("Lowered kit [" << (int)pid << "] priority: " << prio << " with result: " << res);
+
+ // rely on Linux thread-id priority setting to drop this thread' priority
+ pid_t tid = getThreadId();
+ res = setpriority(PRIO_PROCESS, tid, prio);
+ LOG_TRC("Lowered own thread [" << (int)tid << "] priority: " << prio << " with result: " << res);
+ }
+
#endif
std::string replace(std::string result, const std::string& a, const std::string& b)
diff --git a/common/Util.hpp b/common/Util.hpp
index 105eef7dd..0f19828ba 100644
--- a/common/Util.hpp
+++ b/common/Util.hpp
@@ -151,6 +151,9 @@ namespace Util
size_t getCpuUsage(const pid_t pid);
size_t getStatFromPid(const pid_t pid, int ind);
+
+ /// Sets priorities for a given pid & the current thread
+ void setProcessAndThreadPriorities(const pid_t pid, int prio);
#endif
std::string replace(std::string s, const std::string& a, const std::string& b);
diff --git a/loolwsd.xml.in b/loolwsd.xml.in
index 4b40aa46f..bbd37ec35 100644
--- a/loolwsd.xml.in
+++ b/loolwsd.xml.in
@@ -15,6 +15,7 @@
<num_prespawn_children desc="Number of child processes to keep started in advance and waiting for new clients." type="uint" default="1">1</num_prespawn_children>
<per_document desc="Document-specific settings, including LO Core settings.">
<max_concurrency desc="The maximum number of threads to use while processing a document." type="uint" default="4">4</max_concurrency>
+ <batch_priority desc="A (lower) priority for use by batch eg. convert-to processes to avoid starving interactive ones" type="uint" default="5">5</batch_priority>
<document_signing_url desc="The endpoint URL of signing server, if empty the document signing is disabled" type="string" default="@VEREIGN_URL@">@VEREIGN_URL@</document_signing_url>
<redlining_as_comments desc="If true show red-lines as comments" type="bool" default="false">false</redlining_as_comments>
<idle_timeout_secs desc="The maximum number of seconds before unloading an idle document. Defaults to 1 hour." type="uint" default="3600">3600</idle_timeout_secs>
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 801343c63..f0e4a99df 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -172,11 +172,13 @@ public:
std::atomic<unsigned> DocumentBroker::DocBrokerId(1);
-DocumentBroker::DocumentBroker(const std::string& uri,
+DocumentBroker::DocumentBroker(ChildType type,
+ const std::string& uri,
const Poco::URI& uriPublic,
const std::string& docKey) :
_limitLifeSeconds(0),
_uriOrig(uri),
+ _type(type),
_uriPublic(uriPublic),
_docKey(docKey),
_docId(Util::encodeId(DocBrokerId++, 3)),
@@ -206,6 +208,17 @@ DocumentBroker::DocumentBroker(const std::string& uri,
"] created with docKey [" << _docKey << "]");
}
+void DocumentBroker::setupPriorities()
+{
+#if !MOBILEAPP
+ if (_type == ChildType::Batch)
+ {
+ int prio = LOOLWSD::getConfigValue<int>("per_document.batch_priority", 5);
+ Util::setProcessAndThreadPriorities(_childProcess->getPid(), prio);
+ }
+#endif // !MOBILE
+}
+
void DocumentBroker::startThread()
{
_poll->startThread();
@@ -271,6 +284,8 @@ void DocumentBroker::pollThread()
_childProcess->setDocumentBroker(shared_from_this());
LOG_INF("Doc [" << _docKey << "] attached to child [" << _childProcess->getPid() << "].");
+ setupPriorities();
+
static const bool AutoSaveEnabled = !std::getenv("LOOL_NO_AUTOSAVE");
#if !MOBILEAPP
@@ -2226,7 +2241,7 @@ ConvertToBroker::ConvertToBroker(const std::string& uri,
const std::string& docKey,
const std::string& format,
const std::string& sOptions) :
- DocumentBroker(uri, uriPublic, docKey),
+ DocumentBroker(ChildType::Batch, uri, uriPublic, docKey),
_format(format),
_sOptions(sOptions)
{
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 61f74f5a7..40784b204 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -109,7 +109,15 @@ class ClientSession;
class DocumentBroker : public std::enable_shared_from_this<DocumentBroker>
{
class DocumentBrokerPoll;
+
+ void setupPriorities();
+
public:
+ /// How to prioritize this document.
+ enum class ChildType {
+ Interactive, Batch
+ };
+
static Poco::URI sanitizeURI(const std::string& uri);
/// Returns a document-specific key based
@@ -120,7 +128,8 @@ public:
DocumentBroker();
/// Construct DocumentBroker with URI, docKey, and root path.
- DocumentBroker(const std::string& uri,
+ DocumentBroker(ChildType type,
+ const std::string& uri,
const Poco::URI& uriPublic,
const std::string& docKey);
@@ -361,6 +370,8 @@ protected:
/// Seconds to live for, or 0 forever
int64_t _limitLifeSeconds;
std::string _uriOrig;
+ /// What type are we: affects priority.
+ ChildType _type;
private:
const Poco::URI _uriPublic;
/// URL-based key. May be repeated during the lifetime of WSD.
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index dbe119067..60d3c0376 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -914,6 +914,7 @@ void LOOLWSD::initialize(Application& self)
{ "per_document.limit_stack_mem_kb", "8000" },
{ "per_document.limit_virt_mem_mb", "0" },
{ "per_document.max_concurrency", "4" },
+ { "per_document.batch_priority", "5" },
{ "per_document.redlining_as_comments", "false" },
{ "per_view.idle_timeout_secs", "900" },
{ "per_view.out_of_focus_timeout_secs", "120" },
@@ -1816,6 +1817,7 @@ std::mutex Connection::Mutex;
/// After returning a valid instance DocBrokers must be cleaned up after exceptions.
static std::shared_ptr<DocumentBroker>
findOrCreateDocBroker(const std::shared_ptr<ProtocolHandlerInterface>& proto,
+ DocumentBroker::ChildType type,
const std::string& uri,
const std::string& docKey,
const std::string& id,
@@ -1891,7 +1893,7 @@ static std::shared_ptr<DocumentBroker>
// Set the one we just created.
LOG_DBG("New DocumentBroker for docKey [" << docKey << "].");
- docBroker = std::make_shared<DocumentBroker>(uri, uriPublic, docKey);
+ docBroker = std::make_shared<DocumentBroker>(type, uri, uriPublic, docKey);
DocBrokers.emplace(docKey, docBroker);
LOG_TRC("Have " << DocBrokers.size() << " DocBrokers after inserting [" << docKey << "].");
}
@@ -2962,7 +2964,7 @@ private:
std::shared_ptr<ProtocolHandlerInterface> none;
// Request a kit process for this doc.
std::shared_ptr<DocumentBroker> docBroker = findOrCreateDocBroker(
- none, url, docKey, _id, uriPublic);
+ none, DocumentBroker::ChildType::Interactive, url, docKey, _id, uriPublic);
std::string fullURL = request.getURI();
std::string ending = "/ws/wait";
@@ -3078,7 +3080,8 @@ private:
// Request a kit process for this doc.
std::shared_ptr<DocumentBroker> docBroker = findOrCreateDocBroker(
- std::static_pointer_cast<ProtocolHandlerInterface>(ws), url, docKey, _id, uriPublic);
+ std::static_pointer_cast<ProtocolHandlerInterface>(ws),
+ DocumentBroker::ChildType::Interactive, url, docKey, _id, uriPublic);
if (docBroker)
{
#if MOBILEAPP
More information about the Libreoffice-commits
mailing list