Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Receiving UDP packets retains memory #2468

Closed
quirkey opened this issue Jan 5, 2012 · 4 comments
Closed

Receiving UDP packets retains memory #2468

quirkey opened this issue Jan 5, 2012 · 4 comments
Labels

Comments

@quirkey
Copy link

quirkey commented Jan 5, 2012

We recently tried to upgrade our node statsd instances to v0.6.6 (from v0.4.12) and quickly noticed that the process was growing indefinitely once it started receiving packets. We reverted and I've spent some time trying to track it down in the code. Eventually I narrowed it down to this simplified test case:

https://gist.github.com/5a83080df20211e8ff74

Even without doing anything with the received messages, 0.6.6 quickly grows in memory per-packet received. The real kicker is it doesnt release this memory even after a long period of 0 sent. This was not a problem in 0.4.

I've tested this on centos 6 and locally on OS X 10.7.2.

I couldn't find anything obvious in the dgram.js so I'm guessing its in the lower level.

@bnoordhuis
Copy link
Member

Thanks for the writeup. This issue is similar to #2349 in that there is no real memory leak, it just looks that way if you look at RSS only.

If you instrument the code in src/udp_wrap.cc, you'll see that every datagram eventually gets deleted. You can check it for yourself with valgrind --leak-check=full --show-reachable=yes. You'll get a lot of reported leaks (from "eternal" objects that grab memory at start-up) but nothing in the UDP code.

Regarding RSS, it's more visible with UDP than with TCP because Node uses a slab allocator for TCP but plain malloc/free for UDP. Switching over to slab allocation is a TODO.

@quirkey
Copy link
Author

quirkey commented Jan 5, 2012

Can you explain what changed between 0.4 and 0.6 here that would cause such a big diff?

@bnoordhuis
Copy link
Member

v0.4 uses a memory pool-based approach that doesn't quite translate to how v0.6 arranges things. If I have an hour to kill tonight, I'll add slab allocator support to UDP.

@mrb
Copy link

mrb commented Jan 5, 2012

FYI, statsd implementations looking to upgrade to v0.6 node will need this slab allocator for UDP as it is for TCP.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants