I'm getting my processes Killed by the out-of-memory killer. What I'd like to do is tell node "don't use so much memory" and throw an exception if it can't allocate some junk, so that I avoid being killed by the oom killer and potentially can handle it in code. Is this possible? How do I do this?
-
Can't you just track down and modify the particular code that's causing your memory problems? Even if you could put some sort of smaller cap to it from "being killed by the oom killer", what would you even do when the limit was hit?mscdex– mscdex2014-09-18 19:45:47 +00:00Commented Sep 18, 2014 at 19:45
-
Perhaps in here is something: blog.caustik.com/2012/08/19/node-js-w1m-concurrent-connections? ( Look through the blog. )loveNoHate– loveNoHate2014-09-18 19:46:30 +00:00Commented Sep 18, 2014 at 19:46
-
Or here ( Part 5 ): hacks.mozilla.org/category/a-node-js-holiday-season?loveNoHate– loveNoHate2014-09-18 20:05:40 +00:00Commented Sep 18, 2014 at 20:05
-
@mscdex This is part of tracking it down. If my code threw an exception when it was out of memory, at very least I would know where it was when it hit the memory ceiling. Without that, I'm back to using console logs to figure out where it dies. What would be really great is some kind of profiler that tells me what parts of my code cause what memory overhead.B T– B T2014-09-18 23:13:01 +00:00Commented Sep 18, 2014 at 23:13
-
@DOCASAREL Thanks.. but i'm not gonna look through random blogs on the offchance they've answered my very specific question. I have to assume my google searching would have covered that.B T– B T2014-09-18 23:14:54 +00:00Commented Sep 18, 2014 at 23:14
|
Show 1 more comment
1 Answer
There are various modules on npm that can help you find out what is taking up so much memory.
To start with:
node-webkit-agent allows you to do memory (and CPU) profiling and take and compare heap snapshots all within Chrome developer tools.
heapdump and a related article about using it here. This can be useful if you don't want/need all of the features of
node-webkit-agentand want to periodically save heapdumps to disk from your code.node-inspector for interactive debugging and live inspection of variables and such.
3 Comments
B T
+1 for the debugging suggestions, but it technically doesn't answer the question of how I can gracefully handle out of memory problems on the node side.
mscdex
You can't gracefully handle out of memory problems because that comes from V8. For now the most "graceful" thing you can do is have something like the
forever module, monit, systemd, etc. automatically restart your process when it dies unexpectedly like that.B T
Well actually, my issue is coming from the linux out-of-memory killer, which kills processes when the system is out of memory or when the program is using too much memory. So my issue is most definitely not from V8. Are you saying that if I did limit the memory on the V8/node side, it still wouldn't be graceful? I would still appreciate knowing how to do that.