I have a nodejs application in production and I have a memory leaks (memory increases from 600Mo to 3Go in 3 days).
I searched some tools to take a memory dump but I found only plugins who need to be in the application to write dump.
Of course, I can't stop my application and restart it (after modification) to take snapshot, I would like to take a memory dump outside node with a outside tools.
Do you know a tool like this ?
Thanks.
The best approach to checking for the existence of a memory leak in your application is by looking at your RAM usage and investigating the total amount of memory been used versus the total amount available. Evidently, it is advisable to obtain snapshots of your memory's heap dump while in a production environment.
The primary tools for detecting memory leaks are the C/C++ debugger and the C Run-time Library (CRT) debug heap functions. The #define statement maps a base version of the CRT heap functions to the corresponding debug version. If you leave out the #define statement, the memory leak dump will be less detailed.
You can create one (or better several) heapdump(s) in two ways, modifying the code, or without modifying the code.
require('heapdump');
at the beginning of your code.kill -USR2 {{pid}}
from the terminal, or from the code with process.kill(process.pid, 'SIGUSR2');
heapdump-XXX.YYY.heapsnapshot
files, that you can compare with Chrome Dev Tools.kill -USR1 {{pid}}
. Note that this will enable the debug mode, causing an apparent "freeze" in the process.node-inspector
(posible after installing it globally by doing npm install -g node-inspector
)http://0.0.0.0:8080/debug?port=5858
in Google Chrome (port 8080 is used by node-inspector, and port 5858 is used by debugger), this will cause the process to "unfreeze"Snapshot X
files, that you can compare with Chrome Dev Tools.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