Posted by: Chyne on: May 20, 2009
It seems that the “Too many open files” error is a common problem for Linux users. This error can be easily occurs if you had set the maximum number of open files which is allowed by the Operating System is too low and the kernel is longer can handle it anymore.
The following errors will appear in the log files if you are hitting into this problem:-
Caused by: java.io.IOException: Too many open files
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.checkAndCreate(File.java:1704)
at java.io.File.createTempFile(File.java:1793)
at javax.imageio.stream.FileCacheImageOutputStream.(FileCacheImageOutputStream.java:67)
at com.sun.imageio.spi.OutputStreamImageOutputStreamSpi.createOutputStreamInstance(OutputStreamImageOutputStreamSpi.java:50)
at javax.imageio.ImageIO.createImageOutputStream(ImageIO.java:393)
... 66 more
In order to fix the problem, what you need to do in the first place is to check the current maximum number of file descriptors:-
# cat /proc/sys/fs/file-max
The value sets in the /proc/sys/fs/file-max is for the overall limit of files that can be opened across all files. In order to increase the maximum number of file descriptors, you can ‘cat’ a number to this file:-
# echo "200000" >/proc/sys/fs/file-max
If this doesn’t help much, you might need to consider increasing the ulimit open file value as well. The ulimit sets the number of files that can be open per process. For example, you can increase the ulimit file value as following:
# ulimit -n 16384
If you need other information for troubleshooting this, there are several Unix commands that you can use to gather more information about this problem:
Figure out the number of current open file descriptor limit
# more /proc/sys/fs/file-max
Shows the total of open file descriptors are currently being used
# more /proc/sys/fs/file-nr
Shows the list of current open files
# lsof
The total files descriptors used by specific program
# lsof –p pid | wc –l
* Note: the <pid> can be obtained when you are using the #lsof command
Other useful readings about file descriptors and finding open files with lsof: