简体   繁体   中英

why nodejs is not respecting the memory limits set in pm2 ecosystem file

I am trying to configure nodejs to use only 512 MB of ram memory. Here is my ecosystem config file

module.exports = {
  apps: [{
   script: './app.js',
   watch: true,
   instances: "max",
   exec_mode  : "cluster",
   ignore_watch : ["node_modules"],
   "node_args": "--max_old_space_size=512",
   }]
};

and here is the pm2 script in package.json

"scripts": {
"start": "env-cmd -f ./Config/dev.env pm2 start ecosystem.config.js --no-daemon",
"dev": "env-cmd -f ./Config/dev.env nodemon start app.js",
"debug": "env-cmd -f ./Config/dev.env node --inspect app.js"
}

When I run my code using npm run start. And I check my memory of using free -m command I can see that I am using 750 MB of ram memory

I think you have to use --max-memory-restart instead of --max_old_space_size either in your echo system or command line arguments

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM