Linux Tomcat max open files

First of all, I must say that Tomcat is one code that shouldn’t be never written. Troubleshooting is a bitch, it uses Java, and the official support is closing to zero.

I stumbled into a error (in a Debian / Ubuntu) where a Tomcat app writes into /var/log/tomcat7/ an error saying Too many open files"

The app itself also displayed a variety of errors, which basically said nothing.

Tried to hack the “/etc/security/limits.conf” -file – no help there

Tried to hack the “/etc/sysctl.conf” -files – no help there

Tried the “ulimit -n” -way – no help there

After this I contacted Tomcat official support, and the answer was that I should install the instance in a Windows Server -machine, and check, if the problem still extists. (!!!) The server itself had a variety of services, so that was out of the question. Must dig deeper.

After of hours of surfing I came across a known bug of of Tomcat:

…and the resolution, you must hack the /etc/init.d/tomcat7 -file

Inserting lines:

ulimit Hn 16384
ulimit Sn 16384
into a file /etc/init.d/tomcat7 did the trick. I inserted the following:
# Short-Description: Start Tomcat.
# Description:       Start the Tomcat servlet engine.

ulimit -Hn 16384
ulimit -Sn 16384

set -e



From the above I inserted the two “ulimit…” lines, and voil’a, worked.
Before the change (and reboot) it was:
ps aux | grep tomcat

cat /proc/<pid>/limits
Max open files            1024               1024                files

And after the setting (and reboot) it was:[sourcecode language="csharp"]
Max open files            16384                16384                files
I hope anyone doesn’t have to hack this error, and if does, this one will help.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *