The maximum number of concurrent instances of a single server can support

Once upon a time we are also seeking solutions in network programming C10K problem, but now from the point of view of hardware and operating system support Wan concurrent connections on a single server support has been a little challenging. Let's assume that a single server can support up to ten thousand simultaneous connections, in fact, the vast majority of applications, more than enough, but for some countries with a large number of concurrent connections subscriber base of Internet companies are often faced with a million , millions or even hundreds of millions of Tencent (Note: QQ default UDP protocol used). Although clusters, distributed technology for our concurrent load balancing across multiple servers, then we only need to extend the dozens of computer problems can be solved, but we hope to tap the greater resources of a single server first efforts to expand vertically, then horizontally extended, so you can effectively save server-related expenses (hardware resources, room, operation and maintenance, electricity is actually not a small expenditure). So in the end one server can support the number of concurrent TCP connect it?

A common sense: file handle limit
under linux writing a network server friends must know every tcp connection must be accounted a file descriptor, once the file descriptor ran out, the arrival of a new connection back to our mistake is "Socket / File: Can not open so many files ".

Then you need to understand the operating system limit on the maximum number of files that can be opened.

Process limit

Execute ulimit -n output 1024, indicating that a process can only be opened for a maximum of 1024 files, so you can take this default will be configured with up to thousands of concurrent TCP connections.

Temporary modifications: ulimit -n 1000000, but this is only a temporary modification of the currently logged on user current environment effectively, it will fail after the system is restarted or the user exits.

Modify the restart after failure (CentOS 6.5 but I tested and found invalid after the restart): Edit /etc/security/limits.conf file, modify the content

* Soft nofile 1000000

* Hard nofile 1000000

Permanent modification: edit /etc/rc.local, after which add the following

ulimit -SHn 1000000

Global restrictions

Performing cat / proc / sys / fs / file-nr output 93440592026, respectively: 1 has been assigned the number of file handles, 2 but do not use the file handle number has been assigned, the maximum number of file handles 3... But in kernel 2.6 versions of the total value of the second term is zero, this is not a mistake, it actually means that no one has been allocated file descriptor waste have been used.

We can change this value bigger, modify /etc/sysctl.conf file as root:

fs.file-max = 1000000

net.ipv4.ip_conntrack_max = 1000000

net.ipv4.netfilter.ip_conntrack_max = 1000000

Knowledge II: port number range limit?
The following operating system 1024 is the upper port reserved for the system, is used by a user from 1024-65535. Since each TCP connection must account for a port number, so we can have up to more than 60,000 concurrent connections. I would like to have a few friends this wrong idea, right? (Which I used to always think so)

Let's analyze it

How to identify a TCP connection: 4 system with a four-tuple uniquely identifies a TCP connection: {local ip, local port, remote ip, remote port}. Well, we come up with "UNIX Network Programming: Volume I," the fourth chapter explains to accept to look at something conceptual, the second parameter cliaddr represents the ip address and port number of the client. And we actually only use this port when a bind as a server, indicating that the port number 65535 is not complicated by limits on the amount.

The maximum number of connections tcp server: server is generally fixed on a local port monitor, the client waits for connection requests. Without regard to address reuse (unix the SO_REUSEADDR option), even if a plurality of server-side IP, local listening port is exclusive, so tcp server-side connector 4-tuple, only remote ip (i.e. client ip) and remote port (client port) is variable, the maximum number of connections tcp port number for the client ip × client, to the IPV4, without considering other factors ip address classification, the maximum number of connections is about 32 tcp th power of 2 (number ip ) of 16 × 2 power (port number), i.e. the maximum number of server-side single tcp connection 2 to the power of about 48.

Summary
conclusions given above are theoretical number of concurrent connections standalone TCP, in fact, the single number of concurrent connections will certainly be affected by the hardware resources (memory), network resources (bandwidth) limits, at least for our needs can now be done several 100,000 of the concurrency, you do?

Guess you like

Origin www.cnblogs.com/peteremperor/p/10938335.html