当前位置:网站首页>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 )
边栏推荐
- How does unity fixedupdate call at a fixed frame rate
- 高斯消元 AcWing 883. 高斯消元解线性方程组
- [rust notes] 11 practical features
- Binary tree sorting (C language, int type)
- Pit & ADB wireless debugging of vivo real machine debugging
- producer consumer problem
- Unity Editor Extension - event handling
- Slice and index of array with data type
- Log4j2 vulnerability recurrence and analysis
- Really explain the five data structures of redis
猜你喜欢
Unity editor expansion - draw lines
Monotonic stack -42 Connect rainwater
Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
Six dimensional space (C language)
On the setting of global variable position in C language
Servlet的生命周期
UE4 source code reading_ Mobile synchronization
Binary tree sorting (C language, char type)
Binary tree traversal (first order traversal. Output results according to first order, middle order, and last order)
too many open files解决方案
随机推荐
Alibaba canal actual combat
求组合数 AcWing 885. 求组合数 I
Vscode, idea, VIM development tool shortcut keys
求组合数 AcWing 886. 求组合数 II
Solution of 300ms delay of mobile phone
[RPC] RPC remote procedure call
22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令
I made mistakes that junior programmers all over the world would make, and I also made mistakes that I shouldn't have made
Unity notes 1
C language student management system based on linked list, super detailed
Unity Editor Extension - Outline
Concurrent programming (III) detailed explanation of synchronized keyword
On the setting of global variable position in C language
[concurrent programming] consistency hash
[rust notes] 08 enumeration and mode
MySQL three logs
DOM 渲染系统(render mount patch)响应式系统
Common DOS commands
22-06-28 Xi'an redis (02) persistence mechanism, entry, transaction control, master-slave replication mechanism
Unity editor expansion - controls, layouts