Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Really solve "Too many open files" at a process level not on global ubuntu level

We have tomcat running and we face "Too many open files" problem intermittently.. We have really done lots of google and checked out all of stackoverflow and done everything to fix it like modifying "/etc/security/limits.conf" etc..

Now ulimit -n shows a higher number but still we keep facing problem.

like image 434
Deepak Singhal Avatar asked Dec 20 '25 15:12

Deepak Singhal


2 Answers

Finally when we tried $ cat /proc/<processId>/limits ; we noticed that "Number of open Files" was still shown as 4096 which is old value; though for root it was showing higher values.

Finally we could solve the problem by modifying /etc/default/tomcat7 [ or any other file respective to your process] and adding following lines:

ulimit -Hn 10000
ulimit -Sn 10000

No need of rebooting the system; just restart the process and then check /proc/processId/limits

like image 144
Deepak Singhal Avatar answered Dec 23 '25 12:12

Deepak Singhal


Under ubuntu 16.04 tomcat's maximum number of files is limited by systemd and set automatically to 4096. You can change this value by running

systemctl edit tomcat7

add the following lines:

[Service]
LimitNOFILE=8192

alternatively you can create the config by yourself:

mkdir /etc/systemd/system/tomcat7.service.d/
nano /etc/systemd/system/tomcat7.service.d/override.conf 

after that reload tomcat:

service tomcat7 restart

and double check that the limit is set correctly

ps ax | grep tomcat
cat /proc/<processId>/limits 
like image 29
Jeff Avatar answered Dec 23 '25 13:12

Jeff