Tuning: Increase “Open Files Limit” & “Max Open Files”

Posted by

1. fs.file-max : The maximum number of file handles denotes the maximum number of open files on a Linux system.

Find current maximum number of file handles for the entire system
cat /proc/sys/fs/file-max

Find current usage of file handles
[[email protected]:~]# cat /proc/sys/fs/file-nr
4640 0 2097152

– number of allocated file handles
– the number of allocated but unused file handles
– maximum number of file handles.

To change the value without reboot

or edit /etc/sysctl.conf & add following line.

2. Changing Limits for files & processes based on user (values can be varied based on your requirements.)
edit : /etc/security/limits.conf

fields:
– */user-name – to specify the user
– hard – hardlimit
– soft – softlimit
– nofile – max number of open files
– nproc – max number of processes

And to make this effect, Add below line of code in following files,
/etc/pam.d/common-session & /etc/pam.d/common-session-noninteractive

session required pam_limits.so

But remember, if you are using any service like supervisor for managing the process, you will need to change the properties of supervisor since the parent process is supervisord & it will be inherited to itsĀ children. In case of supervisor,

edit /etc/supervisor/supervisord.conf & add the following parameter under [supervisord]
minfds=64000

Testing

Check Hard limit:

Check Soft Limit

To find limits of particular process (using PID)

you can find PID of a process using top/ps command.

this will return all nginx process & their pids.

Leave a Reply

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