Too program open files Problem Analysis

Source: Internet
Author: User

Java programs running on Linux may encounter "Too program open files" exceptions, and are common in scenarios such as high-concurrency File System Access and multi-thread network connection.

Files frequently accessed by programs and sockets are file files in Linux. The system must record the name, location, access authority, and other information of each currently accessed file, such an object is called a file entry. "Open files table" (orange in the figure) stores these file entries and is linearly managed as arrays. The file descriptor serves as the pointer from the process to the open files table, that is, the subscript index of the open files table. Each process is associated with the files it accesses.

 

Each process has a file descriptor table to manage the access of the current process (OpenOrCreate), The file descriptor is associated with the file entry of the file in open files table. Details are not shown. For open files table, how many file entries can be accommodated. In Linux, if the file limit for setting the open files table exceeds the configured value, the system rejects requests for other file operations and throws a too program open files exception. Such restrictions can be divided into system and user levels.

System Level: 
System-level settings are valid for all users. You can view the maximum file limit of the system in two ways.
1CAT/proc/sys/fs/file-max
2Sysctl-Check the number of FS. File-Max configurations in the result.
Modify the/etc/sysctl. conf file and configure the fs. File-Max attribute if the attribute does not exist.
UseSysctl-PTo notify the system to enable this configuration.

User level: 
Linux limits the number of accessible files for each login user. AvailableUlimit-nTo view the current valid settings. If you want to modify this value, useUlimit-n <setting number>Command.

We recommend that you use the power of 2 to increase the proportion of file descriptors. If the number of file descriptors is 1024, it can be increased to 2048. If not, it can be set to 4096, and so on.

After the too program open files problem occurs, you must first find out the main cause. The biggest possible reason is that the opened file or socket is not properly closed. To locate whether the problem is caused by a Java Process, use the Java Process number to view the file descriptor occupied by the current process:

Java code  
  1. Lsof-p $ attributes of each file descriptor of java_pid
  2. Lsof-p $ java_pid | Total number of FD in the file descriptor table of the current Java Process WC-l


Analyze the command results to determine whether the problem is caused by abnormal resource release.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.