서버 프로그램 개발시에 운영체제의 메모리,스레드,파일 디스크립터, 프로세스 최대 지원 개수를 점검하는 간단한 방법을 소개한다.

일반적으로

항목 원도우 Linux
메모리 4G Byte 2.0.x : 1G Byte
2.2.x : 2G Byte
2.4.x : 64G Byte
최대 스레드 제한없음 기본설정 : 1024
변경가능
파일 디스크립트 제한없음 기본설정 : 1024
변경가능

1. checkpf.jar 다운로드

2. 메모리 점검

  • Usage

    [www@ihelpers dist]$ java -cp ./checkpf.jar checkpf.MemConsumer 128
    Allocated : 12
    Max : 63
    Total : 14
    Left : 2
    Allocated : 24
    Max : 63
    Total : 25
    Left : 1
    Allocated : 36
    Max : 63
    Total : 43
    Left : 7
    Allocated : 48
    Max : 63
    Total : 63
    Left : 15
    Allocated : 60
    Max : 63
    Total : 63
    Left : 3
    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
            at checkpf.MemConsumer.main(MemConsumer.java:34)
    [www@ihelpers dist]$ java -cp ./checkpf.jar checkpf.MemConsumer 64

    128MB 짜리 배열을 생성하면 에러가 발생한다. 아래와 같이 최대 메모리를 128MB로 잡아주면 에러 없이 생행이 될수 있습니다. 자바 Virtual Machine 의 메모리를 너무 크게 잡게 되면 디스크 스와핑과 Garagage Collection 이 많이 발생하여 서버의 성능이 현저하게 떨어지게 됩니다. 자바 VM 최대 메모리는 물리적 메모리 보다 작게 하고 프로그램에서는 VM 최대 메모리의 약 70% 이하로 사용하는 것이 좋습니다.

    [www@ihelpers dist]$ java -Xmx128m -cp ./checkpf.jar checkpf.MemConsumer 128
    Allocated : 12
    Max : 127
    Total : 14
    Left : 2
    Allocated : 24
    Max : 127
    Total : 25
    Left : 1
    Allocated : 36
    Max : 127
    Total : 43
    Left : 7
    Allocated : 48
    Max : 127
    Total : 75
    Left : 27
    Allocated : 60
    Max : 127
    Total : 75
    Left : 15

  • java options

[www@ihelpers dist]$ java -X
    -Xmixed           mixed mode execution (default)
    -Xint             interpreted mode execution only
    -Xbootclasspath:<directories and zip/jar files separated by :>
                      set search path for bootstrap classes and resources
    -Xbootclasspath/a:<directories and zip/jar files separated by :>
                      append to end of bootstrap class path
    -Xbootclasspath/p:<directories and zip/jar files separated by :>
                      prepend in front of bootstrap class path
    -Xnoclassgc       disable class garbage collection
    -Xincgc           enable incremental garbage collection
    -Xloggc:<file>    log GC status to a file with time stamps
    -Xbatch           disable background compilation
    -Xms<size>        set initial Java heap size
    -Xmx<size>        set maximum Java heap size
    -Xss<size>        set java thread stack size
    -Xprof            output cpu profiling data
    -Xfuture          enable strictest checks, anticipating future default
    -Xrs              reduce use of OS signals by Java/VM (see documentation)
    -Xcheck:jni       perform additional checks for JNI functions
    -Xshare:off       do not attempt to use shared class data
    -Xshare:auto      use shared class data if possible (default)
    -Xshare:on        require using shared class data, otherwise fail.

3. 파일 디스크립터

  • Usage

    [www@ihelpers dist]$ java -cp ./checkpf.jar checkpf.FDConsumer 2000
    ...

    File Descriptor : 1012
    File Descriptor : 1013
    File Descriptor : 1014
    File Descriptor : 1015
    java.io.IOException: Too many open files


    이에 대한 설정 변경 내용은 참고를 참조해 주십시요.

3. 참고