We tried to deploy a small NodeJS application using Socket.IO and ran into a problem where the application's heap size remains fairly acceptable, the total usable memory (rss) creeps up to over 2 GB after about 2 hours, and continues to grow.
To make sure that the problem is not in our code, we deployed the barebones application without special logic, except for Socket IO initialization. We faced the same production traffic and experienced the same problem.
Every 10 seconds, we output the following data: rss memory usage, total heap count, heap count and number of connections. Here's a sample output:
523898880 199490816 123040352 2001 537059328 209774080 163828336 2011 538578944 206714368 150879848 2031 535252992 199514880 156743280 2041 542162944 200522752 145077944 2039 539652096 195387136 129486792 2055 551006208 206726400 170918304 2070 553254912 205706496 156447496 2071 550584320 198482944 154005496 2076 564363264 209810176 140442920 2095 561176576 201578752 123214232 2118 562487296 200546816 110638376 2112 572096512 206714368 162713240 2133 569552896 200546816 147439016 2121 577777664 205682432 136653448 2115 582496256 207770368 121204056 2133 582909952 205706496 115449888 2153 597364736 215989760 164582600 2158 590491648 204686592 148962008 2158 598315008 209810176 137608840 2164 598249472 205718528 123472944 2188 607158272 211898112 160187496 2168 609869824 210866176 154986472 2161 618110976 214969856 142425488 2180 615014400 207782400 119745816 2188 623575040 214981888 163602944 2180 624717824 210842112 147051160 2189 627556352 210866176 142542800 2191 636477440 216013824 129968776 2203 643809280 221149440 162858408 2219 644407296 217057792 154994536 2224 642068480 211922176 141626008 2240 649084928 214969856 123126792 2267 662454272 224233216 166539024 2272 659439616 217045760 162742688 2258 662867968 217057792 137425392 2266 667013120 218065664 119616592 2261 673230848 220129536 172101080 2272 677904384 220129536 149771776 2267 676691968 217045760 129936448 2267 674639872 211898112 125941816 2277 689025024 223225344 163745856 2274 689991680 219109632 151478936 2282 698601472 225301248 137102712 2298 706170880 229428992 171321288 2306 705675264 224257280 160088496 2303 701198336 217033728 149326384 2313 701833216 216013824 129806072 2314 718053376 227365120 184078288 2335 718950400 223225344 157977312 2333 717037568 218065664 146137456 2354 714428416 210890240 136566344 2381
As you can see, over a fairly short period of time, total memory usage increased by 200 mb, although the number of connections increased by only 400. The heap usage remained approximately the same, a little more, to take into account the higher number of connections.
We are working on Debian Wheezy on a 64-bit version. NodeJS version is 0.10.29, and Socket IO version is 1.0.6. The code we use is:
var http = require('http'), io = require('socket.io'); var app = http.createServer(); var server = io(app); app.listen(80); var connections = 0; server.on('connection', function(socket) { connections++; socket.on('disconnect', function() { connections--; }); }); setInterval(function() { var mem = process.memoryUsage(); console.log(mem.rss + ' ' + mem.heapTotal + ' ' + mem.heapUsed + ' ' + connections); }, 10000);
Is there a way to find out why Node uses so much memory in general, or in some way, to see what happens on the outside of the heap, in order to try to find a memory leak? We have already tried all the usual tricks to test the use of the heap and did not find anything, but did not expect it, since the problem is not related to memory on the heap.