Fixed “ too many open files ”

来源:互联网 发布:装修立体效果图软件 编辑:程序博客网 时间:2024/06/03 13:30

A couple of days ago we ran into the infamous “too many open files” when our Tomcat web server was under load. There are several blogs around the internet that tries to deal with this issue but none of them seemed to do the trick for us. Usually what you do is to set the ulimit to a greater value (it’s something like 1024 by default). But in order to make it permanent after reboot the first thing suggested is to update the /proc/sys/fs/file-max file and increase the value then edit the /etc/security/limits.conf and add the following line * - nofile 2048 (see here for more details). But none of this worked for us. We saw that when doing

cat /proc/<tomcat pid>/limits

the limit was still set to the initial value of 1024:

Limit                     Soft Limit           Hard Limit           UnitsMax cpu time              unlimited            unlimited            secondsMax file size             unlimited            unlimited            bytesMax data size             unlimited            unlimited            bytesMax stack size            8388608              unlimited            bytesMax core file size        0                    unlimited            bytesMax resident set          unlimited            unlimited            bytesMax processes             63810                63810                processesMax open files                1024                     1024                    filesMax locked memory         65536                65536                bytesMax address space         unlimited            unlimited            bytesMax file locks            unlimited            unlimited            locksMax pending signals       63810                63810                signalsMax msgqueue size         819200               819200               bytesMax nice priority         0                    0Max realtime priority     0                    0Max realtime timeout      unlimited            unlimited            us
It was not until we found this thread that the reason and solution became clear. Our Tomcat instance was started as a service during boot and there’s a bug discovered and filed (with patch) in 2005 that doesn’t seem to have been resolved yet. The bug reveals itself by ignoring the max number of open files limit when starting daemons in Ubuntu/Debain. So the work-around suggested by “BOK” was to edit /etc/init.d/tomcat and add:

ulimit -Hn 16384ulimit -Sn 16384
Finally the max number of open files for Tomcat was increased!

摘自:https://blog.jayway.com/2012/02/11/how-to-really-fix-the-too-many-open-files-problem-for-tomcat-in-ubuntu/


原创粉丝点击