Windows limitation on number of simultaneously opened sockets/connections per machine

后端 未结 4 1739
青春惊慌失措
青春惊慌失措 2021-01-03 06:04

Let\'s say I have Windows 7 with one real network interface and few loopback interfaces. I have IOCP enabled server that accepts connections from clients. I\'m trying to sim

相关标签:
4条回答
  • 2021-01-03 06:08

    I've developed a load testing tool.

    Running on Windows 10/16G RAM, it could created 60,000 connections with server successfully.

    But when try to create more connections, the tool will report "socket WinError 10055 No Buffer Space Available" soon.

    Accord to this article, I think the limitation is the overall socket buffer size of whole OS, not the number of opened file.

    0 讨论(0)
  • 2021-01-03 06:10

    In your code example, you are calling Bind(bindEndpoint), but you do not show how bindEndpoint is defined. Check that :

    • Your system actually has multiple IP addresses (loopback does not count)
    • You are actually setting the IP Address of the endpoint to an IP address (not loopback)
    • The binds are being spread across multiple IP addresses

    The loopback address does not count because many systems treat it specially for routing and binding purposes. So binding to ports in loopback may be sucking up the ports across all addresses the same as if you were binding to INADDR_ANY (0.0.0.0).

    0 讨论(0)
  • 2021-01-03 06:16

    I have found on some Microsoft page that:

    ... HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\MaxUserPort registry subkey is defined as the maximum port up to which ports may be allocated for wildcard binds. The value of the MaxUserPort registry entry defines the dynamic port range...

    So, if I force the endpoint to use a certain port, e.g.

    IPEndPoint bindEndpoint = new IPEndPoint(IPAddress.Parse(args[0]), 54321);
    

    Then I can open more than 64K simultaneous sockets in the system.

    0 讨论(0)
  • 2021-01-03 06:17

    Both TCP and UDP use an unsigned 16-bit integer to designate port number. I don't imagine any implementation in any operating system is going to be able to open more than 65535 sockets per bound address at best. Additionally, I wouldn't be surprised if Windows doesn't implement fully isolated state tables for each adapter or each bound address but instead relies on a global state table. If that is the case, it would be a Windows network architecture limit instead of a soft, configurable limit.

    0 讨论(0)
提交回复
热议问题