티스토리 뷰
오류 메시지 : jar파일은 바뀜
java.io.FileNotFoundException : /usr~~~/ .jar (열린 파일이 너무 많음)
too many files opens
1. 오류 발생 원인
오류는 Too many open files로 제한된 file descriptor의 개수를 초과하여 발생
ulimit -a 로 현재 설정된 open file 한계치 확인
2. 발생 원인 분석
2-1) 일시적으로 과부하에 의한 것인지?
설정된 FD가 적고 일시적 과부인 경우는 FD 개수를 늘려서 해결
2-2) File descriptor가 누적되어 발생한 것인지 ?
통신(socket..), input/out stream , 파일 등에서 close가 제대로 되지 않아 발생합니다.
Close가 되지 않으므로 누적되어 제한된 FD개수를 초과한 것입니다.
선행적으로 FD의 정보를 확인하시기 바랍니다. 해지 되지 않고 지속적으로 증가되는지 파악이 필요합니다.
물론, 의심되는 서비스를 호출하여 FD가 증가되지는 확인하는 것이 빠릅니다.
지속적으로 fd 수가 증가할 경우는 코드에서 문제가 발생한 것입니다.
이 경우는 해당 원인이 되는 코드를 수정해야 합니다.
테스트 및 체크 방법
1. File not close 서비스 개발
- 일부러 파일을 close하지 않음
@RequestMapping("notclosefile")
public void doService() throws ServiceException {
String path = axb2ServiceManager.getServicePath();
System.out.println("path="+path);
File file = new File(path+"/h2_sample/merge.xml");
try { FileInputStream fileInputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block e.printStackTrace();
}
}
2. centos에서 FD 체크
$ ls -l /proc/19586/fd
total 0
lr-x------ 1 tobesoft tobesoft 64 Jun 18 10:21 0 -> /dev/null ~~~
l-wx------ 1 tobesoft tobesoft 64 Jun 18 10:21 1 -> /home/tobesoft/apache-tomcat-7.0.33/logs/catalina.out lr-x------ 1 tobesoft tobesoft 64 Jun 18 10:22 118 -> /home/tobesoft/apache-tomcat-7.0.33/webapps/nexup/WEB-INF/service/h2_sample/merge.xml
lr-x------ 1 tobesoft tobesoft 64 Jun 18 10:23 119 -> /home/tobesoft/apache-tomcat-7.0.33/webapps/nexup/WEB-INF/service/h2_sample/merge.xml ~~
lr-x------ 1 tobesoft tobesoft 64 Jun 18 10:22 52 -> /home/tobesoft/apache-tomcat-7.0.33/webapps/nexup/WEB-INF/service/h2_sample/merge.xml
중복 체크 확인 함
3. File Leack Detector 로 체크
opensource로 제공됨 : http://file-leak-detector.kohsuke.org/
Usage :
java -javaagent:path/to/file-leak-detector.jar=http=19999
> 19999 port 로 로그가 나옴
Browser로 http://ip:19999로 연결시 열려 있는 file 정보를 알려준다.
아래 실제 정보 정리
#17 /home/tobesoft/apache-tomcat-7.0.33/webapps/nexup/WEB-INF/service/h2_sample/merge.xml by thread:http-bio-8081-exec-5 on Tue Jun 18 10:23:23 KST 2019 at java.io.FileInputStream.<init>(FileInputStream.java:139) at nexacro.sample.NotCloseFileController.doService(NotCloseFileController.java:31)
~~
#29 /home/tobesoft/apache-tomcat-7.0.33/webapps/nexup/WEB-INF/service/h2_sample/merge.xml by thread:http-bio-8081-exec-10 on Tue Jun 18 10:22:17 KST 2019 at java.io.FileInputStream.<init>(FileInputStream.java:139) at nexacro.sample.NotCloseFileController.doService(NotCloseFileController.java:31)
~~
#32 /home/tobesoft/apache-tomcat-7.0.33/webapps/nexup/WEB-INF/service/h2_sample/merge.xml by thread:http-bio-8081-exec-10 on Tue Jun 18 10:22:03 KST 2019 at java.io.FileInputStream.<init>(FileInputStream.java:139) at nexacro.sample.NotCloseFileController.doService(NotCloseFileController.java:31)
file-leak-detector option
File leak detector arguments (to specify multiple values, separate them by ',': help - show the help screen. trace - log every open/close operation to stderr. trace=FILE - log every open/close operation to the given file. error=FILE - if 'too many open files' error is detected, send the dump here. by default it goes to stderr. threshold=N - instead of waiting until 'too many open files', dump once we have N descriptors open. http=PORT - Run a mini HTTP server that you can access to get stats on demand Specify 0 to choose random available port, -1 to disable, which is default. strong - Don't let GC auto-close leaking file descriptors listener=S - Specify the fully qualified name of ActivityListener class to activate from beginning dumpatshutdown- Dump open file handles at shutdown excludes=FILE - Ignore files opened directly/indirectly in specific methods. File lists 'some.pkg.ClassName.methodName' patterns.
- Total
- Today
- Yesterday
- #User Guide
- user guide
- chrome
- native image
- GraalVM
- #Transaction
- nexacro
- 챗봇
- telegram
- 도서
- #BCI
- #ASM
- #번역
- #IOC
- 대출
- chatbot
- bytecode
- javaaent
- Java
- #MyBatos
- cors
- #Bean
- #SPRING
- #Dynamic Query
- 텔레그램
- ASM
- native-image
- javaagent
- #JAVA
- 번역
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |