2
votes

I'm using node v4.2.1 with socket.io (I have tested even with websocket/ws getting "better" result, but still not enough). At the moment there are few opened connections (hundreads) and the usage percentage of memory is 38% (I'm running on a AWS t2.small Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-48-generic x86_64)).

The server code is embarrising simple (just for test):

... declaration ...
io.on('connection', function(socket){
   socket.send("hi");
});

As far as the client code is concerned, I'm using the corresponding socket.io version. How is it possible that sockets occupy all that space in memory?

Moreover, I'm following this post:

http://www.jayway.com/2015/04/13/600k-concurrent-websocket-connections-on-aws-using-node-js/

and I run the server with --expose-gc flag but seems doesn't working (Every 30 seconds I force the garbage collector global.gc), any guess?

1

1 Answers

0
votes

nodejs GC is mostly lazy, eating memory until it hits it's limit of 1.4Gb. In heavy load app it's normal to see a pattern where node process goes up to ~1.4Gb and then fallback to 200Mb.

GC is lazy because it's synchronous (blocking the loop, stopping the full process, bad stuff...).

It's configurable* with --max-old-space-size here with 800Mb.

node --max-old-space-size=800 app.js

In order to decrease (or increase) this limit.

  • --max-old-space-size actually configure the biggest memory space of node, wich is around 1400 by default, not the GC per say. But when the old space size hit it's limit, it trigger a full GC.