Test conclusion on the relationship between 65535 and the number of TCP connections

First, the conclusion:

  • Can only maintain a maximum of 65535 TCP connections on a host?

    • The client is like this, the server is not
  • Does it matter

    • .There are relationships
      • For the client

        • For the client, there is only 65535, because according to the TCP quadruple sport, the sport has only 16 bits, so (2 ^ 16) -1 is 65535. That is, there are a maximum of 65535 available ports, here only talk about long links, not including SOCK_REUSEOPT
        • However, it cannot be said that a client can maintain 65535 connections to the same server because
        1. Below 1024, occupied by the system
        2. The local_port_range parameter controls the available port range
          sctl -a | grep port_rangenet.ipv4.ip_local_port_range = 50000 65000 ----- means that 50000 ~ 65000 ports are available.
          You can expand the range by modifying ip_local_port_range, but it can only reach 65535
      • . For the server

        • The 65535 limit is for a single client IP link
        • Adjust MAX OPEN FILE to keep more connections
        • Adjust ip_local_port_range to support a larger port range (but there should be no clients that need to establish so many ports?)

Error code encountered:

  • Cannot assign requested address.
    • In fact, the port range is insufficient
  • too many open files (too many open files)
    • Modify the maximum number of openings

test environment:

  • 5 ubuntu 2G 2U, one of which is SERVER

Test Results:

  • Because the MAX OPEN FILE I set at that time was 102400, and the maximum test was about 102100 long links (ESTABLISHED state), and they were not all equal to 102400, so some should be occupied by the system

Test code
Below is the address of the test code, modify the above two parameters, use two machines to test
https://gist.github.com/lisqorz/165204c1703b3cad325231ecbade3876

Further reading

Those who are interested in understanding the quadruple can read the following article
https://www.cnblogs.com/ouzi/archive/2012/10/29/2745430.html

If you are interested in the operation of the descriptor, you can see this

https://blog.csdn.net/u011436427/article/details/103215882

Guess you like

Origin www.cnblogs.com/lisq/p/12747657.html