tags:

views:

198

answers:

2

Lets say I have an application that is going to listen on a particular TCP port for a connection. Is there a theoretical limit on the number of connections that can be handled in the same port?

Or is there only a practical limit based on the OS and other properties?

I've searched the Internet but couldn't find a conclusive answer.

Thanks

+2  A: 

In UNIX (Not Windows), an accepted socket consumes a file descriptor, so the limit is the number of open file descriptors allowed. The number of open file descriptors is a per-process limit with both a hard and a soft limit. See ulimit (2) for more information.

Note that if you close the socket, you free the file descriptor, so it can be used over again. The ulimit limit applies only to the number of simultaneous open file descriptors.

To specifically answer your question, there isn't a limit on the number of sockets a port can accept, only on the number that the process listening to the port can have open at the same time. If there were a limit, web servers, who listen on port 80, would have to be restarted more often.

jfawcett
+2  A: 

If the process limit (as shown by the ulimit command) is 1024, and you have not closed STDIN, STDOUT and STDERR and 100 file descriptors are used by items such as database connections and other file handles, than you will have 921 open connections available for simultaneous processing. This assumes that all connections are processed in parallel. These file descriptors will be reused once each connection is closed. The net result is that if your application handles the file descriptors correctly, the total number of connections between the start up and shutdown of the application, is infinite.

David Harris
i am more interested in windows.
ckv
In windows, the same principals apply but the max limit is actually dependent on the number of system resources available. Sockets on Windows are handles, which are a shared system resource.
jfawcett
ok thanks so in theory there is no such limit but practically there could be
ckv
@viswanathsan: FYI, I have supported a socket based application that was limited to 200 socket connections, processed up to 5 connections per second, about 100,000 connections each day and had at one point an uptime of about 500 days. (The server was rebooted because of a daylight saving time change.)
David Harris