返回顶部

记排查too many open files问题思路

排查思路:

1. 首先确认进程id

ps -ef | grep xxx

 查看对应进程的句柄数

lsof -p $PID | wc -l

这里有一点要注意的是,lsof不加-p参数,得到的结果会比实际句柄数多很多,不是准确数量。https://blog.csdn.net/Waria/article/details/116157567

一般情况下线程共享与独享资源的划分

线程共享

线程独享

地址空间 程序计数器
全局变量 寄存器
打开的文件
子进程 状态字
闹钟  
信号及信号服务成勋  
记账信息  

 

 

 

 

 

 

 

 

 

 

 

2. 查看系统文件描述符

cat /etc/security/limits.conf

查看当前 Shell 的 nofile 限制

ulimit -n

查看某一进程的 nofile限制

cat /proc/$PID/limits

根据查到的结果,可以分析出,是系统设置的句柄数不满足业务需求,还是代码异常导致句柄泄露。

补充:配置supervisord句柄数限制 

修改配置文件  /usr/lib/systemd/system/supervisord.service , 将LimitNOFILE设置为 10000。

[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service nss-user-lookup.target

[Service]
Type=forking
LimitNOFILE=10000
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf

[Install]
WantedBy=multi-user.target

保存文件后,需要调用 systemctl daemon-reload 刷新服务配置。

# 查看默认的 LimitNOFILE
> systemctl show -p DefaultLimitNOFILE
4096
# 查看某一个 Service 的 LimitNOFILE
> systemctl show supervisord -p LimitNOFILE
10000

 

参考自 https://e7868a.com/linux-limits

https://stackoverflow.com/questions/45055748/too-many-open-files-raised-by-supervisord

posted @ 2022-11-03 20:03  雨山木风  阅读(187)  评论(0编辑  收藏  举报