Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I restart a node process once it reaches a certain memory size (leak)?

I have a memory leak in a Node.js, and I'm working on trying to find it but it's currently deployed to Heroku. I'd like to currently have something that would restart the process once it reaches a certain size in memory (especially since I have a few dynos running).

like image 823
Dory Zidon Avatar asked Oct 14 '25 08:10

Dory Zidon


2 Answers

Do you use PM2 to run your app? If yes there's a good config option that fits your need called max_memory_restart.

http://pm2.keymetrics.io/docs/usage/monitoring/#max-memory-restart

like image 62
fadliawan Avatar answered Oct 18 '25 01:10

fadliawan


Not finding a solution I created a npm utli lib that does that. Please note it does not work on windows though.

It's based on cluster and status npm libs.

http://github.com/DoryZi/memory_limiter

like image 21
Dory Zidon Avatar answered Oct 18 '25 01:10

Dory Zidon