How Can I Increase the Operating System File Descriptor Limit?
Too many open files error happens when a process needs to open more files than the operating system allows. This number is controlled by the maximum number of file descriptors the process has. If you experience such an issue, you can increase the operating system file descriptor limit.
File descriptors are an abstract method for your system to store information about open files and thus facilitate communication. Each open file is assigned a file descriptor in a file descriptor table for the whole system and a certain process. The system puts limits on how big these tables can get and, as requests require the opening of files and thus the generating of file descriptors, these limits can constrain how many concurrent requests the server can handle. In UNIX-like operating systems, there are system-level and process-level file descriptor limits. For obvious reasons, the system-level file descriptor limit can restrict how much your server can handle, but, because LiteSpeed Web Server only uses a small number of server processes to serve all clients, LSWS can also require a higher process-level file descriptor limit. Therefore, to use your server to its maximum potential, it is important to set both of these limits to a high enough value.
If the server is started by the root user, when this limit is too low, the system will automatically try to adjust the limit based on server configurations. If the server was not started by the root user, this limit has to be manually adjusted with root privilege. You may want to put the following commands into your startup scripts in order to automatically set the limit after rebooting the machine.
Process-Level File Descriptor Limits
Use the command
ulimit -n to check the current process-level file descriptor limit, like so:
ulimit -n 32768
You can reset these limits by adding a number after the command, such as:
ulimit -n 3276800
Note: In Linux, non-root users can also use
ulimit -n xxxx to change the process-level limit (at least in Kernel 2.4.x), but you need to add the following lines in
/etc/security/limits.conf to give these users permission:
soft nofile 2048 hard nofile 8192
System-Level File Descriptor Limits
Setting system-level file descriptor limits is a different process for different systems.
Check the system-level limit for open files:
If it looks low, increase the limit with:
echo 40000 > /proc/sys/fs/file-max
You may also need to increase
echo "10000" > /proc/sys/fs/nr_open
For kernel 2.2.x, you may also need to adjust the inode limit (the maximum number of files that can be stored in the file system):
echo 65535 > /proc/sys/fs/inode-max
Add the following lines in
To reset the hard file descriptor limit:
set rlim_fd_max = XXXX
To reset the soft file descriptor limit:
set rlim_fd_cur = XXXX
Add the following line in