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. |
Here is some information about Turkey VPS. The Ba...
Beijing, March 21, 2017 – Today, F5 Networks anno...
【51CTO.com Quick Translation】 Artificial intellig...
[51CTO.com original article] Summer is coming to ...
Strategy Analytics released a report today saying...
The tribe has shared information about 80VPS many...
[[404856]] 618 is here, and during the annual sho...
RackNerd has launched two more FLASH SALE package...
[[354426]] 【51CTO.com original article】 HTTP Begi...
[[255453]] The Haidilao indecent video incide...
According to the Ministry of Industry and Informa...
[[238041]] Image source: Visual China IPv4. What ...
As a TV series that has been rebroadcast thousand...
When you use WiFi at home to surf the Internet, i...
Education is an eternal research topic, and its i...