[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - loleaflet/admin.strings.js loleaflet/dist loleaflet/src wsd/Admin.cpp wsd/Admin.hpp wsd/AdminModel.hpp wsd/LOOLWSD.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Jul 31 21:10:10 UTC 2017
loleaflet/admin.strings.js | 4 +
loleaflet/dist/admin/adminSettings.html | 8 +++
loleaflet/src/admin/AdminSocketSettings.js | 4 +
wsd/Admin.cpp | 67 +++++++++++++++++++++--------
wsd/Admin.hpp | 5 ++
wsd/AdminModel.hpp | 13 +++++
wsd/LOOLWSD.cpp | 17 +++++--
7 files changed, 96 insertions(+), 22 deletions(-)
New commits:
commit 97e11108cc35fed11be008c76a9876557d57918d
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Jun 11 22:51:38 2017 -0400
Support setting rlimits from Admin Console
Change-Id: Ia0d45948998d7a5612a1828a90ad20908d07639e
Reviewed-on: https://gerrit.libreoffice.org/38677
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
(cherry picked from commit 9e11cd7db711b86fadbc0a2d00920268779233d2)
Reviewed-on: https://gerrit.libreoffice.org/38762
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/loleaflet/admin.strings.js b/loleaflet/admin.strings.js
index 66b51774..5e0cb661 100644
--- a/loleaflet/admin.strings.js
+++ b/loleaflet/admin.strings.js
@@ -27,6 +27,10 @@ l10nstrings.strMemoryStatsCachesize = _('Cache size of memory statistics');
l10nstrings.strMemoryStatsInterval = _('Time interval of memory statistics (in ms)');
l10nstrings.strCpuStatsCachesize = _('Cache size of CPU statistics');
l10nstrings.strCpuStatsInterval = _('Time interval of CPU statistics (in ms)');
+l10nstrings.strLimitVirtMemMb = _('Maximum Document process virtual memory (in MB)');
+l10nstrings.strLimitDataMemKb = _('Maximum Document process data memory (in KB)');
+l10nstrings.strLimitStackMemKb = _('Maximum Document process stack memory (in KB)');
+l10nstrings.strLimitFileSizeMb = _('Maximum file size allowed to write to disk (in MB)');
if (module) {
module.exports = l10nstrings;
diff --git a/loleaflet/dist/admin/adminSettings.html b/loleaflet/dist/admin/adminSettings.html
index fb1cff71..4426ac6a 100644
--- a/loleaflet/dist/admin/adminSettings.html
+++ b/loleaflet/dist/admin/adminSettings.html
@@ -83,6 +83,14 @@
<input type="text" id="cpu_stats_size" name="Cpu Stats Size"><br/>
<label for="cpu_stats_interval"><script>document.write(l10nstrings.strCpuStatsInterval)</script></label>
<input type="text" id="cpu_stats_interval" name="Cpu Stats Interval"><br/>
+ <label for="limit_virt_mem_mb"><script>document.write(l10nstrings.strLimitVirtMemMb)</script></label>
+ <input type="text" id="limit_virt_mem_mb" name="Max Document Virtual Memory MB"><br/>
+ <label for="limit_data_mem_kb"><script>document.write(l10nstrings.strLimitDataMemKb)</script></label>
+ <input type="text" id="limit_data_mem_kb" name="Max Document Data Memory KB"><br/>
+ <label for="limit_stack_mem_kb"><script>document.write(l10nstrings.strLimitStackMemKb)</script></label>
+ <input type="text" id="limit_stack_mem_kb" name="Max Document Stack Memory Kb"><br/>
+ <label for="limit_file_size_mb"><script>document.write(l10nstrings.strLimitFileSizeMb)</script></label>
+ <input type="text" id="limit_file_size_mb" name="Max File Write Size Mb"><br/>
<script>document.write('<input type="submit" value="' + l10nstrings.strSave + '"/><br/>')</script>
</form>
<br />
diff --git a/loleaflet/src/admin/AdminSocketSettings.js b/loleaflet/src/admin/AdminSocketSettings.js
index 537d1487..630067f1 100644
--- a/loleaflet/src/admin/AdminSocketSettings.js
+++ b/loleaflet/src/admin/AdminSocketSettings.js
@@ -23,6 +23,10 @@ var AdminSocketSettings = AdminSocketBase.extend({
command += ' mem_stats_interval=' + memStatsInterval;
command += ' cpu_stats_size=' + cpuStatsSize;
command += ' cpu_stats_interval=' + cpuStatsInterval;
+ command += ' limit_virt_mem_mb=' + $('#limit_virt_mem_mb').val();
+ command += ' limit_data_mem_kb=' + $('#limit_data_mem_kb').val();
+ command += ' limit_stack_mem_kb=' + $('#limit_stack_mem_kb').val();
+ command += ' limit_file_size_mb=' + $('#limit_file_size_mb').val();
socketSettings.send(command);
});
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index ef2fecec..29d77c16 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -156,14 +156,19 @@ void AdminSocketHandler::handleMessage(bool /* fin */, WSOpCode /* code */,
{
// for now, we have only these settings
std::ostringstream oss;
- oss << tokens[0] << " "
- << "mem_stats_size=" << model.query("mem_stats_size") << " "
- << "mem_stats_interval=" << std::to_string(_admin->getMemStatsInterval()) << " "
- << "cpu_stats_size=" << model.query("cpu_stats_size") << " "
- << "cpu_stats_interval=" << std::to_string(_admin->getCpuStatsInterval());
-
- std::string responseFrame = oss.str();
- sendTextFrame(responseFrame);
+ oss << "settings "
+ << "mem_stats_size=" << model.query("mem_stats_size") << ' '
+ << "mem_stats_interval=" << std::to_string(_admin->getMemStatsInterval()) << ' '
+ << "cpu_stats_size=" << model.query("cpu_stats_size") << ' '
+ << "cpu_stats_interval=" << std::to_string(_admin->getCpuStatsInterval()) << ' ';
+
+ const DocProcSettings& docProcSettings = _admin->getDefDocProcSettings();
+ oss << "limit_virt_mem_mb=" << docProcSettings.LimitVirtMemMb << ' '
+ << "limit_data_mem_kb=" << docProcSettings.LimitDataMemKb << ' '
+ << "limit_stack_mem_kb=" << docProcSettings.LimitStackMemKb << ' '
+ << "limit_file_size_mb=" << docProcSettings.LimitFileSizeMb << ' ';
+
+ sendTextFrame(oss.str());
}
else if (tokens[0] == "shutdown")
{
@@ -177,7 +182,7 @@ void AdminSocketHandler::handleMessage(bool /* fin */, WSOpCode /* code */,
for (size_t i = 1; i < tokens.count(); i++)
{
StringTokenizer setting(tokens[i], "=", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
- unsigned settingVal = 0;
+ int settingVal = 0;
try
{
settingVal = std::stoi(setting[1]);
@@ -189,38 +194,66 @@ void AdminSocketHandler::handleMessage(bool /* fin */, WSOpCode /* code */,
return;
}
- if (setting[0] == "mem_stats_size")
+ const std::string settingName = setting[0];
+ if (settingName == "mem_stats_size")
{
- if (settingVal != static_cast<unsigned>(std::stoi(model.query(setting[0]))))
+ if (settingVal != std::stoi(model.query(settingName)))
{
model.setMemStatsSize(settingVal);
}
}
- else if (setting[0] == "mem_stats_interval")
+ else if (settingName == "mem_stats_interval")
{
- if (settingVal != _admin->getMemStatsInterval())
+ if (settingVal != static_cast<int>(_admin->getMemStatsInterval()))
{
_admin->rescheduleMemTimer(settingVal);
model.clearMemStats();
model.notify("settings mem_stats_interval=" + std::to_string(settingVal));
}
}
- else if (setting[0] == "cpu_stats_size")
+ else if (settingName == "cpu_stats_size")
{
- if (settingVal != static_cast<unsigned>(std::stoi(model.query(setting[0]))))
+ if (settingVal != std::stoi(model.query(settingName)))
{
model.setCpuStatsSize(settingVal);
}
}
- else if (setting[0] == "cpu_stats_interval")
+ else if (settingName == "cpu_stats_interval")
{
- if (settingVal != _admin->getCpuStatsInterval())
+ if (settingVal != static_cast<int>(_admin->getCpuStatsInterval()))
{
_admin->rescheduleCpuTimer(settingVal);
model.clearCpuStats();
model.notify("settings cpu_stats_interval=" + std::to_string(settingVal));
}
}
+ else if (LOOLProtocol::matchPrefix("limit_", settingName))
+ {
+ DocProcSettings docProcSettings = _admin->getDefDocProcSettings();
+ if (settingName == "limit_virt_mem_mb")
+ {
+ docProcSettings.LimitVirtMemMb = settingVal;
+ }
+ else if (settingName == "limit_data_mem_kb")
+ {
+ docProcSettings.LimitDataMemKb = settingVal;
+ }
+ else if (settingName == "limit_stack_mem_kb")
+ {
+ docProcSettings.LimitStackMemKb = settingVal;
+ }
+ else if (settingName == "limit_file_size_mb")
+ {
+ docProcSettings.LimitFileSizeMb = settingVal;
+ }
+ else
+ {
+ LOG_ERR("Unknown limit: " << settingName);
+ }
+
+ model.notify("settings " + settingName + '=' + std::to_string(settingVal));
+ _admin->setDefDocProcSettings(docProcSettings);
+ }
}
}
}
diff --git a/wsd/Admin.hpp b/wsd/Admin.hpp
index 864c6c82..2edaba85 100644
--- a/wsd/Admin.hpp
+++ b/wsd/Admin.hpp
@@ -102,6 +102,9 @@ public:
void dumpState(std::ostream& os) override;
+ const DocProcSettings& getDefDocProcSettings() const { return _defDocProcSettings; }
+ void setDefDocProcSettings(const DocProcSettings& docProcSettings) { _defDocProcSettings = docProcSettings; }
+
private:
/// Memory consumption has increased, start killing kits etc. till memory consumption gets back
/// under @hardModeLimit
@@ -117,6 +120,8 @@ private:
std::atomic<int> _memStatsTaskIntervalMs;
std::atomic<int> _cpuStatsTaskIntervalMs;
+
+ DocProcSettings _defDocProcSettings;
};
#endif
diff --git a/wsd/AdminModel.hpp b/wsd/AdminModel.hpp
index f963a9da..5a35bc8c 100644
--- a/wsd/AdminModel.hpp
+++ b/wsd/AdminModel.hpp
@@ -60,6 +60,13 @@ struct DocBasicInfo
_saved(saved),
_mem(mem)
{ }
+
+struct DocProcSettings
+{
+ size_t LimitVirtMemMb;
+ size_t LimitDataMemKb;
+ size_t LimitStackMemKb;
+ size_t LimitFileSizeMb;
};
/// A document in Admin controller.
@@ -105,6 +112,9 @@ public:
void setModified(bool value) { _isModified = value; }
bool getModifiedStatus() const { return _isModified; }
+ const DocProcSettings& getDocProcSettings() const { return _docProcSettings; }
+ void setDocProcSettings(const DocProcSettings& docProcSettings) { _docProcSettings = docProcSettings; }
+
private:
bool _isModified;
const std::string _docKey;
@@ -121,6 +131,9 @@ private:
std::time_t _start;
std::time_t _lastActivity;
std::time_t _end = 0;
+
+ /// Per-doc kit process settings.
+ DocProcSettings _docProcSettings;
};
/// An Admin session subscriber.
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index d7545dbd..7a1333ab 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -805,7 +805,7 @@ void LOOLWSD::initialize(Application& self)
std::cerr << "\nLaunch this in your browser:\n\n"
<< getLaunchURI() << '\n' << std::endl;
- std::string adminURI = getAdminURI(config());
+ const std::string adminURI = getAdminURI(config());
if (!adminURI.empty())
std::cerr << "\nOr for the Admin Console:\n\n"
<< adminURI << '\n' << std::endl;
@@ -1168,11 +1168,18 @@ bool LOOLWSD::createForKit()
args.push_back("--clientport=" + std::to_string(ClientPortNumber));
args.push_back("--masterport=" + std::to_string(MasterPortNumber));
+ DocProcSettings docProcSettings;
+ docProcSettings.LimitVirtMemMb = getConfigValue<int>("per_document.limit_virt_mem_mb", 0);
+ docProcSettings.LimitDataMemKb = getConfigValue<int>("per_document.limit_data_mem_kb", 0);
+ docProcSettings.LimitStackMemKb = getConfigValue<int>("per_document.limit_stack_mem_kb", 0);
+ docProcSettings.LimitFileSizeMb = getConfigValue<int>("per_document.limit_file_size_mb", 0);
+ Admin::instance().setDefDocProcSettings(docProcSettings);
+
std::ostringstream ossRLimits;
- ossRLimits << "limit_virt_mem_mb:" << getConfigValue<int>("per_document.limit_virt_mem_mb", 0);
- ossRLimits << ";limit_data_mem_kb:" << getConfigValue<int>("per_document.limit_data_mem_kb", 0);
- ossRLimits << ";limit_stack_mem_kb:" << getConfigValue<int>("per_document.limit_stack_mem_kb", 0);
- ossRLimits << ";limit_file_size_mb:" << getConfigValue<int>("per_document.limit_file_size_mb", 0);
+ ossRLimits << "limit_virt_mem_mb:" << docProcSettings.LimitVirtMemMb;
+ ossRLimits << ";limit_data_mem_kb:" << docProcSettings.LimitDataMemKb;
+ ossRLimits << ";limit_stack_mem_kb:" << docProcSettings.LimitStackMemKb;
+ ossRLimits << ";limit_file_size_mb:" << docProcSettings.LimitFileSizeMb;
args.push_back("--rlimits=" + ossRLimits.str());
if (UnitWSD::get().hasKitHooks())
More information about the Libreoffice-commits
mailing list