Number of concurrent TCP connections on a single server "Linux"

Source: Internet
Author: User
Tags ip number

Number of concurrent TCP connections on a single server

Question: How many TCP concurrent connections can a single server support?

1. File Descriptor Restrictions:
For a server, each TCP connection consumes a file descriptor, and once the file descriptor is used, the error that the new connection comes back to us is "Socket/file:can ' t open so many files"

At this point, you need to understand the limit that the operating system can open the maximum number of files.

Process limit (user limit):
Perform ulimit-n output 1024, which means that you can open up to 1024 files for a process, so you will be able to use this default configuration up to thousands of TCP connections.

Temporary modification: ulimit-n 1000000, but this temporary modification is only valid for the currently logged in user environment, the system restart or user exit will be invalidated.

Permanent entry: Modify the/etc/security/limits.conf file:

                *    Soft    nofile    1000000                *    hard    nofile     1000000              1000000 >>/etc/rc.local

Global Restrictions:
Executive Cat/proc/sys/fs/file-nr
1216 0 187612
(1) 1216: Number of file descriptors already assigned
(2) 0: The number of file descriptors that have been allocated but not used, meaning that the kernel allocates 1216 and then 1216 are exhausted, so "the number of handles allocated but not used" is 0
(3) 187612: Maximum number of file handles
Note: The value of the second entry in the kernel2.6 version is always 0, which is not an error, it actually means that the file descriptor that has been assigned is not a waste of
be used.

You can adjust the size of the last value by defining Fs.file-max = 1000000来 in/etc/sysctl.conf

2. Port number Range limit:
Operating system port number 1024 The following is the system reserved, from 1024-65535 is used by the user, because there is no TCP connection to occupy a port number, so we can use up to
More than 60,000 concurrent connections, which is the understanding of the client.
Analysis:
(1) How do I identify a TCP connection? The system uses a 4-tuple to identify a TCP connection: (Local ip,local port,remote IP, remote port) for accept, the sock of the accept does not account for the new port the first local IP, the local port on behalf of the customer IP address and port number of the end.
And we as a server actually just use bind this one port
Description Port 65535 is not a limitation of concurrency.
(2) Server maximum number of TCP connections: server is usually fixed on a local port for listening, waiting for client connection requests. Regardless of address reuse, even if multiple IP
The local listening port is also exclusive. Therefore, only the remote IP and remote ports in the server-side TCP connection 4-tuple are mutable, so the maximum TCP connection is
Client IP number * Client port number. For IPv4, regardless of the IP address and other factors, the maximum TCP connection is approximately 2 of the 32-time (IP number) * 2 of the 16-square (port number)
That is, server side: The maximum number of TCP connections for a single machine is approximately 2 48.


Issue 1: View file descriptor use Lsof to see the number of handles and the/PROC/SYS/FS/FILE-NR value is not the same, why?

        [Email protected] ~]# Lsof | WC-L        710        ~]#!  Cat        /proc/sys/fs/file-nr        416    0    1000000

Answer: A file can be opened by more than one process, lsof listed is the file opened by each process, so the value of lsof is larger than File-nr is normal.

Question 2: How good is the file handle set?

To see how many handles are:

        [Email protected] ~]# cat/proc/sys/fs/file-nr        832    0    97321                  ~]# cat/proc/sys/fs/file-max        97321                 The default maximum number of handles is 97321

This value in kernel's document means that File-max is generally calculated as 10% of the memory size (KB), which can be computed if the shell is used:
Grep-r Memtotal/proc/meminfo | awk ' {printf ("%d", $2/10)} ' calculates a value that is generally approximate to the default maximum number of handles.

        " Fs.file-max = 100133 " >>/etc/sysctl.conf && sysctl-p

Number of concurrent TCP connections on a single server for Linux

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.