Fixing “Too many open files” error

Often we get “org.apache.tomcat.jni.Error: 24: Too many open files” errors on Apache Tomcat. If this happened then the process will wait for 3 minutes in open state and will fail after that. It can be fixed by increasing the Open file limits on OS limits. By default CentOS is set with 1024 limit.

1. Edit the file /etc/security/limits.conf and add the following lines

*       soft    nofile  8192
*       hard    nofile  65535

2. Edit the file /etc/pam.d/login and add the following lines

session required /lib/security/

3. Check the limit again by logoff and login

ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 119859
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 8192
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 119859
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Here we can see the open files is set to 8192 which should be enough but it is best practice to check the open file with lsof and adjust as per requirements.

Tomcat Native Library (APR)– Installation on CentOS

Tomcat can use the Apache Portable Runtime to provide superior scalability, performance, and better integration with native server technologies.

You will see this info often on catalina.out if you dont have the tomcat native library not installed on servers.

INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/local/jdk1.6.0_23/jre/lib/amd64/server:/usr/local/jdk1.6.0_23/jre/lib/amd64:/usr/local/jdk1.6.0_23/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

to get rid of this we need to install apr utilities and tomcat native library. Lets see how to install on CentOS 5.4-X86_64

yum install apr.x86_64 apr-devel.x86_64 -y

We installed apr utilities, now we need to install tomcat native libraries Continue reading Tomcat Native Library (APR)– Installation on CentOS