Too many open files error

Root causes:

In most operating systems, a file is simply a chunk of data stored on disk. However, in Linux, everything is file. Besides data and executable files, directories, sockets, even different components are treated as files. Therefore max-file handle can be opened at once is vitally important for portal to function properly. One must consider all the file handles consumed by portal and 3rd party libraries under the expected load.

The file-max file located in /proc/sys/fs/file-max shows the maximum number of file-handles that the Linux kernel will allocate for that user. It is required to modify the parameter to improve the number of open files by increasing the value of /proc/sys/fs/file-max to sufficient enough value. The defacto calculation for maximum possible file-handles is as follows: 256 handles for every 4M of RAM exists: for instance, a machine with 128 MB of RAM and Linux O.S. can handle 128/4=32, 32*256=8192 file handles safely.

In the case of portal solution, it is required to have a larger window between the opening and closing file handles to prevent errors like “too many open files” or “no such file or directory” caused by too many open files. By default a bmpweb user have maximum of 1024 file handles allowed. However, this value is not enough to handle the entire request according to the maximum load required.

Solution:

Since handling of opening and closing files requires a larger window than 1024 maximum open files in portal, we must increase this value. If we would set this parameter to 65536, the amount memory required when all the file handles are allocated would be (65536/256) *4 = 1024 MB. Therefore we can safely set this value to 65536.

To set this parameter for bmpweb user we must modify limits.conf under /etc/security as follows:

After limits.conf file is modified, it is required to restart for modifications to take effect.

You can check setting with commands:
check user id to make sure same user is in use , than execute

server # limit descriptors
descriptors  4096

 

Jan D.
Jan D.

"The only real security that a man will have in this world is a reserve of knowledge, experience, and ability."

Articles: 678