How much memory does the inet stream socket use in Node.js?

Of course, data can be buffered and grow if the client is too slow to read the server writes [1].

But what is the default buffer size? I assume that it is configured in / proc / sys / net / ipv 4 / tcp_rmem and tcp_wmem (assuming Linux) ...

I am trying to do basic capacity planning. If I have a VPS with 512 MB of RAM, and I assume that OS et al will use ~ 100 MB, my application has ~ 400 MB for what it wants to do. If each connected client (a regular old TCP / IP socket) requires, by default, 8 KB (read 4 KB, write 4 KB), I have a capacity for 400 MB / 8 KB = ~ 50,000 clients.

[1] http://nodejs.org/docs/v0.4.7/api/all.html#socket.bufferSize

+3
source share
1 answer

I don’t know from head to toe, and this probably varies from platform to platform, but here, as you can find out!

Use this code:

var net = require('net');

net.createServer(function (socket) {
    socket.on('data', function(data) {
      console.log('chunk length: ' + data.length);
    });
}).listen(function() {
    console.log("Server listening on %j", this.address());
});

And then quote the large file (for example, ISO) through "nc localhost $ port", using the port number that the script will sleep when it starts, and look at the result to see what size is the largest block. On my OS X computer, it looks like the largest buffer - 40,960 bytes, but it may be different on yours.

+1
source

All Articles