오래전 부터 고민이 있었다.
모니터링 시스템을 볼 때 마다 오후 쯤 file open 수가 점점 증가하는 것이었다.
결국에는 다음과 같은 오류를 내면서 장애
java.io.IOException: java.io.IOException: Too many open files
아뿔사..
드디어 그날이 왔구나.
ulimit 로 파일 오픈 셋팅을 보니 16000 .. 무리 없는 셋팅
구글링 끝에 lsof 이라는 명령어를 루트로 실행하면 현 상태를 파악 할 수 있을 것이라는 것만을 알게 되었다.
pipe
pipe
pipe
모든 FD가 파이프 여는데 사용되고 있었다.
코드에서 파이프를 사용하는 곳은 한군데
바로 ProcessBuilder !!!
비교 코드 들어간다.
ProcessBuilder builder = new ProcessBuilder( command );
process = builder.start();
process.waitFor()
으흠 도통 할 수가 없어서 API 문서를 살펴 보았다.
이것보다는 Process의 API 문서가 더 도움될 것 같은데..
눈에 띈 부분이 맘에 걸렸다.
destory...
destory()
destory()
으흠 이런거 해주는 코드 자체가 없는데
구글링 해보니 inputstream, outputstream, errorstream 를 종종 열어두는 경우가 발생한다는!!!
이거닷!
혹시나 해서 Utillity class가 있나 싶어서 찾아보았지만 없었다.
그래서 그냥 하나 만들었다. ㅋㅋ
public class ProcessExecutor {
private static final Logger LOG = Logger.getLogger(ProcessExecutor.class);
public static int execute(List<String> command) {
Process process = null;
try {
ProcessBuilder builder = new ProcessBuilder( command );
process = builder.start();
LOG.debug(StringUtils.join(builder.command().toArray()," "));
if (0 != process.waitFor()){
LOG.info("Command Execute Fail");
LOG.info(StringUtils.join(builder.command().toArray()," "));
}
return process.exitValue();
} catch (IOException e) {
LOG.info(StringUtils.join(command.toArray()," "));
throw new RuntimeException(e);
} catch (InterruptedException e) {
LOG.info(StringUtils.join(command.toArray()," "));
throw new RuntimeException(e);
} finally {
if ( null != process) {
IOUtils.closeQuietly(process.getInputStream());
IOUtils.closeQuietly(process.getOutputStream());
IOUtils.closeQuietly(process.getErrorStream());
process.destroy();
} else {
LOG.fatal(StringUtils.join(command.toArray()," "));
LOG.fatal("Cannot close Process Streams");
throw new RuntimeException("Cannot close Process Streams");
}
}
}
}
생각보다 기네..
아직 까지는 별 문제 없이 잘 돌고 있다..
특히 모니터링에서 너무 이쁜 그래프~
'direct' 카테고리의 다른 글
| ProcessBuilder 사용시 주의 사항 (1) | 2009/08/24 |
|---|---|
| 득템? 득녀 했습니다. (2) | 2009/05/31 |
| 책홍보.. 프로스프링 2.5 (2) | 2009/04/30 |
| CSS Naked Day~! (2) | 2009/04/09 |


