커피닉스, 시스템 엔지니어의 쉼터
  Too many open files 에러발생시 작성일 : 2006/07/11 14:51
 
  • 글쓴이 : 좋은진호 ( http://coffeenix.net/ )
  • 조회수 : 33126
     
    제  목 : Too many open files 에러발생시
    작성자 : 좋은진호(truefeel, http://coffeenix.net/ )
    작성일 : 2006.7.10(월)

    자바에서 다음과 같은 에러가 발생했다면 FD(File Descriptor)를 늘려줘야 한다.

     
    java.net.SocketException: Too many open files
            at java.net.PlainSocketImpl.socketAccept(Native Method)
            at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:353)
            at java.net.ServerSocket.implAccept(ServerSocket.java:448)
            at java.net.ServerSocket.accept(ServerSocket.java:419)
    ... 생략 ...
     


    1. open files 최대 개수 확인

    먼저 ulimit -a 으로 open files 개수를 확인한다. ulimit -aH는 hard limit, -aS는 sort limit를 확인.
    csh 쉘을 사용하면 limit 명령으로 살펴볼 수 있다.

     
    $ ulimit -a
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 1024
    max locked memory       (kbytes, -l) 32
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    stack size              (kbytes, -s) 10240
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 69632
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
     


    2. 프로세스별로 오픈된 파일 개수 확인

    열린 파일

    lsof 명령으로 확인할 수 있다. 지정한 프로세스가 몇개의 파일을 사용중인지를 확인할 때는 다음처럼 실행
    하면 알 수 있다.

    lsof -p PID | wc -l

    1234, 1236 PID 2개에 대해 살펴본다면 콤마(,)로 PID를 구분해서 적어주면 된다.

     
    $ lsof -p 1234,1236 |wc -l
     


    3. 파일개수 늘리기

    리눅스환경을 기준으로 설명한다. truefeel 사용자의 open files개수를 4096(sort limit),
    6144(hard limit) 로 제한한다면 /etc/security/limits.conf에 다음 줄을 추가해주면 로긴시 적용된다.

     
    truefeel         soft    nofile          4096
    truefeel         hard    nofile          6144
     


    4. 참고 자료

    * Too Many Open Files Exception
      http://kr.bea.com/files/services/customer_support/best_tip/06_200406/06_2_14.pdf

    * Too many open files
      http://kr.bea.com/services/customer_support/SupportPattern/08_15_Too_Many_Open_Files_Pattern.html


    커피닉스, 시스템 엔지니어의 쉼터 / URL : http://coffeenix.net/board_view.php?bd_code=1422