当前位置:网站首页>PHP server interacts with redis with a large number of close_ Wait analysis
PHP server interacts with redis with a large number of close_ Wait analysis
2022-07-03 11:25:00 【dj1540225203】
Recently, it was found that there was a small number of visits ( Probably 1000 Time / God ) Server for , With the redis In the process of interaction , A lot of CLOSE_WAIT Network state , Lead to fd Resources are full . At first glance, it's counter intuitive , The number of visits is small and takes up a lot of resources , Finally, through analysis tcp agreement , And analysis php-fpm Model , Finally found and solved the problem .
Inquire about linux in tcp The order of the situation :
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' 

A lot of close_wait state
1.CLOSE_WAIT principle
It's disconnected tcp When the connection , There will be one. 4 The process of waving . The party who actively disconnects will initiate a FIN package , The receiver will return a ACK Bao told the initiator that I knew you were going to disconnect , At this time, the status of the receiver changes to CLOSE_WAIT And deal with the closing work . Under normal circumstances , After the receiving party completes the closing work , Will send a FIN package , Then after receiving the reply from the developer ACK After the bag , Whole 4 The process of waving is over .
But under abnormal circumstances , The receiver does not send FIN package , Leading to its state has been CLOSE_WAIT state , If every connection is like this , It will occupy a lot of system resources , As a result, services cannot be provided externally .

4 Second wave
2. Such a small number of visits php The server , And redis Why does interaction occur CLOSE_WAIT state
php And redis Interactive analysis
stay php in , did not redis The concept of connection pool , So in order to avoid continuous connection 、 Disconnect from redis The connection of , We are php In general, the form of long connection is used with redis Interact .
This form creates the life cycle of the connection and php-fpm The life cycle of a process is consistent , So every time a new request comes , City reuse php-fpm Originally created redis Connect , This saves constant connections 、 disconnect redis The resulting network overhead .
php-fpm Life cycle of
php-fpm There is a configuration pm.max_requests Express ,php-fpm Process process pm.max_requests Requests will be destroyed and a new child process will be generated . This means that 1 individual fpm The process needs to go through max_requests Requests will be destroyed
pm.max_requests = 50240Focus on the problem
from php And redis Interaction analysis of , We can draw : One reids Long connection life cycle and php-fpm Child processes are consistent .
and php-fpm The life cycle of is experience pm.max_requests A request , The configuration of our server is 50240.
meanwhile , The number of server visits with problems is particularly small (1000 Time / God ), That is to say a php-fpm The life cycle of is at least 50 God (50240/1000=50, There should be more , Because there is more than one process ), that redis The life cycle of the connection is at least 50 God .
Here 50 In the day ,redis Will give php The server initiates a disconnect request ,php The server will return a ACK, Then change the status to CLOSE_WAIT, however php The server will not send another FIN Give it to redis, Because its life cycle is not over . So it will eventually produce a lot of CLOSE_WAIT.
3. Why does a large number of visits not appear CLOSE_WAIT
Large amount of visits , signify php-fpm Process max_requests Easy to reach ,php-fpm The life cycle of will be very short , Not yet redis Trigger time of server timeout disconnection .
4. Solution
Use a short connection ~
Reference resources :
http://www.gosanye.com/post/10160.html
Reference resources :http://t.zoukankan.com/xinfang520-p-8961129.html
边栏推荐
- Touch and screen automatic rotation debugging
- Double linked list of linear list
- 使用onvif协议操作设备
- Oracle withdraw permission & create role
- (二)进制
- 高精度室内定位技术,在智慧工厂安全管理的应用
- POI excel 单元格换行
- Analysis of JMM memory model
- 在腾讯云容器服务Node上执行 kubectl
- Gut | Yu Jun group of the Chinese University of Hong Kong revealed that smoking changes intestinal flora and promotes colorectal cancer (do not smoke)
猜你喜欢

10. Nacos source code construction

Redis things

Crawl with requests

After a month, I finally got Kingdee offer! Share tetrahedral Sutra + review materials

行业唯一!法大大电子合同上榜36氪硬核科技企业

Expandablelistview that can expand and shrink (imitating the list page of professional selection of Zhilian recruitment)

Matlab extracts numerical data from irregular txt files (simple and practical)

有赞CTO崔玉松:有赞Jarvis核心目标是使产品变得更加聪明和可靠

Résumé des questions d'entrevue (2) Modèle io, ensemble, principe NiO, pénétration du cache, avalanche de rupture

数据库增量备份 - DB INCR DB FULL
随机推荐
Solve undefined reference to`__ aeabi_ Uidivmod 'and undefined reference to`__ aeabi_ Uidiv 'error
POI excel 单元格换行
C language AES encryption and decryption
How to clean up v$rman_ backup_ job_ Details view reports error ora-02030
使用onvif协议操作设备
Programmers' entrepreneurial trap: taking private jobs
面试题总结(2) IO模型,集合,NIO 原理,缓存穿透,击穿雪崩
表空间创建管理及控制文件管理
图解网络:什么是虚拟路由器冗余协议 VRRP?
如何成为一名高级数字 IC 设计工程师(1-2)Verilog 编码语法篇:Verilog 1995、2001、2005 标准
VPP three-layer network interconnection configuration
Illustrated network: what is virtual router redundancy protocol VRRP?
行业唯一!法大大电子合同上榜36氪硬核科技企业
Hal - General
Activity and fragment lifecycle
Solutions of n-ary linear equations and their criteria
搭建ADG后,实例2无法启动 ORA-29760: instance_number parameter not specified
Résumé des questions d'entrevue (2) Modèle io, ensemble, principe NiO, pénétration du cache, avalanche de rupture
[VTK] vtkPolydataToImageStencil 源码解读
MATLAB提取不規則txt文件中的數值數據(簡單且實用)