5

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?

Overv
  • 8,433
  • 2
  • 40
  • 70
  • Interesting issue, have no idea, but... have you tried chanigng nodejs version and/or verifying if any of [theese](https://github.com/joyent/node/search?q=leak&ref=cmdform&state=open&type=Issues) issues apply? – xjedam Mar 28 '14 at 15:03
  • I'm having the same issue with TCP sockets. – majidarif Feb 15 '15 at 22:58
  • 2
    Did you solve it? i'm having the same issue with einaros websockets. – shaharmor Feb 16 '15 at 22:04
  • @DeaglinG Nope, I ended up having a cronjob that restarts the process once every few hours. – Overv Feb 16 '15 at 23:54
  • Not sure if it will help, but i think its related to the closure of the websockets callbacks. you should try not using any variables from an upper score in the send/error callbacks of the send command. – shaharmor Feb 19 '15 at 08:16
  • This answer solved the problem for me http://stackoverflow.com/questions/30252905/nodejs-decrease-v8-garbage-collector-memory-usage – shoren Dec 03 '15 at 20:21
  • @shoren Not for me, I fixed the problem by no longer using Node.JS. – Overv Dec 03 '15 at 20:23

1 Answers1

0

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.

CharlieBrown
  • 4,143
  • 23
  • 24
  • Are you sure that would help me if the v8 heap usage itself is exactly the way it should be? – Overv Mar 28 '14 at 12:25