File descriptor limits
Maximum number of TCP connections to the serverWhat is the maximum number of connections that a server-side TCP network application can theoretically support? The server IP and server Port are fixed (that is, the listening TCP program), so the theoretical upper limit of the number of connections depends on the number of combinations of (client IP * client Port). Of course, if the server program listens to all port numbers from 1 to 65535, the theoretical upper limit of the number of connections becomes: Of course, in reality, this upper limit cannot be reached for three reasons:
In summary, the maximum number of connections that a server-side TCP network application can support mainly depends on its memory size (assuming that the kernel parameters have been tuned). How to test?How to test the scenario of millions of connections when the test equipment is insufficient? The core idea is to break through the TCP four-tuple limitation.
too many open filesFirst, let's look at a "classic problem" in a high-concurrency scenario: too many open files. The root cause of this problem is that a large number of network (file) connections are opened in a short period of time, exceeding the operating system's limit on the number of file descriptors allowed to be opened by a single process. What parameters need to be tuned if a single machine is to support 1 million connections? SolutionSoft open files is a Linux system parameter that affects the maximum number of file handles that a single process in the system can open. This means that a single process can maintain a maximum of 1024 network (such as TCP) connections at the same time. You can increase this parameter to support a larger number of network connections. (1) Temporary Adjustment Only valid in the current session (terminal), invalid after exiting or restarting (2) Permanent settings Modify the configuration file /etc/security/limits.conf: Run the sysctl -p command to make the settings effective. The settings will still be effective after reboot. (3) Other settings The number of file descriptors opened by a single process cannot exceed the number of file descriptors of all processes in the operating system (/proc/sys/fs/file-max), so the corresponding value needs to be modified: Run the sysctl -p command to make the settings effective. The settings will still be effective after reboot. (4) View configuration Linux kernel parameter tuningTo support 1 million connections on a single machine, in addition to tuning the file descriptor number parameter just mentioned, you also need to tune some kernel parameters. Open the system configuration file /etc/sysctl.conf and add (or modify) the following configuration data. The parameter names and their functions are written in the comments. Run the sysctl -p command to make the settings effective. The settings will still be effective after reboot. PrecautionsIf the system has used the parameter net.ipv4.tcp_syncookies, the parameter net.ipv4.tcp_max_syn_backlog will automatically become invalid. Client ParametersWhen the server acts as a "client role" (such as a proxy server), each connection needs to be assigned a temporary port number when connecting to the backend server. |
When it comes to network security and performance...
[[280757]] Introduction As a post-80s generation,...
DCIM (Data Center Infrastructure Management) is a...
0. Summary of the previous situation During a fli...
From the 1G analog communication era to the 4G mo...
The operator called to inform me that the package...
Gary Sevounts, Aryaka's chief marketing offic...
WiFi Wi-Fi (Wireless Fidelity) is a wireless LAN ...
Starting with Bitcoin, the decentralized and data...
spinservers has sent the latest 2023 US Labor Day...
As digital transformation progresses and cloud-ne...
Sometimes I hear friends ask such questions: My r...
After the Chinese New Year, HostKvm sent a specia...
[51CTO.com original article] As an indispensable ...