Wednesday, May 15, 2013

Too many open files error

Today I've got a ticket about hitting resource limit on one of my Linux boxes.
User was running some java process which started failing with "too many open files" error.
Default limit on RHEL6 is set to 1024 open files per user which may be not enough for bigger applications and databases.
You can verify current limit by running:
ulimit -n
ulimit -Hn
and modify it in /etc/security/limits.conf. Change will be visible upon next login.

If not sure, you may verify current list of open files by using:
lsof -u username
You may notice that lsof will sometimes report higher number of open files than it's allowed (according to ulimit). To get more reasonable value you will need to filter the output to remove entries that are not counted as open file descriptors:
lsof -u username | grep / | egrep -v "mem|DIR|DEL|COMMAND" | sort  -k9 -u

While setting higher values of allowed open file descriptors it's worth to check operating system limit:
cat /proc/sys/fs/file-max
You may change it in /etc/sysctl.conf by adding:
fs.file-max = 123000
and running sysctl -p to re-read /etc/sysctl.conf and apply new settings.

No comments:

Post a Comment