Too many open files (too much open file) workaround

Source: Internet
Author: User
I. Reasons for the formation of

Too many open files (too much open file) is a common error in Linux systems, which literally means that the program has too many open files, but the files here are not just the meaning of the file, but also the open communication links (such as sockets), the ports being monitored, etc. , so sometimes it can also be called a handle (handle), and this error can often be called a handle that exceeds the system limit.
This is caused by the fact that at some point in time the process has opened the number of files exceeding the system limit and the number of communication links, and the command ulimit-a can view the maximum number of handles for the current system setting:

[Tomcat@localhost bin]$ ulimit-a
core file size          (blocks,-c) 0
data seg size           (Kbytes,-D) Unlimited
Scheduling Priority             (-e) 0
file size               (blocks,-f) Unlimited pending signals (-I                 ) 14732
Max Locked Memory       (Kbytes, L)
max memory size         (Kbytes, m) Unlimited
open files (-                      N) 1024
Pipe Size            (bytes, p) 8
POSIX message Queues     (bytes,-q) 819200
real-time Priority              (-R) 0
stack size< c23/> (Kbytes,-s) 10240
CPU time               (seconds,-T) unlimited
max User Processes              (-u) 1024
virtual Memory          (Kbytes,-V) unlimited
file Locks                      (-X) Unlimited
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16-17

The open files line represents the maximum number of handles that the system currently allows a single process to open, here is 1024.
Use the command lsof-p process ID to view all open file details for a single process, using the command lsof-p process ID | Wc-l can count how many files the process has opened:

[Tomcat@localhost bin]$ JPS
3092 Bootstrap
3197 JPS
[tomcat@localhost bin]$ lsof-p 3092 | wc-l
108
1 2 3 4 5

As an example of a bare-boot tomcat, you can see that it currently has 108 files open, and you can use Lsof-p process ID > Openfiles.log to export the execution results to a log file if the number of files is too large to be fully viewed using the Lsof-p Process ID command. Ii. Solutions 1. Increase the number of files allowed to open--command mode

Ulimit-n 2048
1

This sets the maximum allowable number of open files for the current user to 2048, but this setting is restored to the default value after the reboot.
The Ulimit-n command can only be set to 4096 for non-root users.
If you want to set to 8192 you need sudo permission or root user. 2, increase the number of files allowed to open--Modify the system configuration file

vim/etc/security/limits.conf  
#在最后加入  
* Soft nofile 4096  
* Hard nofile 4096  
1 2 3 4

or just Join

*-Nofile 8192
1

The top * represents all users and can set a user as needed, such as

Roy Soft Nofile 8192  
Roy Hard Nofile 8192  
1 2

Note that there are two possible restrictions on the "Nofile" item. Is the hard and soft under the item. For the maximum number of open files that have been modified to take effect, you must set both limits. If you use the "-" character setting, the hard and soft settings will be set at the same time. 3, check the procedure problem

If you have a certain solution to your program, you should open the number of files (number of links) to the upper limit of a certain estimate, if you feel the number is abnormal, please use the first step of the lsof-p process ID > Openfiles.log command, get the full details of the current occupancy handle analysis,

1 Open these files are not all necessary.
2 Locate the file to open the Code
3) whether the program operation of the file write, but did not perform a normal shutdown of
4) whether the program is communicating, but not normal shutdown (that is, no time-out mechanism)
1 2 3 4

If these problems exist in the program, regardless of the number of system handles set how large, as time goes on, will certainly occupy the end.

Original link: https://blog.csdn.net/Roy_70/article/details/78423880

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.