开发者

What limits the number of connections for a TCP port?

开发者 https://www.devze.com 2022-12-12 21:31 出处:网络
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?

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 co开发者_高级运维uldn't find a conclusive answer.

Thanks


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消