From eadc2a7a047531722c1a59729fcb5cde5e565bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= Date: Sat, 4 Nov 2023 18:24:33 +0100 Subject: [PATCH] feat: Set the embedded process priority to below normal for good measure --- backend/lib/Valetudo.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/backend/lib/Valetudo.js b/backend/lib/Valetudo.js index 61f7f1ba032..fb9d8414bbd 100644 --- a/backend/lib/Valetudo.js +++ b/backend/lib/Valetudo.js @@ -187,22 +187,32 @@ class Valetudo { * @private */ setupEmbeddedTweaks() { - if (this.config.get("embedded") === true) { - try { - const newOOMScoreAdj = 666; - const previousOOMScoreAdj = parseInt(fs.readFileSync("/proc/self/oom_score_adj").toString()); + if (this.config.get("embedded") !== true) { + return; + } - if (previousOOMScoreAdj > newOOMScoreAdj) { - Logger.info("Current /proc/self/oom_score_adj: " + newOOMScoreAdj); - } else { - fs.writeFileSync("/proc/self/oom_score_adj", newOOMScoreAdj.toString()); + try { + const newOOMScoreAdj = 666; + const previousOOMScoreAdj = parseInt(fs.readFileSync("/proc/self/oom_score_adj").toString()); - Logger.info("Setting /proc/self/oom_score_adj to " + newOOMScoreAdj + ". Previous value: " + previousOOMScoreAdj); - } - } catch (e) { - Logger.warn("Error while setting OOM Score Adj:", e); + if (previousOOMScoreAdj > newOOMScoreAdj) { + Logger.info("Current /proc/self/oom_score_adj: " + newOOMScoreAdj); + } else { + fs.writeFileSync("/proc/self/oom_score_adj", newOOMScoreAdj.toString()); + + Logger.info(`Setting /proc/self/oom_score_adj to ${newOOMScoreAdj}. Previous value: ${previousOOMScoreAdj}`); } + } catch (e) { + Logger.warn("Error while setting OOM Score Adj:", e); } + + + const newPriority = os.constants.priority.PRIORITY_BELOW_NORMAL; + const previousPriority = os.getPriority(); + + os.setPriority(newPriority); + + Logger.info(`Setting process priority to ${newPriority}. Previous value: ${previousPriority}`); } async shutdown() {