Monday, February 7, 2011

Too many open files

Certain applications, such as a web server with lots of database connections, require a large number of open files. Most Linux systems are, by default, configured to allow relatively small number of open files, e.g. 1024. How to change this limit isn't as obvious as one might hope.

ulimit will show you current limits and let you change limits for the current session. But, one rarely cares about a temporary change. For a permanent change, one must realize that these limits are in place for security purposes---so that it is difficult for a single user to bring down the entire machine. So, the limits are configured in /etc/security/limits.conf. Adding the following lines to /etc/security/limits.conf should help if you are having "too many open files" troubles:

* soft nofile 16384
* hard nofile 65536
Note that this is also the place to "unlimit" the number of processes a user can run, e.g.:
* soft nproc 4096
* hard nproc 16384
Note that a "soft" limit is the limit a user will get when starting a shell. The "hard" limit is the highest limit they can set without "root" privileges.

Note that when checking limits using ulimit, soft limits are shown by default. Use the -H option to get hard limits. The -a option shows "all" limits. So, run the following two commands to see soft, then hard limits, respectively:

ulimit -a
ulimit -a -H

1 comment:

  1. In my system when i run ulimit -a ,it shows open
    files (-n) 1024 ,
    Hi ,

    small confusion .

    But when i run , below command to know openfiles related to java .it is showing more than 1024 only form java .

    #lsof|grep java|wc -l
    27661

    ReplyDelete