-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically restart processes using more than a fixed amount of RAM #141
Comments
I need it too. Maybe restart based on amount of CPU usage too. |
+1 |
👍 Very useful feature for production while debugging the leak in dev. |
+1 |
I think you could set a memory limit in node.js/v8 command-line arguments, so it'll crash when the limit is reached. And pm2 will restart it as usual. Would this work for you? |
Thanks @rlidwka you mean by V8_MAX_SEMISPACE_SIZE ? or any other way to set it on with PM2 ? |
I'm talking about If you're using pm2, I suppose I'm not sure if it's the right way, but it seems worth exploring. |
That's nice and working. Just tested with a small memory leak that tests the pidusage module. This test breaks when memory is up to 200 MB and with
Of course when using pm2 the process will be restarted. Thanks @rlidwka for this nice information! Should it be added to pm2 anyway? To restart on CPU or memory amount with pm2 we 'd have to check the process status based on an interval which would lead to more CPU usage, I don't think that it's a good idea. Suggestions are welcome. |
Thanks a lot @rlidwka ! |
I've added the option --max-restart-memory: https://github.com/Unitech/pm2/tree/development#automatic-restart-process-based-on-memory Thanks for that v8 trick @rlidwka ! |
Hey @Unitech actually the max-restart-memory doesn't work well in my machine, the memory in my machine keeps under 100M, but my node instance will automatically restart every 30s. |
I have the same problem where after about 8-10 hours, the pm2 instance runs of out of memory and never recovers. When I log into the server and run pm2 list, its like pm2 was never running and it restarts the Daemonizer. Here's my log. This is running on a 512MB Debian digital ocean droplet. I run it with the command 'pm2 start -x index.js'
|
Maybe it is your app which takes large amounts of memory and thus PM2 doesn't have enough. |
Sure but shouldn't pm2 be catching that error and restart itself? Is it because I'm using fork mode? I guess I don't have to since it is only 1 core.. Its using jsdom and jquery and reading web page, I make sure to close the session each time but I'm sure its possible the dom library has some leaks in it. Idk if its a PM2 issue or a Node issue in general, but every app I've made I've noticed that memory use always constantly increases, its never dumped. Is there a fix for this that I've missed? |
Well, the thing is, in order to update itself, PM2 calls spawn('pm2 update') but since there's not enough memory for spawn(), it doesn't work. That's why you see the error twice. The first time it gets triggered by a spawn() in the worker, the second time it gets triggered when pm2 tries to update itself. |
Thanks guys, my issue is addressed by restarted the pm2 process, because in my previous boot script I set max-memory-restart to 80m, but later i changed it to 150m, but I guess there is a cache problem, so the solution is to kill the pm2 and restart it by using the new setup. By the way, could someone can point out how the max-memory-restart is working? what's the difference from the v8 flag: max-old-space-size? |
Okay thank you @jorge-d |
It's just a worker which checks every 30sec the memory usage of your app and restarts it if it exceeds the limit |
@ablankenship10 PM2 v0.12.16 is released. This bug shouldn't happen anymore. At least it won't crash PM2 if ENOMEM occurs. |
What is the default value of max-memory-restart? We are seeing that in a nodejs app we have given the max-old-space to be 512M its not hitting that limit. Still pm2 is retsrating our app. Does pm2 restart on cpu reaching 100% or anything too? |
Btw, in nodejs 7 I see:
|
It would be very valuable to get the option to kill and respawn processes that are using more memory than a configurable amount. This would help a lot in the case of a leaking app. Indeed, consider the following scenario:
I'm not saying that leaking apps are a good thing. But from a "host" point of view, killing and respawning seems like the best thing to do. This is what Heroku does, for example.
The text was updated successfully, but these errors were encountered: