Maximum Number of Concurrent Connections on a Single Port (Socket) of Server

What is the theoretical maximum number of open TCP connections that a modern Linux box can have

A single listening port can accept more than one connection simultaneously.

There is a '64K' limit that is often cited, but that is per client per server port, and needs clarifying.

Each TCP/IP packet has basically four fields for addressing. These are:

source_ip source_port destination_ip destination_port
<----- client ------> <--------- server ------------>

Inside the TCP stack, these four fields are used as a compound key to match up packets to connections (e.g. file descriptors).

If a client has many connections to the same port on the same destination, then three of those fields will be the same - only source_port varies to differentiate the different connections. Ports are 16-bit numbers, therefore the maximum number of connections any given client can have to any given host port is 64K.

However, multiple clients can each have up to 64K connections to some server's port, and if the server has multiple ports or either is multi-homed then you can multiply that further.

So the real limit is file descriptors. Each individual socket connection is given a file descriptor, so the limit is really the number of file descriptors that the system has been configured to allow and resources to handle. The maximum limit is typically up over 300K, but is configurable e.g. with sysctl.

The realistic limits being boasted about for normal boxes are around 80K for example single threaded Jabber messaging servers.

Maximum number of Socket (for HTTP traffic) connections possible for a single machine

The connection is identified by Source address, Destination Address, Source port, Destination port. So if you fix the destination port to 80 (HTTP), the destination address to your server IP and the source address to your client IP, then, yes the number of contemporaneous connections cannot exceed the number of port range.

Theoretically your server can have more connections than the port range if it talks with multiple clients.

What is the maximum number of active connections a client can have to a server IP? (networking)

A port is 16 bits, so the absolute limit would be 216.

Of course, port 0 is not really ever used and ports 1 to 1023 are clearly reserved for servers. Plus, in most cases, you have a limited range of ports you can use to connect as a client. These are called ephemeral ports and are between 49152 and 65535.

The number 49152 is 0xC000. So you get the top quarter of the ports available to clients or 16384 ports (214). That's your limit as a client.

Note that memory is also required. More or less depending on your application but also the kernel needs enough memory to allocate so many ports. So you are more likely to run out of memory before you can allocate that many ports (unless, like me, you have a computer with 512Mb of RAM or more... then you'll have a hard time to stress the memory allocation in most cases).

In practical use, I've never run out of client ports. The main issue I run into is multiple applications trying to listen on the same port (i.e. two servers trying to listen on port 80, for example).

What is the theoretical maximum number of open TCP connections allowed on a Windows server

Based on an answer by a MSFT employee:

It depends on the edition, Web and Foundation editions have connection limits while Standard, Enterprise, and Datacenter do not.

Though as Harry mentions in another answer, there is a setting for open TCP connections that has a limit of a bit over 16M.

But while technically you could have a large amount of connections, there are practical issues that limit the amount:

  • each connection is identified by server address and port as well as client address and port. Theoretically even the number of connections two machines can have between them is very large, but usually the server uses a single port which limits the number. Also rarely a single client would open thousands of connections, but in NAT cases it may seem like it

  • the server can only handle a certain amount of data and packets per second, so a high speed data transfer or lots of small packets may cause the number to go down

  • the network hardware might not be able to handle all the traffic coming in

  • the server has to have memory allocated for each connection, which again limits the number

  • also what the server does is an important issue. Is it a realtime game server or a system delivering chess moves between people thinking their moves for 15 minutes at a time

What is the practical / hard limit on socket connections per server

Assuming you select a sensible architecture for your server then the limit will be memory and cpu related. IMHO you'll never reach the hard limit that Martin mentions :)

So, rather than worrying about a theoretical limit that you'll never hit you should, IMHO, be thinking about how you will design your application and how you will test it to determine the current maximum number of client connections that you can maintain for your application on given hardware. The important thing for me is to run your perf tests from Day 0 (see here for a blog posting where I explain this). Modern operating systems and hardware allow you to build very scalable systems but simple day to day coding and design mistakes can easily squander that scalability and so you simply MUST run perf tests all the time so that you know when you are building in road blocks to your performance. You simply cannot go back and fix these kind of mistakes at the end of the project.

As an aside, I ran some tests on Windows 2003 Server with a low spec VM and easily achieved more than 70,000 concurrent and active connections with a simple server based on an overlapped I/O (I/O completion port) based design. See this answer for more details.

My personal approach would be to get a shell of a server put together quickly using whatever technology you decide on (I favour unmanaged C++ using I/O Completion Ports and minimal threads), see this blog posting for more details. Then build a client or series of clients that can stress test the application and keep updating and running the test clients as you implement your server logic. You would expect to see a gradually declining curve of maximum concurrent clients as you add more complexity to your server; large drops in scalability should cause you to examine the latest check ins to look for unfortunate design decisions.

Maximum concurrent Socket.IO connections

This article may help you along the way: http://drewww.github.io/socket.io-benchmarking/

I wondered the same question, so I ended up writing a small test (using XHR-polling) to see when the connections started to fail (or fall behind). I found (in my case) that the sockets started acting up at around 1400-1800 concurrent connections.

This is a short gist I made, similar to the test I used: https://gist.github.com/jmyrland/5535279



Related Topics



Leave a reply



Submit