-
Notifications
You must be signed in to change notification settings - Fork 505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is nan v2.0.0 leaking memory? #389
Comments
Further testing shows that destructor ~MyObject is called when |
What if you try Node 0.12? Could be the |
Switching to |
I'm quite confident that Persistent I mentioned is leaking for < 0.12, I'll fix it by reimplementing the whole class tomorrow. I don't know about the rest. |
Try #392 and see if that helps with Node 0.10. |
The following was performed with both Node.js v0.10.40 and v0.12.7:
Here's the output when
Here's the output when
The leak is still there in Node.js v0.10.40 and v0.12.7 has a new issue. |
There, I've added a commit which should take care of the problems. Thanks for reproducible tests. |
The epoll module was also leaking. Here's a summary of some test results (hopefully there are no mistakes here)
The leak in nan v2.0.0 with v0.10.40 (test no. 5) is no longer there if the kkoopa nan memleak branch is used (test no. 6). However, there appears to be a new source of leaks. The epoll nan2 branch doesn't leak with nan v2.0.0 and v0.12.7 (test no. 3), but it does leak with the kkoopa nan memleak branch and v0.12.7 (test no. 4). I won't have access to a development computer for the next few weeks. |
@bnoordhuis Any suggestions? I can't think of anything more that could be leaking. |
@fivdi What do you base the leaking on in tests 4 and 8? I'm seeing the same memory growth with both NAN 2.0.0 and NAN 1.8.4. In the nan2 branch you have also increased the count from 1e6 to 1e9, making it run longer and consume more memory. |
The leaking in tests 4 and 8 is based on the fact that memory usage in test 3 is extremely stable and doesn't increase on the test machine. In test 4 memory usage keeps increasing and increasing and then there is swapping. I didn't have time to wait and see if there was a bad_alloc error with test 4 as I had to leave for the airport. The only difference between tests 3 and 4 is the branch of nan being used. The count was increased from 1e6 to 1e9 to test longer. |
Yeah, the memory usage is increasing, but I don't know why. The output from valgrind is useless. It reports a lot as definitely leaking, but the memory does get deallocated upoon garbage collection, yet the memory usage increases. |
I'm not sure if everything that valgrind claims is a leak is really a leak when V8 is being used. AFAIK, when V8 knows that the process is about to terminate, destructors are purposely not called. I'm afraid I don't know why memory usage increases either. |
I've also seen a production memory leak. Downgrading [email protected] to [email protected] fixes my memory leak. It leaks about 200mbs/hr for me. |
Preliminary finding: it doesn't look like a persistent handle leak. I see the number of persistent objects go up and down over time, like you'd expect in a GC-managed environment. Destructors are called properly, too. |
Same as I saw. Diffing snapshots from heapdump also shows nothing, but growth does happen when monitoring the process with top. |
Had some more time to look into it. I can't reproduce the std::bad_alloc exception with v3.0.0. RSS and heap total stabilize after a while, heap used fluctuates but that's the expected rise-then-drop saw wave of the GC at work. |
Did you try 0.12.7? That's what I used. With NAN 1.8.4 memory usage of Node stabilizes at 5 % of max, but with 2.0.1 it keeps growing past 20 % and does not seem to end. On August 5, 2015 10:07:43 PM EEST, Ben Noordhuis [email protected] wrote:
|
@kkoopa what is 2.0.1? master? If so, I wouldn't expect to see any problems with v0.12.7. This would be almost the same as tests 1 and 3 in the table above. With v0.12.7, I'd only expect to see issues with the constellation from test 4. |
No, the memleak branch. |
I just tried with io.js 3.0 and the memleak branch. Memory grew until about 80 % usage and seemed to hover fairly stable around there. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7823 kkoopa 20 0 1847916 801952 2988 R 100.1 79.9 3:56.78 node VIRT grew constantly though. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7823 kkoopa 20 0 2423684 818144 1092 R 99.8 81.5 6:48.21 node But something is still strange, as Node 0.12.7 would stay at 5 % with NAN 1.8.4 but would exceed that with NAN 2.0.0. Why does a bunch of memory get allocated but never used? |
The figures I saw with TOP were similar. RES was 1.6GB rather than 800MB but that was also about 80% on the test machine, if I remember correctly. It stayed at about 1.6GB and VIRT kept increasing and increasing. The increase in VIRT resulted in trashing and %CPU dropped to way below 100% and everything got really really slow. My interpretation is not that memory usage (RES/RAM) hovers at 80% and remains stable, but that it's stuck at 80% because no more memory is available. The process wants more RAM, but it's not getting it. Instead, it gets VIRTual memory on the hard disk, starts trashing, and gets really really slow. |
You may be right about the analysis. Assuming it is not handles that are leaking, I searched for references to What is left that could be leaking? |
@fivdi What happens when you pass |
It just keeps growing as before. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8349 kkoopa 20 0 1147904 327176 7852 R 94.3 32.6 2:20.59 node It's the heap of the node process that grows at an alarming rate, independent of the js heap. |
I ran 0.12.7 with memwatch now. JS heap is fine, but process heap grows unfettered. 2000000 instances created and events detected { num_full_gc: 20,
num_inc_gc: 60,
heap_compactions: 20,
usage_trend: 0,
estimated_base: 4079950,
current_base: 4083424,
min: 3641096,
max: 4462424 } |
Made some progress. Turns out the leak only happens when using the new |
That's good news :) |
And it seems to be either because of the |
Further investigation shows that it is something with SetWeak and the weak callback that leaks. |
I still cannot wrap my head around why this acts in such a strange way. Localizing the problem only made it weirder. |
ref: s-a/iron-node#44 |
nan 2.x.x support currently blocks on nodejs/nan#389. Until then, don’t test iojs v3.0.0 (for which the build fails with nan 1.x.x)
Fixed in 98d38c1 |
@kkoopa good work! memory usage is nice and stable now. |
I'm in the process of migrating the epoll module from nan v1.8.4 to nan v2.0.0. Everything is looking ok except for memory usage. There's an epoll test called brute-force-leak-check.js. This test is used to create millions of objects and while it's running the memory usage is observed to see if everything looks ok. With
Node.js v0.10.40
andnan v1.8.4
memory usage is extremely stable and everything looks good. WithNode.js v0.10.40
andnan v2.0.0
memory usage keeps increasing and eventually the test will terminate with:I can't figure out where the problem is and wrote the following test to see if the problem is in the
epoll
code or perhaps somewhere else:This test is similar to the
epoll
brute-force-leak-check
but creates millions ofnan
MyObject
instances instead (objectwraphandle.cpp).If this test is placed in the
nan
test\js
folder and run from there, the same issue can be seen. WithNode.js v0.10.40
andnan v1.8.4
memory usage is extremely stable and everything looks good. WithNode.js v0.10.40
andnan v2.0.0
memory usage keeps increasing and eventually the test will terminate after throwing an instance ofstd::bad_alloc
.Unfortunately, it may take a long time for
std::bad_alloc
to be thrown, even on a machine with only 2GB of RAM, but the constant increase in memory usage is immediately visible. This is the followed by swapping to the hard-disk after a relatively short period of time.Additional information:
Is the test a little too stupid/synthetic or is there an issue somewhere?
The text was updated successfully, but these errors were encountered: