Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node JS pm2 maximum memory limit

I'm using pm2 and node js. What I want to do is set a maximum memory limit for an application. My dev server's limit is 500mb split between two applications. Ideally I would like to limit it to 200mb. I need this limit to be a hard limit for the application, and for it to not restart the application if it exceeds it like the pm2 command "max_memory_restart" does. I've also tried to use the --max_old_space_size command with no luck. Is there any way to do this?

Example pm2 json file

{
  "apps": [
   {
     "name": "Sample",
     "script": "runit.js",
     "watch": false,
     "cwd": "xxxxxx",
     "env": {
       "NODE_TLS_REJECT_UNAUTHORIZED": '0',
       "NODE_ENV": "local_public",
       "PORT": 3000,
       "PROXY_PORT": 4000,
     },
     "args": [
       "--max_old_space_size=200"
     ]
   }
 ]

}

like image 854
N8ALL3N Avatar asked Mar 22 '17 22:03

N8ALL3N


1 Answers

I used pm2 to directly run node.js scripts and this code works for me:

pm2 start file.js --max-memory-restart 100M

Hope the max-memory-restart argument works for you

like image 100
zhangjinzhou Avatar answered Nov 08 '22 12:11

zhangjinzhou