Skip to content

Commit

Permalink
#2501 low memory environment option via PM2_OPTIMIZE_MEMORY
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Jul 4, 2017
1 parent b0fd46c commit 34d13dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- #2997 --disable-logs option to suppress error
- #2290 allow to declare apps under "pm2" attribute (eq "apps"). Nicer in package.json
- pm2 install module-name --uid <uid> --gid <gid> possible
- #2501 low memory environment pm2 setting via PM2_OPTIMIZE_MEMORY (beta)
- #2968 pm2 attach <pm_id> to attach to process stdin / stdout
- pm2-runtime -> drop in replacement for the node.js binary
- #2951 pm2 reload command locker via timestamped lock file
Expand Down
2 changes: 2 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var csts = {
CLUSTER_MODE_ID : 'cluster_mode',
FORK_MODE_ID : 'fork_mode',

LOW_MEMORY_ENVIRONMENT : process.env.PM2_OPTIMIZE_MEMORY || false,

KEYMETRICS_ROOT_URL : process.env.KEYMETRICS_NODE || 'root.keymetrics.io',
KEYMETRICS_BANNER : '../lib/keymetrics',
DEFAULT_MODULE_JSON : 'package.json',
Expand Down
8 changes: 6 additions & 2 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,14 @@ Client.prototype.launchDaemon = function(opts, cb) {
err = fs.openSync(that.conf.PM2_LOG_FILE_PATH, 'a');
}

if (this.conf.LOW_MEMORY_ENVIRONMENT) {
var os = require('os');
node_args.push('--gc-global'); // Does full GC (smaller memory footprint)
node_args.push('--max-old-space-size=' + Math.floor(os.totalmem() / 1024 / 1024));
}

// Node.js tuning for better performance
//node_args.push('--expose-gc'); // Allows manual GC in the code
//node_args.push('--gc-global'); // Does full GC (smaller memory footprint)
//node_args.push('--max-old-space-size=100');

/**
* Add node [arguments] depending on PM2_NODE_OPTIONS env variable
Expand Down

0 comments on commit 34d13dc

Please sign in to comment.