Solving various limitations on the maximum number of connections to highly concurrent sockets under Linux
When running highly concurrent TCP programs on linux as a server system, it is common that connections cannot be established after a certain number of connections have been established
I am at work, testing high concurrency tcp program (GPS server-side program), many times test, found that each time the connection is established to about 3800, can no longer establish tcp connection, the most total Internet search, to solve the problem of connection limits, recorded here, to facilitate future work continue to use, although the reference blog post in the content of a little more, the text described in the content is not very clear, but summarized, according to the following steps can be operated (my image, after this method of setting, test the establishment of more than 8000 connections also did not appear what error):.
As a first step, modify the /etc/security/limits.conf file by adding the following line (* refers to the system user name) to modify the Linux system's soft and hard limits on the number of files a user can open.
* soft nofile 20000
* hard nofile 20000
Step 2 Modify the /etc/pam.d/login file by adding the following line to the file.
session required /lib/security/pam_limits.so
If it's a 64bit system, it should be for :
session required /lib64/security/pam_limits.so
In the third step, modify the /etc/sysctl.conf file by adding the following line to the file (clear from the original content of the file) (modifying the network kernel's restrictions on TCP connections in question).