当前位置:网站首页>The interviewer dug a hole for me: how many concurrent TCP connections can a single server have?
The interviewer dug a hole for me: how many concurrent TCP connections can a single server have?
2022-04-23 13:28:00 【Zhu Xiaosi】
There was a time when we were looking for network programming C10K Solutions to problems , But now from the perspective of hardware and operating system support, it's not very challenging for a single server to support tens of thousands of concurrent connections . of C10K( Stand alone 1 10000 concurrent connection problems ) You can refer to 《 the previous 10 year , The famous C10K Concurrent connection problems [1]》 and 《The C10K problem[2]》 These two articles .
Let's assume that a single server can only support 10000 level concurrent connections at most , In fact, it's far enough for most applications , But for some Internet companies with a large user base , The number of concurrent connections often faced is millions 、 Ten million 、 Even hundreds of millions . Although the current cluster , Distributed technology can share concurrent load on multiple servers , Then we just need to expand dozens of computers to solve the problem , But we would like to mine more resources of a single server , Try to expand vertically first , Further horizontal expansion , This can effectively save server related expenses ( Hardware resources 、 Computer room 、 Operation and maintenance manpower 、 Electricity is also a big expense ).
How much can a server support TCP Concurrent connection ?
First of all, we need to consider the limitation of file handle . stay linux The friends who write the web server program must know every one of them tcp All connections take up a file descriptor , Once the file descriptor is used up , The error returned by the new connection is “Socket/File:Can't open so many files”. At this point, you need to understand the operating system's limit on the maximum number of files that can be opened . We can go through ulimit -n
command 、/etc/security/limits.conf file as well as /etc/sysctl.conf File, etc. to modify the number of file handles . More details can be found in 「 Zhu Xiaosi's blog 」 This article in 《 File handle ? File descriptor ? Stupid is not clear 》.
The second thing to consider is the limitation of port range . Port number on the operating system 1024 The following are reserved by the system , from 1024-65535 It is used by users . Because each TCP All connections need a port number , So we can have at most 60000 Multiple concurrent connections . I think there's a lot of wrong thinking friends ? Interviewers also prefer to lead digging here , There are similar problems : One UDP Connection can be reused TCP The port occupied by the connection ?( You can leave your answer in the message area below .)
How to identify a TCP Connect ? The system uses a 4 Four tuples to uniquely identify a TCP Connect : Local port number local port、 Local IP Address local ip、 Remote port number remote port、 Distal IP Address remote ip.server Usually fixed on a local port to listen , wait for client Connection request for . Address reuse not considered (unix Of SO_REUSEADDR Options ) Under the circumstances , Even if server Multiple ends ip, The local listening port is also exclusive , therefore server End tcp Connect 4 Only tuples remote ip( That is to say client ip) and remote port( client port) Is variable , So the biggest tcp Connect as client ip Count × client port Count , Yes IPV4, Don't consider ip Address classification and other factors , Maximum tcp The number of connections is about 2 Of 32 Power (ip Count )×2 Of 16 Power (port Count ), That is to say server End stand-alone maximum tcp The number of connections is about 2 Of 48 Power .
The above conclusions are all theoretical single machines TCP Number of concurrent connections , In fact, the number of concurrent connections of a single machine must be subject to hardware resources ( Memory )、 Network resources ( bandwidth ) The limitation of , At least we can achieve hundreds of thousands of levels of concurrency .
Reference material
[1]
the previous 10 year , The famous C10K Concurrent connection problems : http://www.52im.net/thread-566-1-1.html
[2]
The C10K problem: http://www.kegel.com/c10k.html
Want to know more ? sweep Trace the QR code below and follow me
The background to reply ” Add group “ Access to official account entrance
版权声明
本文为[Zhu Xiaosi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231232410502.html
边栏推荐
- [wechat applet] flex layout usage record
- MySQL5.5安装教程
- Imx6ull QEMU bare metal tutorial 1: GPIO, iomux, I2C
- Nodejs + Mysql realize simple registration function (small demo)
- Introduction to metalama 4 Use fabric to manipulate items or namespaces
- C语言之字符串与字符数组的区别
- Esp32 vhci architecture sets scan mode for traditional Bluetooth, so that the device can be searched
- 面试官给我挖坑:URI中的 “//” 有什么用?
- You and the 42W bonus pool are one short of the "Changsha bank Cup" Tencent yunqi innovation competition!
- Filter and listener of three web components
猜你喜欢
RTOS mainstream assessment
[point cloud series] pointfilter: point cloud filtering via encoder decoder modeling
【快排】215. 数组中的第K个最大元素
初鉴canvas,展示个小小的小案例
解决虚拟机中Oracle每次要设置ip的问题
"Xiangjian" Technology Salon | programmer & CSDN's advanced road
MySQL5.5安装教程
面试官给我挖坑:URI中的 “//” 有什么用?
[point cloud series] foldingnet: point cloud auto encoder via deep grid deformation
【动态规划】221. 最大正方形
随机推荐
@优秀的你!CSDN高校俱乐部主席招募!
The interviewer dug a hole for me: what's the use of "/ /" in URI?
AUTOSAR from introduction to mastery 100 lectures (50) - AUTOSAR memory management series - ECU abstraction layer and MCAL layer
Solve the problem that Oracle needs to set IP every time in the virtual machine
Xi'an CSDN signed a contract with Xi'an Siyuan University, opening a new chapter in IT talent training
集简云 x 飞书深诺,助力企业运营部实现自动化办公
Scons build embedded ARM compiler
[point cloud series] deepmapping: unsupervised map estimation from multiple point clouds
The filter() traverses the array, which is extremely friendly
[point cloud series] Introduction to scene recognition
[quick platoon] 215 The kth largest element in the array
How to build a line of code with M4 qprotex
Machine learning -- model optimization
Uniapp image import local image not displayed
十万大学生都已成为猿粉,你还在等什么?
【动态规划】221. 最大正方形
hbuilderx + uniapp 打包ipa提交App store踩坑记
"Xiangjian" Technology Salon | programmer & CSDN's advanced road
Migrating your native/mobile application to Unified Plan/WebRTC 1.0 API
playwright控制本地谷歌浏览打开,并下载文件