springboot使用undertow假死的原因

最近使用springboot,在高并发下出现了一个问题:

服务的进程还跑着,端口缺不再监听了,报错如下:

Too many open files in system

 原来是开的系统文件太高了

通过以下命令可以查看系统文件总上限:

cat /proc/sys/fs/file-max
cat /proc/sys/fs/file-nr

Centos7下,以下命令修改文件上限:

实时修改:

sysctl -w fs.file-max=500000

永久修改:

vi /etc/sysctl.conf

增加内容
fs.file-max=500000

刷新
sysctl -p

通过以下命令可以查看单个用户limit

ulimit -n

Centos7下,以下命令修改单个用户文件上限:

#实时修改
ulimit -n 655350

#永久修改
vi /etc/security/limits.d/20-nproc.conf

添加内容:

#nproc
* soft nproc 655350
root soft nproc unlimited
* hard nproc 655350
root hard nproc unlimited
#nofile
* soft nofile 655350
* hard nofile 655350

centos-7 新增了/etc/security/limits.d/20-nproc.conf文件,并且该文件会覆盖/etc/security/limits.conf的配置参数

参考内容:

https://www.tecmint.com/increase-set-open-file-limits-in-linux/

https://www.cnblogs.com/CoolMark-blog/p/12318850.html

相关命令:

#系统当前open file总数(参考)-Ki命令排除线程,包含网络连接
lsof -Ki|wc -l
# 通过系统快照查看
cat /proc/sys/fs/file-nr
#以上两个可能不同,因为下边的是某一个时刻的快照,系统的open file可能随时在波动


#以下命令会统计线程,线程是共享文件描述符的(The file descriptors are shared between the threads.)
lsof|wc -l

#查看某个pid的open files数量
lsof -p 8957
lsof -Ki | grep 8957| wc -l 



--------------------------------------------------------
本文发表于:https://www.cnblogs.com/flying607/
原文地址:https://www.cnblogs.com/flying607/p/14824252.html