当前位置:网站首页>Too many open files solution
Too many open files solution
2022-07-03 08:52:00 【Clovemeo】

The test environment appeared after running for a period of time too many open files, Lead to a regular report redis Tasks of frequently fail .
linux The default is 1024, It can be done by ulimit -n Command quantity adjustment .
example :ulimit -n 4096
Not root Users can only set it to 4096, If you need more, you need root jurisdiction .
Carry out orders ps -ef | grep java, Find out the process id:13945.

perform lsof -p 13945
It is found that a large number of file handles have not been released . It is suspected that the small partner in the group did not traverse the file close Lead to .
So look for clues from the code .
The reason for the discovery is delete The method uses DirectoryStream did not close.
java8 Inside Files.newDirectoryStream(p), It's usually usedtry(Files.newDirectoryStream()){ } catch() { }The way , To avoid explicit close Release resources .
So judge the classmate who wrote this code at that time Files.newDirectoryStream() Example time , I can't see close() Method mistakenly thinks that you don't need to release files to use directly . Led to too many open files It's abnormal .Another thing to note , stay try() File opened in , Do not delete , Otherwise, the handle cannot be released . for example :
try(InputStream inputStream = new FileInputStream(new File(path))) { // doSomething(); } catch(Exception e) { }finally{ Files.deleteIfExists(Paths.get(path)); }It will lead to the following results :

File handle not released
summary :
encounter too many open files when ,- perform lsof -p <pid>, View the handle opened by the process
If the number of handles is abnormal , Then check the cause of abnormality according to the open handle , If the handle is normal , Then proceed to the second step as follows . perform unlimit -a, see open files( The maximum number of files allowed to be opened )

边栏推荐
- Pit & ADB wireless debugging of vivo real machine debugging
- Parameters of convolutional neural network
- Escape from heaven and forget what he suffered. In ancient times, it was called the punishment of escape from heaven. Article collection
- MySQL three logs
- [rust notes] 09- special types and generics
- Unity editor expansion - draw lines
- Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
- createjs easeljs
- [rust notes] 11 practical features
- Unity editor expansion - window, sub window, menu, right-click menu (context menu)
猜你喜欢

Graphics_ Learnopongl learning notes
![[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q](/img/76/6561a78b7f883a0e75a53e037153c3.jpg)
[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q

22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令

Analysis of Alibaba canal principle

Binary tree sorting (C language, int type)

Deep parsing JVM memory model

22-06-28 Xi'an redis (02) persistence mechanism, entry, transaction control, master-slave replication mechanism

Format - C language project sub file

【Rust笔记】02-所有权

Phpstudy 80 port occupied W10 system
随机推荐
Visual Studio (VS) shortcut keys
Deeply understand the underlying data structure of MySQL index
Notes on understanding applets 2022/7/3
22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
Message queue for interprocess communication
Binary tree traversal (first order traversal. Output results according to first order, middle order, and last order)
Development material set
MySQL index types B-tree and hash
Query XML documents with XPath
数据库原理期末复习
【Rust 笔记】09-特型与泛型
Message pack in C deserializes array objects
Markdown learning
Binary tree sorting (C language, int type)
22-06-28 Xi'an redis (02) persistence mechanism, entry, transaction control, master-slave replication mechanism
Really explain the five data structures of redis
Mortgage Calculator
Unity editor expansion - window, sub window, menu, right-click menu (context menu)
Baidu editor ueeditor changes style
Servlet的生命周期




