Tomcat — Too many open files

I guess if you didn’t change anything on your ubuntu box then your default settings are like this.

# ubuntu at hello in ~ [17:13:12]
→ cat /proc/4013/limits; # 4013 is Tomcat's PID.
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 59759 59759 processes
Max open files 4096 4096 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 59759 59759 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us

However, if you get “(Too many open files)” exception (as below)

Processing of multipart/form-data request failed. /tmp/tomcat.5941536117364812143/work/Tomcat/localhost/ROOT/upload_e463db01_1b46_4cc5_96b9_9eac15eae4cc_
00181875.tmp (Too many open files)

then, you should open your /etc/security/limits.conf file then put

* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535

these lines to the end of file (1). After editing this file, you have to log out from your ssh session to apply. Then re-start your Tomcat then run this to see whether it’s applied or not.

cat /proc/<tomcat PID>/limits;

(1) The config that I used might not be a good fit for everyone, so I recommend to check out what “limits.conf” file is.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.