In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > IT Information >
Share
Shulou(Shulou.com)11/24 Report--
This article comes from the official account of Wechat: developing Internal skills practice (ID:kfngxl). Author: Zhang Yanfei allen
Perplexing the concurrency problems of many people in network development, I found that many students did not fully understand a basic problem all the time. That is, how many network connections can a server support? I think it is necessary for me to send a separate article to talk about this problem.
Many students' first reaction to this question was 65535. The reason is: "it is said that there are at most 65535 port numbers, and that long-term connections will be maintained at most 65535." Is that it? Others said, "it should be limited by the space size of the quad in the TCP connection, which adds up to more than 200 trillion!"
If you don't understand this problem thoroughly, I'll tell you a story today.
A chat about server-side concurrency
"the TCP connection quad is the source IP address, source port, destination IP address, and destination port. If any element changes, it represents a completely different connection. Take my Nginx, for example, its port is fixed using 80. In addition, my IP is also fixed, so the destination IP address and destination port are fixed. The rest of the source IP address and source port are variable. So in theory, I can establish at most 2 to the 32 th power (ip number) × 2 to the 16th power (port number) on my Nginx. This is a big number of more than 200 trillion! "
"every time a process opens a file (everything in linux, including socket), it consumes a certain amount of memory resources. If someone with bad intentions starts a process to create and open new files indefinitely, it will crash the server. Therefore, for the sake of security, the linux system limits the number of file descriptors that can be opened in many locations, including system level, user level and process level. The meaning and modification of these three restrictions are as follows: "
System level: the maximum number that can be opened by the current system, which can be modified by the fs.file-max parameter
User level: specify the maximum number of users can open, modify / etc / security / limits.conf
Process level: the maximum number that can be opened by a single process, which can be modified by the fs.nr_open parameter
"my receive cache size is configurable and can be viewed with the sysctl command."
$sysctl-a | grep rmemnet.ipv4.tcp_rmem = 4096 87380 8388608net.core.rmem_default = 212992net.core.rmem_max = 8388608 "where the first value in tcp_rmem is the minimum number of bytes that need to be allocated for your TCP connection. The default value is 4K, up to a maximum of 8MB. In other words, when you have data to send, I need to allocate at least 4K memory for the corresponding socket, maybe even larger. "
"the size of the send cache allocated by TCP is affected by the parameter net.ipv4.tcp_wmem configuration."
$sysctl-a | grep wmemnet.ipv4.tcp_wmem = 4096 65536 8388608net.core.wmem_default = 212992net.core.wmem_max = 8388608 "in net.ipv4.tcp_wmem" the first value is the minimum value of the send cache, which is also 4K by default. Of course, if the data is very large, the cache will actually be allocated larger than the default value. "
Record of millions of connections on the server
"what are you going to prepare? remember that Linux has a limit on the maximum number of file objects, so if you want to complete this experiment, you have to increase this limit at the user level, system level, process level, and so on. The purpose of our experiment is 100W, which is set to 110W, which is very important! because it is necessary to ensure that other basic commands such as ps,vi are available when doing the experiment."
The number of active connections did reach 100W:
$ss-n | grep ESTAB | wc-l 1000024 the total memory of the current machine is 3.9GB, of which the kernel Slab takes up as much 3.2GB. MemFree and Buffers add up to just over 100 MB:
$cat / proc/meminfoMemTotal: 3922956 kBMemFree: 96652 kBMemAvailable: 6448 kBBuffers: 44396 kBSlab: 3241244KB kB through the slabtop command, you can see that densty, flip, sock_inode_cache and TCP each have 100W kernel objects:
Conclusion one of the business characteristics of the back-end of the Internet is high concurrency. However, the question of how many TCP connections a server can support seems to confuse many students. I hope you can rub this problem under your feet after today!
Learning is a painful thing, especially many readers in our account come to see my technical number article after a full day's work. I've been trying to figure out how to organize the form of technical content so that people can understand it and save a little more brain cells. I wanted to post the maximum number of concurrency of this server for a long time, but I am not satisfied with writing two or three versions. Today, I finally came up with a way to make it easier for everyone to understand.
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.