Various restrictions on the maximum number of connections to a high-concurrency socket under linux (remove IO limit)

Source: Internet
Author: User

Linux as a server system, when running high concurrent TCP programs, usually there will be a certain number of connections established after the connection can not be established

I am at work, testing high concurrent TCP program (GPS server-side program), multiple tests, found each connection established to 3800 or so, can no longer establish a TCP connection, the most total Internet search, reference: http://blog.csdn.net/guowake/article/ details/6615728 solve the connection limitations, recorded here, convenient for future work continue to use, although the reference blog post content a bit more, the content described in the text is not clear, but summarized down, as follows a few steps can be (i image, after this method is set, Test to establish a connection more than 8,000 when there are no errors):

    • The first step, modify the /etc/security/limits.conf file, add the following line in the file (* Refer to the System user name), modify the Linux system on the user's number of open files soft limit and hard limit :

    * Soft Nofile 20000

* Hard Nofile 20000

    • In the second step, modify the /etc/pam.d/login file to add the following line to the file:

    Session required/lib/security/pam_limits.so

    If it is a 64bit system, it should be:
Session required/lib64/security/pam_limits.so

    • In the third step, modify the /etc/sysctl.conf file to add the following line in the file (clear the original contents of the file) ( modify the network kernel restrictions on TCP connections ):
Net.ipv4.ip_local_port_range =1024x768 65535Net.core.rmem_max=16777216Net.core.wmem_max=16777216Net.ipv4.tcp_rmem=4096 87380 16777216Net.ipv4.tcp_wmem=4096 65536 16777216Net.ipv4.tcp_fin_timeout=Tennet.ipv4.tcp_tw_recycle=1Net.ipv4.tcp_timestamps=0net.ipv4.tcp_window_scaling=0Net.ipv4.tcp_sack=0Net.core.netdev_max_backlog=30000Net.ipv4.tcp_no_metrics_save=1Net.core.somaxconn=262144net.ipv4.tcp_syncookies=0Net.ipv4.tcp_max_orphans=262144Net.ipv4.tcp_max_syn_backlog=262144net.ipv4.tcp_synack_retries=2net.ipv4.tcp_syn_retries=2

    • Fourth step, execute the following command (to make the above settings effective):

    

/sbin/sysctl-p/etc/sysctl.conf/sbin/sysctl-w net.ipv4.route.flush=1

    • Fifth step, execute the following command (Linux system optimized network must be high to allow the number of open files to support large concurrency, default 1024 is far from enough ):

 

65536 >>/etc/65536 >>/root/65536

    • Sixth step, restart the machine.

Various restrictions on the maximum number of connections to a high-concurrency socket under linux (remove IO limit)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.