Skip to content

Commit

Permalink
feat: Set the embedded process priority to below normal for good measure
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Nov 4, 2023
1 parent aac0f51 commit eadc2a7
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions backend/lib/Valetudo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit eadc2a7

Please sign in to comment.