-
Notifications
You must be signed in to change notification settings - Fork 7.3k
RSS memory leak on highload #4217
Comments
I believe we're seeing the same error. Thanks @baryshev for your thorough testing and debugging! |
I see no memory leaks with your example. You are however buffering up a lot of data, which explains the growing RSS. I've said it before and I'll say it again: RSS is an extremely poor metric for determining memory leaks. malloc implementations are very reluctant to return memory to the system even under ideal circumstances (i.e. no heap fragmentation). Here is a gist that demonstrates that. |
@bnoordhuis Do you know of any tool/technique to see what are these buffers that are being allocated and how we can hopefully reduce their amount? |
@superfeedr You can use something node-inspector or node-heapdump to create and inspect heap snapshots. Regarding the test case (which I'll post here for the sake of posterity): var server = net.createServer(function (socket) {
socket.on('data', function() {
setTimeout(function() {
for (var i = 0; i < 100000; i++) {
var d = new Date();
socket.write(d.toString());
}
}, 10);
});
}); It writes data to the socket without checking the return value of write(). The core logic should be rewritten to something like this: var i = 1e5;
function f() {
for (; i > 0; --i)
if (socket.write(d.toString()) === false) // the strict check is not optional
return socket.on('drain', f);
}
f(); |
@bnoordhuis But wait, I thought Buffers were outside of the heap? |
Yes, but as of commit 6a128e0 (v0.8.12 and up) they're reported properly in heap snapshots. |
Brilliant! Back to exploration. Thanks for the precious help. |
Indeed, but you can find out their total size with the statistics extension:
|
@bnoordhuis how do i get access to that extension? I tried the command line above, and node tells me it doesn't recognize this flag --track_gc_object_stats. I tried this on 0.8.18 and 0.8.14. Thanks! node --track_gc_object_stats -p -e 'Buffer(10_1024_1024); getV8Statistics();' Buffer(10_1024_1024); getV8Statistics(); |
@spollack It's only available in the master branch, the V8 version in v0.8 is too old. |
@bnoordhuis my rss is increasing, but Before gc():
After gc():
heap dump file is around 250mb, but chrome says that it is only 5.1mb. What am I missing? My app processes around 20m simple requests per day and becomes less responsible (3ms on the first day -> up to 500ms on the third day). I don't use compiled modules, only redis and empty-gif. node.js 0.10.10 |
@bobrik dead thread probably won't get you many responses. i'd say throw this on the mailing list. and some code is going to much more helpful. |
@superfeedr Hi. It's pretty late, but were you able to figure out the reason? I'm facing this behavior in one of my apps as well:
|
RSS memory doesn't release after doing some intensive tasks (highload).
My environment
How to reproduce leak
node server.js
.node client.js
.node server.js
rise up to 250-300Mb (or more).client.js
and wait some time to giveserver.js
time to complete all tasks.client.js
for a short time again, to get GC ofserver.js
work.Expected result
RSS memory will be released as well as a heap memory and will be comparable with initial values.
Actual result
Heap memory released successfully, but RSS memory not.
My results:
Before test:
After test:
Related discussions
The text was updated successfully, but these errors were encountered: