allocate swap size for containers based on system ratio
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
exports = module.exports = {
|
||||
getDisks,
|
||||
checkDiskSpace,
|
||||
getMemory
|
||||
getMemory,
|
||||
getMemoryAllocation
|
||||
};
|
||||
|
||||
const apps = require('./apps.js'),
|
||||
@@ -148,14 +149,24 @@ function checkDiskSpace(callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function getMemory(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
function getSwapSize() {
|
||||
const stdout = safe.child_process.execSync('swapon --noheadings --raw --bytes --show=SIZE', { encoding: 'utf8' });
|
||||
const swap = !stdout ? 0 : stdout.trim().split('\n').map(x => parseInt(x, 10) || 0).reduce((acc, cur) => acc + cur);
|
||||
|
||||
return swap;
|
||||
}
|
||||
|
||||
function getMemory(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
callback(null, {
|
||||
memory: os.totalmem(),
|
||||
swap: swap
|
||||
swap: getSwapSize()
|
||||
});
|
||||
}
|
||||
|
||||
function getMemoryAllocation(limit) {
|
||||
const pc = os.totalmem() / (os.totalmem() + getSwapSize());
|
||||
const ratio = Math.round(pc * 10) / 10; // a simple ratio
|
||||
return Math.round(Math.round(limit * ratio) / 1048576) * 1048576; // nearest MB
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user