Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many TCP sockets can I open at once? [duplicate]

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?

like image 725
thehilmisu Avatar asked Feb 25 '14 20:02

thehilmisu


People also ask

How many TCP ports can be open at the same 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.

Can you open multiple sockets on the same port?

@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.

How many TCP connection can be created?

(1) It is 1-65535, not 0-65535.

How many TCP connections can Windows 10 handle?

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.


2 Answers

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

like image 100
Torxed Avatar answered Oct 24 '22 16:10

Torxed


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.

like image 34
corsiKa Avatar answered Oct 24 '22 18:10

corsiKa