Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/API/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
"docDefault": "~/.pm2/pids/app_name-id.pid",
"docDescription": "File path where the pid of the started process is written by pm2"
},
"cpu_limit": {
"type": "number",
"docDefault": 0,
"docDescription": "Max percentage of a CPU core to allow this app to use"
},
"restart_delay": {
"type" : "number",
"docDefault": 0,
Expand Down
16 changes: 16 additions & 0 deletions lib/God/ForkMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ module.exports = function ForkMode(God) {
cspr.process.pid = cspr.pid;
cspr.pm2_env = pm2_env;

// limit CPU
if (pm2_env.cpu_limit) {
var cpuLimiter = require('cpulimit');
var cpuLimiterOptions = {
limit: pm2_env.cpu_limit,
includeChildren: true,
pid: cspr.process.pid
};
cpuLimiter.createProcessFamily(cpuLimiterOptions, function (err, processFamily) {
if (err) {
return;
}
cpuLimiter.limit(processFamily, cpuLimiterOptions);
});
}

cspr.stderr.on('data', function forkErrData(data) {
var log_data = null;

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"chokidar": "^2.0.4",
"cli-table-redemption": "^1.0.0",
"commander": "2.15.1",
"cpulimit": "git+https://github.com/vangelov/node-cpulimit.git",
"cron": "^1.3",
"debug": "^3.1",
"eventemitter2": "5.0.1",
Expand Down