In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to get the number of concurrent Linux servers, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
1. Prologue
Before we begin, throw out an interview question:
What is the maximum number of concurrency of a single machine that you have come into contact with?
What do you think is the maximum number of concurrency of the current normally configured server physical machine?
For back-end developers, the number of concurrency is often positively related to technical difficulty, and in fact it is: mass determines the architecture.
The server will have different priorities according to different business scenarios, the simple pursuit of high concurrency is not the fundamental goal, high availability & stability is more important.
So in the end, our goal is to pursue high concurrency, reduce cost and increase efficiency on the basis of high availability and high stability.
High availability-high concurrency is what we feel intuitively, in essence, this is a complex system engineering, each link will affect the results, each piece is worth studying and in-depth.
2. C10K problem and C10M problem
At the beginning of 2000, the scale of the global Internet was not large, but the problem of C10K was already put forward at that time. The so-called C10K is a concurrency problem of one week on a single machine, although it is no longer a difficult problem, but it was a far-sighted and challenging problem at the beginning.
The C10K question was first posted on its personal site by Dan Kegel. The original link is as follows:
Http://www.kegel.com/c10k.html
Related information shows that Dan Kegel currently works at Google and has been exposed to computer programming since 1978. He is the author of Winetricks and Crosstool and a photo of the boss when he was young:
Dan Kegel's article is not difficult to read. Readers who are engaged in server-side development or are interested in high-performance network development are advised to try to read it.
Epoll is not mentioned in the third edition of APUE, so it is not long for us to solve the C10K problem, in which technologies such as IO reuse epoll/kqueue/iocp play a very important role in solving the C10K problem.
Open source gods have developed network libraries such as libevent/libuv based on epoll/kqueue, which greatly improves the development efficiency of highly concurrent networks, which is not unfamiliar to CSync programmers.
Here is a brief mention of the prospects and challenges for the next decade: the C10m problem.
The people at the top of the wave have long been thinking about achieving 1000W concurrency on a single machine, which now sounds incredible, but to achieve this goal, in addition to hardware improvements, it is more important to transform the system software and protocol stack.
Errata Security's CEO Robert Graham's speech at the Shmoocon 2013 conference, the important point of the boss is:
Don't let the OS kernel perform all the onerous tasks: transfer packet processing, memory management, processor scheduling, and other tasks from the kernel to the application efficiently, leaving OS such as Linux only to the control layer and leaving the data layer to the application.
That's true. Don't you think the Linux kernel has done too many things that shouldn't have been done by itself?
DPDK, PFRING, NETMAP and other technologies that have emerged in recent years are similar ideas, and the popular coprocessor + CPU architecture is also like this:
3. Analysis of the maximum concurrency of servers
The C10K and C10M problems mentioned above are all about improving the concurrency ability of the server, but it is inevitable to ask: what is the maximum concurrency limit for the server?
3.1 Quintuple
Those who have done correspondence must have heard the concept of quintuple. A quintuple can uniquely mark a network connection, so to understand and analyze the maximum number of concurrency, you must understand quintuple:
In this way, it can be basically considered that the maximum number of concurrency in theory = only one five tuples on the server side.
3.2Port & IP combinations
So for the server, what is the maximum number of server-side tuples?
Some people say it is 65535, but obviously not, but there is such an answer because the current port number of Linux is a 2-byte short type, with a total of 2 ^ 16 ports. Excluding some ports occupied by the system, there are only more than 64000 ports left.
For the server itself, the number of DestPort is indeed limited, assuming that there are multiple network cards, each network card is bound to multiple IP, and the combination type of the number of Port ports and IP number of the server is also limited.
For clients, their own ports and IP are also limited, although this is a combination problem, but the number is still limited:
3.3 theoretical limit of concurrent number
Looking at the front port-IP combination number calculation, it seems that the number of concurrency will not be very large.
No, it's really big.
For analysis, the previous calculations are for a single server or client, but in fact, each server will deal with all clients across the network, so from the server point of view, the number of source IP and source Port is very large.
Theoretically, the client IP that can be accepted by the server is 2 ^ 32 (calculated according to IPv4), and the number of ports is 2 ^ 16. At present, the port number is still 16bit, so the theoretical maximum value is 2 ^ 48, which is really large!
3.4 actual situation
There is no free lunch.
Each connection consumes system resources, so in practice, the maximum number of concurrency may be set to ensure the security and stability of the server, so the maximum number of concurrency in this theory is impossible to achieve.
In fact, the number of concurrency is directly related to the business, and it is no problem for memory-based servers like Redis to concurrency more than one hundred thousand. In most cases, tens of thousands / hundreds / thousands / tens of thousands exist.
4. Maximum number of client connections
It is understood that the maximum number of concurrency of the server is 2 ^ 48, so how many servers can the client connect to?
For the client, of course, we can increase the connection capacity with the help of multiple network cards and multiple IP. We still assume that the client has only one network card and one IP. Due to the limit of the number of ports to 2 ^ 16, and then remove the ports occupied by the system, the remaining available port is almost 64000.
In other words, although the client can connect to any destination IP and destination port, the client's own port is limited, so the theoretical maximum number of connections for the client is 2 ^ 16, including the port occupied by the system.
5. Client in NAT environment
After solving the first two problems, let's look at another one:
How many private network IP concurrently can a public network egress NAT service device support to access public network services?
After all, the public network IP is limited and costs money, and most of our machines access the public network with NAT in the local area network, so this scenario is still very familiar.
Let's take a look at the IP& port replacement and mapping restore process when the private network machine accesses the public network. We will understand:
Because the client is a NAT device, a maximum of 65535 concurrent accesses to the public network are supported in the NAT environment.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.