Skip to content

Instantly share code, notes, and snippets.

@ivan-loh
Last active March 3, 2021 13:26
Show Gist options
  • Star 57 You must be signed in to star a gist
  • Fork 23 You must be signed in to fork a gist
  • Save ivan-loh/ee0d96c3795e59244063 to your computer and use it in GitHub Desktop.
Save ivan-loh/ee0d96c3795e59244063 to your computer and use it in GitHub Desktop.
Node.JS ( & pm2 ) Process Memory Limit
# Plain Ol' Node
node --max-old-space-size=1024 app.js # increase to 1gb
node --max-old-space-size=2048 app.js # increase to 2gb
node --max-old-space-size=3072 app.js # increase to 3gb
node --max-old-space-size=4096 app.js # increase to 4gb
node --max-old-space-size=5120 app.js # increase to 5gb
node --max-old-space-size=6144 app.js # increase to 6gb
# For pm2
pm2 start app.js --node-args="--max-old-space-size=1024" # increase to 1gb
pm2 start app.js --node-args="--max-old-space-size=2048" # increase to 2gb
pm2 start app.js --node-args="--max-old-space-size=3072" # increase to 3gb
pm2 start app.js --node-args="--max-old-space-size=4096" # increase to 4gb
pm2 start app.js --node-args="--max-old-space-size=5120" # increase to 5gb
pm2 start app.js --node-args="--max-old-space-size=6144" # increase to 6gb
@neophob
Copy link

neophob commented Feb 13, 2017

correct parameter name is --max_old_space_size

check it: node --v8-options | grep 'max_old_space_size'

@bchr02
Copy link

bchr02 commented Feb 28, 2017

No, actually both ways work. See npm/npm#12238 (comment)

@jayeshbhalodia
Copy link

jayeshbhalodia commented Sep 18, 2017

For Forever - https://www.npmjs.com/package/forever

forever start -c "/usr/local/bin/node --stack_size=1024 --max-old-space-size=1024" app-prod.js #increase to 1GB
forever start -c "/usr/local/bin/node --stack_size=2048 --max-old-space-size=2048" app-prod.js #increase to 2GB
forever start -c "/usr/local/bin/node --stack_size=3072 --max-old-space-size=3072" app-prod.js #increase to 3GB
forever start -c "/usr/local/bin/node --stack_size=4096 --max-old-space-size=4096" app-prod.js #increase to 4GB
forever start -c "/usr/local/bin/node --stack_size=5120 --max-old-space-size=5120" app-prod.js #increase to 5GB
forever start -c "/usr/local/bin/node --stack_size=6144 --max-old-space-size=6144" app-prod.js #increase to 6GB

👍

@nikoohp
Copy link

nikoohp commented Dec 10, 2018

#pm2 use configuration within a JSON file

{
  "apps": [
    {
      ...
      "node_args": "--max_old_space_size=4096"
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment