I am going to develop a TCP server application. I am on the "choose server" step. My TCP server is going to have 2000+ clients and one socket to each client.
Is there limit for amount of created sockets depending on the operating system? Which operating system permits more open sockets at a given time?
On the TCP level the tuple (source ip, source port, destination ip, destination port) must be unique for each simultaneous connection. That means a single client cannot open more than 65535 simultaneous connections to a single server. But a server can (theoretically) serve 65535 simultaneous connections per client.
@premktiw: Yes, multiple client sockets can be bound to the same local IP/port pair at the same time, if they are connected to different server IP/Port pairs so the tuples of local+remote pairs are unique.
(1) It is 1-65535, not 0-65535.
As part of the Windows EULA (on versions 7, 8, 8.1 & 10 as of publishing this KB article) the maximum device connection limit is 20 concurrent TCP/IP connections.
Yea there are limitations, but you'll probably never get close to them (connections is not the same as connecting or incomming connections, a connection is something that has happned and is established and that number is significantly higher than other states. @corsiKa gave a good quote on the number of connected sessions you can have.)
Here are some useful commands:
# Shows some general useful information,
ulimit -a
# if not, here are some other places to look
# maximum files:
cat /proc/sys/fs/file-max
# maximum filedescriptors:
cat /proc/sys/fs/file-nr
# maximum backlog of unaccepted clients:
cat /proc/sys/net/core/somaxconn
# And number of threads to run at once:
cat /proc/sys/kernel/threads-max
What limits how many open You->Them
connections is basically how many local ports you have availible and assigned as your pool, you can find this information in:
sysctl net.ipv4.ip_local_port_range
There's also a "buffert" on incoming ports that limits how many clients you can simultaionsly have connecting to you, find this information here:
sysctl net.ipv4.tcp_max_syn_backlog
sysctl net.core.netdev_max_backlog
Also, find a complete description here: Increasing the maximum number of tcp/ip connections in linux
A 2Gb Windows server should support 16,000 - so that's pretty decent, since 2Gb is rather cheap:
On Windows NT, Windows 2000, Windows XP and Windows 2003 Server, sockets are allocated from the non-paged memory pool so the actual number of sockets that can be created system-wide depends on the amount of physical memory that is installed. The non-paged memory pool is 1/8th the size of physical RAM, with a maximum of 128Mb on Windows NT and 256Mb on Windows 2000 and later platforms. The theoretical maximum for Windows NT servers is approximately 12,000 sockets, and 25,000 for Windows 2000 and later versions. In practical terms, it is safe to estimate that the Windows Server platforms can allocate approximately 4,000 sockets for every 512Mb of physical memory. For Windows NT, this means that the maximum number of sockets will be around 8,000 for a system with 1Gb or more of RAM. For Windows 2000 and later versions, the maximum number of sockets is around 16,000 for a system with 2Gb or more of RAM.
It appears free BSD can have over 1 million, and that was over 2 years ago:
Over the past few months we have been making a lot of improvements to our servers to increase the performance, uptime and scalability. Today we have tuned some knobs, shifted some traffic around and achieved 1 million established tcp sessions on a single machine (and with memory and cpu to spare!)
$ netstat -an | grep -c EST
1016313
So somewhere between 10^5 and 10^7 sockets, ish.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With