I have an Express.js web app which is constantly breaking because of memory problems:
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap
out of memory
When I start the service, the memory usage is about 170Mb (reported by htop as RES memory). Then I start throwing request at it, and the memory start rising.
I'm using memwatch
to try to track the problem in what looks like a memory leak, but a memwatch.HeapDiff()
reports something like:
{ before: { nodes: 2093729, size_bytes: 197165296, size: '188.03 mb' },
after: { nodes: 2491264, size_bytes: 232097040, size: '221.34 mb' },
...
... where I understand that the app is using 221.34mb for the heap; but with htop
the memory usage is about 2GB when it breaks.
The question is, if my assumptions are right, what could be using non-heap memory that is still reported by htop as RES memory?
I've seen this before , where memory reported in used was much smaller that memory as seen by htop.
In our case it was a memory leak in JavaScript that looked small, but when was fixed resolved the memory issue.
I wrote a post detailing the steps I took to diagnose it, it's too long to post in here.
https://techtldr.com/simple-guide-to-finding-a-javascript-memory-leak-in-node-js/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With