3

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

But what is the default buffer size? I assume it's whatever is configured in /proc/sys/net/ipv4/tcp_rmem and tcp_wmem (assuming Linux)...

I'm trying to do some basic capacity planning. If I have a VPS with 512 MB RAM, and I assume the OS et al will use ~ 100MB, my app has ~ 400MB for whatever it wants to do. If each connected client (regular old TCP/IP socket) requires say 8KB (4KB read, 4KB write) by default, I have capacity for 400MB / 8KB = ~ 50000 clients.

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

MPelletier
  • 16,256
  • 15
  • 86
  • 137
horton
  • 53
  • 5
  • 1
    I really don't think you need to worry about the specifics here. You're in the right ballpark, and whether the exact number is 25,000 or 40,000 or 60,000, once you hit that number of ___simultaneous___ users, you'll be able to afford a bit more memory in your VPS :P Also, at those numbers you start running into issues with the OS having too many connections open –  May 16 '11 at 19:21
  • Yes of course true. I'm just trying to get some baseline number of max connections / host. My plan is to have a number of these hosts and direct clients to the least loaded host when the client wants to connect to the "cluster". But I'll need to know when I need more client-facing hosts. Sure load average and other metrics are needed but my app is not very CPU bound so the dominant factor in deciding when and how to grow is RAM. Thanks! – horton May 16 '11 at 19:25

1 Answers1

1

I don't know off the top of my head and it probably varies from platform to platform but here's how 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 cat a large file (like an ISO) through 'nc localhost $port' using the port number that the script spits out when it starts up, and watch the output to see what the largest chunk size is. On my OS X machine, it looks like the largest buffer is 40960 bytes, but it might be different on yours.

clee
  • 10,943
  • 6
  • 36
  • 28