Mohsen Shakiba
Mohsen Shakiba

Reputation: 1872

socket - maximum limit of active sockets

I'm using node.js with ws(a socket library) to handle sockets.
and I've read this link that claims any VPS machine can have up to 64K client per port. now the question is, how many active sockets can I have on my linux VPS?
is there a theoretical limit to how many open sockets can a linux VPS handle?
and what is the bottle neck? is it RAM? or bandwidth?

Upvotes: 1

Views: 1768

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328840

When computer A connects to B, both need to have a single socket allocated. When the server accepts the connection, it copies the clients IP address and port into a new connection. This means that now the next client can connect on the same socket. You need one file descriptor on the server for this operation, so the limit is the number of file descriptors per process which you can check with the ulimit command.

A client needs a socket to initiate a connection. Each socket is identified by a 16 bit integer. That means you can have at most 64K sockets on the client side.

Since the server socket is "released" after the connection is established, it can accept more than 64K connections.

In theory, you can fill your server RAM with file descriptors without a problem. In practice, connections are made to exchange data. So the real bottleneck is usually bandwidth.

Upvotes: 2

Related Questions