allocate swap size for containers based on system ratio
This commit is contained in:
+3
-2
@@ -59,6 +59,7 @@ var appdb = require('./appdb.js'),
|
||||
spawn = require('child_process').spawn,
|
||||
split = require('split'),
|
||||
request = require('request'),
|
||||
system = require('./system.js'),
|
||||
util = require('util');
|
||||
|
||||
const NOOP = function (app, options, callback) { return callback(); };
|
||||
@@ -811,7 +812,7 @@ function updateServiceConfig(platformConfig, callback) {
|
||||
const containerConfig = platformConfig[serviceName];
|
||||
let memory, memorySwap;
|
||||
if (containerConfig && containerConfig.memoryLimit) {
|
||||
memory = containerConfig.memoryLimit / 2;
|
||||
memory = system.getMemoryAllocation(containerConfig.memoryLimit);
|
||||
memorySwap = containerConfig.memoryLimit;
|
||||
} else {
|
||||
memory = SERVICES[serviceName].defaultMemoryLimit;
|
||||
@@ -838,7 +839,7 @@ function updateAppServiceConfig(name, instance, servicesConfig, callback) {
|
||||
const serviceConfig = servicesConfig[name];
|
||||
let memory, memorySwap;
|
||||
if (serviceConfig && serviceConfig.memoryLimit) {
|
||||
memory = serviceConfig.memoryLimit / 2;
|
||||
memory = system.getMemoryAllocation(serviceConfig.memoryLimit);
|
||||
memorySwap = serviceConfig.memoryLimit;
|
||||
} else {
|
||||
memory = APP_SERVICES[name].defaultMemoryLimit;
|
||||
|
||||
+2
-1
@@ -45,6 +45,7 @@ var addons = require('./addons.js'),
|
||||
settings = require('./settings.js'),
|
||||
shell = require('./shell.js'),
|
||||
safe = require('safetydance'),
|
||||
system = require('./system.js'),
|
||||
util = require('util'),
|
||||
volumes = require('./volumes.js'),
|
||||
_ = require('underscore');
|
||||
@@ -313,7 +314,7 @@ function createSubcontainer(app, name, cmd, options, callback) {
|
||||
'syslog-format': 'rfc5424'
|
||||
}
|
||||
},
|
||||
Memory: memoryLimit / 2,
|
||||
Memory: system.getMemoryAllocation(memoryLimit),
|
||||
MemorySwap: memoryLimit, // Memory + Swap
|
||||
PortBindings: isAppContainer ? dockerPortBindings : { },
|
||||
PublishAllPorts: false,
|
||||
|
||||
+16
-5
@@ -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