Sunday, November 30, 2008

Process File Descriptor Tuning on Linux

I've recently encountered on file handlers limit problem while running java program that holds a large hash of file descriptors. The following example describes how to raise the maximum number of file descriptors per process to 4096 on the RedHat/CentOS distibution of Linux:

Process File Descriptor Tuning

In addition to configuring system-wide global file-descriptor values, you must also consider per-process limits.

The following example describes how to raise the maximum number of file descriptors per process to 4096 on the RedHat?CentOS distibution of Linux:

  1. Allow all users to modify their file descriptor limits from an initial value of 1024 up to the maximum permitted value of 4096 by changing /etc/security/limits.conf

       *       soft    nofile  1024
    * hard nofile 4096

    In /etc/pam.d/login, add:

       session required /lib/security/pam_limits.so
  2. Increase the system-wide file descriptor limit by adding the following line to the /etc/rc.d/rc.local startup script:

       echo -n "8192" > /proc/sys/fs/file-max

    or, on 2.6 kernels:

       echo -n "8192" > $( mount | grep sysfs | cut -d" " -f 3 )/fs/file-max

    Now restart the system or run these commands from a command line to apply these changes.

  3. You will then need to tell the system to use the new limits:

    ulimit -n unlimited (bash)

    or

    ulimit -n 65535 (bash)

    or

    unlimit descriptors (csh, tcsh).
  4. Verify this has raised the limit by checking the output of:
    ulimit -a (bash) or limit (csh, tcsh)

No comments: