How to modify the maximum number of tcp connections on the windows server

When doing performance testing, if the system page being tested is simple and has good performance, this will result in insufficient tcp links on the press and cause the following errors:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\tcpip\Parameters\TcpTimedWaitDelay to 30
and HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\tcpip\Parameters\MaxUserPort to 65534
and rebooting the machine
See the readme.doc file for more information
The most introduced through Baidu search is to modify the two values of TimedWaitDelay and MaxUserPort. Among them, it is a relatively small point to modify TimedWaitDelay, which can be determined according to the actual situation.
At the same time, modify the value of MaxUserPort to be larger, but after the modification and restart the machine, the problem still exists. Check the information through multiple parties, and then modify some registry:
[HKEY_LOCAL_MACHINE \System \CurrentControlSet \Services \Tcpip \Parameters]
TcpNumConnections = 0x00fffffe (Default = 16,777,214)
The above registry information configures the maximum number of TCP connections allowed for a single machine, and the default is 16M. This value seems to be very large. This is not the only condition that limits the maximum number of connections. There are other conditions that limit the maximum number of TCP connections.
Maximum number of dynamic ports
When a TCP client connects to a server, the client must allocate a dynamic port. By default, the allocation range of this dynamic port is 1024-5000, which means that by default, the client can initiate up to 3977 Socket connections at the same time. We can modify the following registry to adjust the range of this dynamic port
[HKEY_LOCAL_MACHINE \System \CurrentControlSet \Services \Tcpip \Parameters]
MaxUserPort = 5000 (Default = 5000, Max = 65534)
Maximum number of TCB
The system allocates a TCP control block (TCP control block or TCB) for each TCP connection. This control block is used to buffer some parameters of the TCP connection. Each TCB needs to allocate a 0.5 KB pagepool and 0.5 KB Non-pagepool, which means In other words, each TCP connection will occupy 1KB of system memory.
The maximum number of TCBs in the system is determined by the following registry settings
[HKEY_LOCAL_MACHINE \System \CurrentControlSet \Services \Tcpip \Parameters]
MaxFreeTcbs = 2000 (Default = RAM dependent, but usual Pro = 1000, Srv=2000)
For non-Server version, the default value of MaxFreeTcbs is 1000 (more than 64M physical memory)
Server version, the default value for this is 2000.
In other words, by default, the Server version can establish and maintain up to 2000 TCP connections at the same time.
Maximum number of TCB Hash tables
TCB is managed by Hash table, the following registry setting determines the size of this Hash table
HKEY_LOCAL_MACHINE \System \CurrentControlSet \services \Tcpip \Parameters]
MaxHashTableSize = 512 (Default = 512, Range = 64-65536)
This value indicates the amount of pagepool memory allocated, that is, if MaxFreeTcbs = 1000, then the amount of pagepool memory is 500KB
Then MaxHashTableSize should be greater than 500. The larger the number, the higher the redundancy of the Hash table, and the less time it takes to allocate and find TCP connections each time. This value must be a power of 2, and the maximum is 65536.
MaxUserPort = 65534 (Decimal)
MaxHashTableSize = 65536 (Decimal)
MaxFreeTcbs = 16000 (Decimal)
Here we can see that MaxHashTableSize is configured to be 4 times larger than MaxFreeTcbs, which can greatly increase the speed of TCP establishment.