【JVM】小记Linux下的一次JVM性能调优经过          返回主页

背景阐述:

    环境 : ubuntu server 14.04
        JDK1.7
        TOMCAT7
    使用默认配置导致出现OOM异常。

解决方式:

初始设置

    1. 首先设置tomcat启动选项:
    修改TOMCAT_HOME/bin/catalina.sh
    位置cygwin=false前。
    JAVA_OPTS="-server -Xms256m -Xmx512m -XX:PermSize=64M -XX:MaxPermSize=128m" 

    注意,此处:
    -Xms:java Heap初始大小。 默认是物理内存的1/64。
    -Xmx:java heap最大值。建议均设为物理内存的一半。不可超过物理内存。
     

    -XX:PermSize:设定内存的永久保存区初始大小,缺省值为64M。
    -XX:MaxPermSize:设定内存的永久保存区最大 大小,缺省值为64M。
    2. 这里,服务器的物理内存为4GB,经过计算,得出初始大小为1/64*4096=64MB,
    最大值为2GB,设置为1GB即可。

调优指令:

1. 首先需要查看VM进程PID:jps -L

    root@:~/Desktop/tomcat/bin# jps -l
    3375 sun.tools.jps.Jps
    3025 org.apache.catalina.startup.Bootstrap

2. 这里得到tomcat对应的PID:3025

3. 查看某个进程的内存情况

        a. Jstat -gcutil pid
          S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT
          0.00  93.77  52.11  72.68  17.87    161    0.835     0    0.000    0.835

        解释:新生代(Eden区)使用率52.11%
            老生代使用72.68%,永久代使用17.87%。
            Young GC发生168次,full GC发生0次。
            Young GC时间为0.835秒,GC总用时为0.835秒

4. 实时查看调整JVM各项参数

    jps -v (查看启动参数)3025
Bootstrap -Djava.util.logging.config.file=/root/Desktop/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms256m -Xmx1024m -Xss1024K -XX:PermSize=256m -XX:MaxPermSize=512m -Djava.endorsed.dirs=/root/Desktop/tomcat/endorsed -Dcatalina.base=/root/Desktop/tomcat -Dcatalina.home=/root/Desktop/tomcat -Djava.io.tmpdir=/root/Desktop/tomcat/temp
3502 Jps -Dapplication.home=/usr/lib/jvm/java-7-openjdk-amd64 -Xms8m
 5. 查看JVM的系统设置  jinfo -sysprops {PID}
    Attaching to process ID 3025, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 24.95-b01
    java.runtime.name = OpenJDK Runtime Environment
    java.vm.version = 24.95-b01
    sun.boot.library.path = /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64
    shared.loader =
    java.vendor.url = http://java.oracle.com/
    java.vm.vendor = Oracle Corporation
    path.separator = :
    file.encoding.pkg = sun.io
    java.vm.name = OpenJDK 64-Bit Server VM
    java.util.logging.config.file = /root/Desktop/tomcat/conf/logging.properties
    tomcat.util.buf.StringCache.byte.enabled = true
    sun.os.patch.level = unknown
    sun.java.launcher = SUN_STANDARD
    user.country = US
    tomcat.util.scan.StandardJarScanFilter.jarsToScan = log4j-core*.jar,log4j-taglib*.jar,log4javascript*.jar
    user.dir = /root/Desktop/tomcat/bin
    java.vm.specification.name = Java Virtual Machine Specification
    java.runtime.version = 1.7.0_101-b00
    java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
    os.arch = amd64
    java.endorsed.dirs = /root/Desktop/tomcat/endorsed
    line.separator =

    java.io.tmpdir = /root/Desktop/tomcat/temp
    java.vm.specification.vendor = Oracle Corporation
    java.util.logging.manager = org.apache.juli.ClassLoaderLogManager
    java.naming.factory.url.pkgs = org.apache.naming
    os.name = Linux
    sun.jnu.encoding = UTF-8
    java.library.path = /usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
    java.class.version = 51.0
    java.specification.name = Java Platform API Specification
    sun.management.compiler = HotSpot 64-Bit Tiered Compilers
    os.version = 3.13.0-92-generic
    user.home = /root
    user.timezone = Asia/Shanghai
    catalina.useNaming = true
    java.awt.printerjob = sun.print.PSPrinterJob
    file.encoding = UTF-8
    java.specification.version = 1.7
    tomcat.util.scan.StandardJarScanFilter.jarsToSkip = bootstrap.jar,commons-daemon.jar,tomcat-juli.jar,annotations-api.jar,el-api.jar,jsp-api.jar,servlet-api.jar,websocket-api.jar,catalina.jar,catalina-ant.jar,catalina-ha.jar,catalina-storeconfig.jar,catalina-tribes.jar,jasper.jar,jasper-el.jar,ecj-*.jar,tomcat-api.jar,tomcat-util.jar,tomcat-util-scan.jar,tomcat-coyote.jar,tomcat-dbcp.jar,tomcat-jni.jar,tomcat-websocket.jar,tomcat-i18n-en.jar,tomcat-i18n-es.jar,tomcat-i18n-fr.jar,tomcat-i18n-ja.jar,tomcat-juli-adapters.jar,catalina-jmx-remote.jar,catalina-ws.jar,tomcat-jdbc.jar,tools.jar,commons-beanutils*.jar,commons-codec*.jar,commons-collections*.jar,commons-dbcp*.jar,commons-digester*.jar,commons-fileupload*.jar,commons-httpclient*.jar,commons-io*.jar,commons-lang*.jar,commons-logging*.jar,commons-math*.jar,commons-pool*.jar,jstl.jar,taglibs-standard-spec-*.jar,geronimo-spec-jaxrpc*.jar,wsdl4j*.jar,ant.jar,ant-junit*.jar,aspectj*.jar,jmx.jar,h2*.jar,hibernate*.jar,httpclient*.jar,jmx-tools.jar,jta*.jar,log4j*.jar,mail*.jar,slf4j*.jar,xercesImpl.jar,xmlParserAPIs.jar,xml-apis.jar,junit.jar,junit-*.jar,ant-launcher.jar,cobertura-*.jar,asm-*.jar,dom4j-*.jar,icu4j-*.jar,jaxen-*.jar,jdom-*.jar,jetty-*.jar,oro-*.jar,servlet-api-*.jar,tagsoup-*.jar,xmlParserAPIs-*.jar,xom-*.jar
    catalina.home = /root/Desktop/tomcat
    user.name = root
    java.class.path = /root/Desktop/tomcat/bin/bootstrap.jar:/root/Desktop/tomcat/bin/tomcat-juli.jar
    java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory
    package.definition = sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.naming.,org.apache.tomcat.
    java.vm.specification.version = 1.7
    sun.arch.data.model = 64
    sun.java.command = org.apache.catalina.startup.Bootstrap start
    java.home = /usr/lib/jvm/java-7-openjdk-amd64/jre
    user.language = en
    java.specification.vendor = Oracle Corporation
    awt.toolkit = sun.awt.X11.XToolkit
    java.vm.info = mixed mode
    java.version = 1.7.0_101
    java.ext.dirs = /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext:/usr/java/packages/lib/ext
    sun.boot.class.path = /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/resources.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jsse.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jce.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/charsets.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/rhino.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/jfr.jar:/usr/lib/jvm/java-7-openjdk-amd64/jre/classes
    server.loader =
    java.vendor = Oracle Corporation
    catalina.base = /root/Desktop/tomcat
    file.separator = /
    java.vendor.url.bug = http://bugreport.sun.com/bugreport/
    common.loader = "${catalina.base}/lib","${catalina.base}/lib/*.jar","${catalina.home}/lib","${catalina.home}/lib/*.jar"
    sun.io.unicode.encoding = UnicodeLittle
    sun.cpu.endian = little
    package.access = sun.,org.apache.catalina.,org.apache.coyote.,org.apache.jasper.,org.apache.tomcat.
    sun.cpu.isalist =

6. 小结

本文讲解了linux 下的tomcat性能优化,从参数的设置到性能的查看再到基本的java优化指令。完整的介绍了基本的jvm性能优化过程。希望能对读者有所帮助。