Node.JS process uses 1.4 GB of memory, but heapdum

2019-04-10 01:17发布

问题:

I'm running a Socket.IO server with Node.JS, which normally uses about 400 MB of memory, because there's a lot of data being cached to send to clients. However, after a couple of hours it suddenly starts growing to 1.4 GB of usage over about 40 minutes. Someone told me to use heapdump to find if there is a memory leak.

The problem is that the heapdump only turned out to be 317 MB and nothing in it looks out of the ordinary, so I'm stuck with debugging. I've also run it with nodetime, which says that the V8 heap usage is around 400 MB, but the total V8 heap size is 1.4 GB.

How do I find out where the remaining 1 GB comes from?

回答1:

Maybe node-memwatch could help you?

https://github.com/lloyd/node-memwatch

From its Readme:

node-memwatch is here to help you detect and find memory leaks in Node.JS code. It provides:

A leak event, emitted when it appears your code is leaking memory.

A stats event, emitted occasionally, giving you data describing your heap usage and trends over time.

A HeapDiff class that lets you compare the state of your heap between two points in time, telling you what has been allocated, and what has been released.



标签: node.js v8