memoryLimit: redefine to not include swap

Currently, we allocate 50% as RAM and 50% as swap. The manifest is
usually quite conservative on memory values. This means that we set
up a system where the app is applying memory pressure almost immediately.
This then swaps things randomly and increases cpu usage (kswapd shows
up in the profile).

To rethink the whole situation: we should not cap apps with a swap limit at all.
The memory hard limit is what is important. By redefining memoryLimit , we are
doubling every container's memory and it's good that we over allocate this.
This commit is contained in:
Girish Ramakrishnan
2024-04-09 18:59:40 +02:00
parent 6c3f8b9b84
commit be2775e12e
8 changed files with 18 additions and 47 deletions
+4 -6
View File
@@ -49,7 +49,6 @@ const apps = require('./apps.js'),
semver = require('semver'),
shell = require('./shell.js'),
safe = require('safetydance'),
system = require('./system.js'),
timers = require('timers/promises'),
volumes = require('./volumes.js');
@@ -349,8 +348,8 @@ async function createSubcontainer(app, name, cmd, options) {
'syslog-format': 'rfc5424'
}
},
Memory: await system.getMemoryAllocation(memoryLimit),
MemorySwap: memoryLimit, // Memory + Swap
Memory: memoryLimit,
MemorySwap: -1, // Unlimited swap
PortBindings: isAppContainer ? dockerPortBindings : { },
PublishAllPorts: false,
ReadonlyRootfs: app.debugMode ? !!app.debugMode.readonlyRootfs : true,
@@ -643,15 +642,14 @@ async function df() {
return result;
}
async function update(name, memory, memorySwap) {
async function update(name, memory) {
assert.strictEqual(typeof name, 'string');
assert.strictEqual(typeof memory, 'number');
assert.strictEqual(typeof memorySwap, 'number');
// scale back db containers, if possible. this is retried because updating memory constraints can fail
// with failed to write to memory.memsw.limit_in_bytes: write /sys/fs/cgroup/memory/docker/xx/memory.memsw.limit_in_bytes: device or resource busy
for (let times = 0; times < 10; times++) {
const [error] = await safe(shell.exec(`update(${name})`, `docker update --memory ${memory} --memory-swap ${memorySwap} ${name}`, {}));
const [error] = await safe(shell.exec(`update(${name})`, `docker update --memory ${memory} --memory-swap -1 ${name}`, {}));
if (!error) return;
await timers.setTimeout(60 * 1000);
}