`
85977328
  • 浏览: 1903626 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JVM内存分析系列(十一)GC基本情况与CMS垃圾收集器调优

 
阅读更多
初始标记
CMS-initial-mark
并发标记
CMS-concurrent-mark
CMS-concurrent-preclean
CMS-concurrent-abortable-preclean
重新标记
CMS-remark
并发清理
CMS-concurrent-sweep
重置线程
CMS-concurrent-reset


其中preclean该步用于重新扫描在concurrent mark阶段CMS Heap中被新创建的对象或从新生代晋升到旧生代对象的引用关系,以减少remark所需耗费的时间,这是Sun JDK 1.5后增加的一个优化步骤。

可选参数
-XX:CMSInitiatingOccupancyFraction=85(触发FULL GC的老年代使用百分比)
-XX:CMSFullGCsBeforeCompaction=5(多少次后进行内存压缩)
-XX:ParallelGCThreads=8(并发标记和清除时的线程数)

其他参数
-XX:+UseCMSInitiatingOccupancyOnly 使用手动定义初始化定义开始CMS收集


CMS触发参数与条件(与eden区有关系)
-XX:CMSScheduleRemarkEdenSizeThreshold=2M
-XX:CMSScheduleRemarkEdenPenetration=50
-XX:CMSMaxAbortablePrecleanTime=5000(单位为毫秒)

当eden space占用超过CMSScheduleRemarkEdenSizeThreshold时,执行此步,并且将一直并发的执行到eden space的使用率超过CMSScheduleRemarkEdenPenetration,之后触发remark动作,过CMSMaxAbortablePrecleanTime时间扔为达到要求,则直接触发CMS-remark

常用的优化配置示例
#!/bin/bash

SERVER_HOME="/application/search/server"
CONF_HOME="/application/search/server/conf"
LOG_HOME="/data0/search/server"
CURRENT_TIME=`date +%Y-%m-%d_%H:%M:%S`

java -server -verbose:gc -Xms512m -Xmx512m -Xmn192m -XX:PermSize=32m -XX:MaxPermSize=32m -Xss256k -XX:+UseConcMarkSweepGC -XX:ParallelGCThreads=4 -XX:+UseCMSCompactAtFullCollection -XX:CMSMaxAbortablePrecleanTime=5000 -XX:CMSFullGCsBeforeCompaction=5 -XX:CMSInitiatingOccupancyFraction=85 -XX:+UseParNewGC -Xloggc:${LOG_HOME}/logs/gc.${CURRENT_TIME}.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${LOG_HOME}/logs/HeapDumpOnOutOfMemoryError.${CURRENT_TIME}.log -XX:+DisableExplicitGC -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -cp ${SERVER_HOME}/server.jar:${SERVER_HOME}/lib/* -DCONF_HOME=${CONF_HOME} -DLOG_HOME=${LOG_HOME} com.chinaso.search.Server >>${LOG_HOME}/logs/console.log 2>&1 &




案例一:空跑
package com.chinaso.phl;


/**
 * -Xms20m -Xmx20m -Xmn10m -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCMSInitiatingOccupancyOnly  
 * @author piaohailin
 * @date   2014-1-15
*/
public class Server0 {

    /**
     * 
     * @param args
     * @author piaohailin
     * @date   2014-1-15
    */
    public static void main(String[] args) throws Exception {
    }

}

/*
Heap
par new generation   total 9216K, used 507K [0x00000000f9a00000, 0x00000000fa400000, 0x00000000fa400000)
 eden space 8192K,   6% used [0x00000000f9a00000, 0x00000000f9a7eee0, 0x00000000fa200000)
 from space 1024K,   0% used [0x00000000fa200000, 0x00000000fa200000, 0x00000000fa300000)
 to   space 1024K,   0% used [0x00000000fa300000, 0x00000000fa300000, 0x00000000fa400000)
concurrent mark-sweep generation total 10240K, used 0K [0x00000000fa400000, 0x00000000fae00000, 0x00000000fae00000)
concurrent-mark-sweep perm gen total 21248K, used 3033K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
*/

空跑eclipse的时候,占用了507K的新生代空间,老生代无任何数据。持久代使用了3033K空间。其中默认值遵循了eden:survival=8:1的原则。

案例二:验证对象大小
package com.chinaso.phl;


/**
 * -Xms20m -Xmx20m -Xmn10m -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCMSInitiatingOccupancyOnly  
 * @author piaohailin
 * @date   2014-1-15
*/
public class Server1 {

    /**
     * 
     * @param args
     * @author piaohailin
     * @date   2014-1-15
    */
    public static void main(String[] args) throws Exception {
        byte[] b1 = getM(2);
        byte[] b2 = getM(2);
        byte[] b3 = getM(2);
//        System.out.println("minor gc");
//        byte[] b4 = getM(2);
    }

    public static byte[] getM(int m) {
        return new byte[1024 * 1024 * m];
    }

}
/*
Heap
 par new generation   total 9216K, used 6651K [0x00000000f9a00000, 0x00000000fa400000, 0x00000000fa400000)
  eden space 8192K,  81% used [0x00000000f9a00000, 0x00000000fa07ef10, 0x00000000fa200000)
  from space 1024K,   0% used [0x00000000fa200000, 0x00000000fa200000, 0x00000000fa300000)
  to   space 1024K,   0% used [0x00000000fa300000, 0x00000000fa300000, 0x00000000fa400000)
 concurrent mark-sweep generation total 10240K, used 0K [0x00000000fa400000, 0x00000000fae00000, 0x00000000fae00000)
 concurrent-mark-sweep perm gen total 21248K, used 3034K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
*/

新生代使用的空间为6651K = 507 + 2048 * 3,所以新分配的3个2M对象,占用了6M的空间。但是没有发生GC,如果再分配一个2M对象,就会超出eden空间进行一次minor gc。

案例三:minor GC
package com.chinaso.phl;

/**
 * -Xms20m -Xmx20m -Xmn10m -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCMSInitiatingOccupancyOnly  
 * @author piaohailin
 * @date   2014-1-15
*/
public class Server2 {

    /**
     * 
     * @param args
     * @author piaohailin
     * @date   2014-1-15
    */
    public static void main(String[] args) throws Exception {
        byte[] b1 = getM(2);
        byte[] b2 = getM(2);
        byte[] b3 = getM(2);
        System.out.println("minor gc");
        byte[] b4 = getM(2);//执行这一行的时候就会GC
    }

    public static byte[] getM(int m) {
        return new byte[1024 * 1024 * m];
    }

}
/*
minor gc
0.108: [GC 0.109: [ParNew: 6487K->173K(9216K), 0.0048546 secs] 6487K->6319K(19456K), 0.0049077 secs] [Times: user=0.03 sys=0.00, real=0.00 secs] 
Heap
 par new generation   total 9216K, used 2385K [0x00000000f9a00000, 0x00000000fa400000, 0x00000000fa400000)
  eden space 8192K,  27% used [0x00000000f9a00000, 0x00000000f9c28fd8, 0x00000000fa200000)
  from space 1024K,  16% used [0x00000000fa300000, 0x00000000fa32b500, 0x00000000fa400000)
  to   space 1024K,   0% used [0x00000000fa200000, 0x00000000fa200000, 0x00000000fa300000)
 concurrent mark-sweep generation total 10240K, used 6146K [0x00000000fa400000, 0x00000000fae00000, 0x00000000fae00000)
 concurrent-mark-sweep perm gen total 21248K, used 3039K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
*/

从内容来看,执行了一次新生代的垃圾回收操作。对象占用空间从6487K减少到173K,其中总新生代可用空间(1*eden + 1*survival)即9216K,耗时0.0048546 secs,整个堆内存的情况为闸弄空间从6487K降低到6319K,其中总可用堆大小为19456K。其中查看heap,可知道新生代已用2385K,老生代使用6146K,基本与之前分配的3个2M对象2048*3=6144相等,表明此3个对象进行minor GC后,进入了老年代。而新生代占用的空间2385中,基本与刚分配的第四个2M对象相等。下个实验,我们将触发major GC即:full gc

案例四:major GC
本案例开启参数-XX:+UseCMSInitiatingOccupancyOnly
package com.chinaso.phl;

import java.util.concurrent.TimeUnit;

/**
 * 案例四:major GC
 * -Xms20m -Xmx20m -Xmn10m -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCMSInitiatingOccupancyOnly  
 * @author piaohailin
 * @date   2014-1-15
*/
public class Server3 {

    /**
     * 
     * @param args
     * @author piaohailin
     * @date   2014-1-15
    */
    public static void main(String[] args) throws Exception {
        byte[] b1 = getM(2);
        byte[] b2 = getM(2);
        byte[] b3 = getM(2);
        System.out.println("minor gc");
        byte[] b4 = getM(2);//执行这一行的时候就会GC
        TimeUnit.SECONDS.sleep(2);

        byte[] b5 = getM(2);
        byte[] b6 = getM(2);
        System.out.println("promotion failed");
        byte[] b7 = getM(2);
        TimeUnit.SECONDS.sleep(2);
    }

    public static byte[] getM(int m) {
        return new byte[1024 * 1024 * m];
    }

}
/*
minor gc
0.102: [GC 0.102: [ParNew: 6487K->176K(9216K), 0.0049663 secs] 6487K->6322K(19456K), 0.0050174 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
promotion failed
2.110: [GC 2.110: [ParNew: 6570K->6570K(9216K), 0.0000346 secs]2.110: [CMS: 6146K->8192K(10240K), 0.0134294 secs] 12716K->12448K(19456K), [CMS Perm : 3074K->3074K(21248K)], 0.0135341 secs] [Times: user=0.02 sys=0.00, real=0.01 secs] 
2.124: [GC [1 CMS-initial-mark: 8192K(10240K)] 14496K(19456K), 0.0002687 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2.125: [CMS-concurrent-mark-start]
2.128: [CMS-concurrent-mark: 0.003/0.003 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2.128: [CMS-concurrent-preclean-start]
2.130: [CMS-concurrent-preclean: 0.002/0.002 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
2.130: [CMS-concurrent-abortable-preclean-start]
2.130: [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2.131: [GC[YG occupancy: 6304 K (9216 K)]2.131: [Rescan (parallel) , 0.0001867 secs]2.131: [weak refs processing, 0.0000054 secs] [1 CMS-remark: 8192K(10240K)] 14496K(19456K), 0.0002429 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2.131: [CMS-concurrent-sweep-start]
2.131: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2.131: [CMS-concurrent-reset-start]
2.131: [CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.092: [GC [1 CMS-initial-mark: 8192K(10240K)] 14496K(19456K), 0.0002814 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.093: [CMS-concurrent-mark-start]
4.096: [CMS-concurrent-mark: 0.003/0.003 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.096: [CMS-concurrent-preclean-start]
4.096: [CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.096: [CMS-concurrent-abortable-preclean-start]
4.096: [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.096: [GC[YG occupancy: 6304 K (9216 K)]4.096: [Rescan (parallel) , 0.0001894 secs]4.096: [weak refs processing, 0.0000050 secs] [1 CMS-remark: 8192K(10240K)] 14496K(19456K), 0.0002433 secs] [Times: user=0.00 sys=0.01, real=0.00 secs] 
4.096: [CMS-concurrent-sweep-start]
4.096: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.096: [CMS-concurrent-reset-start]
4.097: [CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 par new generation   total 9216K, used 6468K [0x00000000f9a00000, 0x00000000fa400000, 0x00000000fa400000)
  eden space 8192K,  78% used [0x00000000f9a00000, 0x00000000fa051178, 0x00000000fa200000)
  from space 1024K,   0% used [0x00000000fa300000, 0x00000000fa300000, 0x00000000fa400000)
  to   space 1024K,   0% used [0x00000000fa200000, 0x00000000fa200000, 0x00000000fa300000)
 concurrent mark-sweep generation total 10240K, used 8192K [0x00000000fa400000, 0x00000000fae00000, 0x00000000fae00000)
 concurrent-mark-sweep perm gen total 21248K, used 3082K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
*/


案例五:major GC
本案例删除参数-XX:+UseCMSInitiatingOccupancyOnly
package com.chinaso.phl;

import java.util.concurrent.TimeUnit;

/**
 * 案例五:major GC
 * -Xms20m -Xmx20m -Xmn10m -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps 
 * @author piaohailin
 * @date   2014-1-15
*/
public class Server4 {

    /**
     * 
     * @param args
     * @author piaohailin
     * @date   2014-1-15
    */
    public static void main(String[] args) throws Exception {
        byte[] b1 = getM(2);
        byte[] b2 = getM(2);
        byte[] b3 = getM(2);
        System.out.println("minor gc");
        byte[] b4 = getM(2);//执行这一行,minor GC
        TimeUnit.SECONDS.sleep(2);

        byte[] b5 = getM(2);
        byte[] b6 = getM(2);
        System.out.println("promotion failed");
        byte[] b7 = getM(2);//执行这一行,分配担保失败
        TimeUnit.SECONDS.sleep(2);
    }

    public static byte[] getM(int m) {
        return new byte[1024 * 1024 * m];
    }

}
/*
minor gc
0.106: [GC 0.106: [ParNew: 6487K->176K(9216K), 0.0050621 secs] 6487K->6322K(19456K), 0.0051125 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
2.111: [GC [1 CMS-initial-mark: 6146K(10240K)] 8620K(19456K), 0.0003830 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2.112: [CMS-concurrent-mark-start]
promotion failed
2.115: [GC 2.115: [ParNew: 6570K->6570K(9216K), 0.0000308 secs]2.115: [CMS2.117: [CMS-concurrent-mark: 0.004/0.005 secs] [Times: user=0.00 sys=0.02, real=0.00 secs] 
 (concurrent mode failure): 6146K->8192K(10240K), 0.0144718 secs] 12716K->12448K(19456K), [CMS Perm : 3074K->3074K(21248K)], 0.0145735 secs] [Times: user=0.00 sys=0.02, real=0.01 secs] 
4.094: [GC [1 CMS-initial-mark: 8192K(10240K)] 14496K(19456K), 0.0003338 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.094: [CMS-concurrent-mark-start]
4.098: [CMS-concurrent-mark: 0.004/0.004 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
4.098: [CMS-concurrent-preclean-start]
4.100: [CMS-concurrent-preclean: 0.002/0.002 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.100: [CMS-concurrent-abortable-preclean-start]
4.100: [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.102: [GC[YG occupancy: 6304 K (9216 K)]4.103: [Rescan (parallel) , 0.0001871 secs]4.103: [weak refs processing, 0.0000054 secs] [1 CMS-remark: 8192K(10240K)] 14496K(19456K), 0.0002575 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.103: [CMS-concurrent-sweep-start]
4.103: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.103: [CMS-concurrent-reset-start]
4.103: [CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 par new generation   total 9216K, used 6468K [0x00000000f9a00000, 0x00000000fa400000, 0x00000000fa400000)
  eden space 8192K,  78% used [0x00000000f9a00000, 0x00000000fa051178, 0x00000000fa200000)
  from space 1024K,   0% used [0x00000000fa300000, 0x00000000fa300000, 0x00000000fa400000)
  to   space 1024K,   0% used [0x00000000fa200000, 0x00000000fa200000, 0x00000000fa300000)
 concurrent mark-sweep generation total 10240K, used 8192K [0x00000000fa400000, 0x00000000fae00000, 0x00000000fae00000)
 concurrent-mark-sweep perm gen total 21248K, used 3082K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
*/


案例六:设置CMS的preclean超时触发
package com.chinaso.phl;

import java.util.concurrent.TimeUnit;

/**
 * 案例六:设置CMS的preclean超时触发
 * -Xms20m -Xmx20m -Xmn10m -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:CMSMaxAbortablePrecleanTime=5000 -XX:CMSScheduleRemarkEdenSizeThreshold=1M
 * @author piaohailin
 * @date   2014-1-15
*/
public class Server5 {

    /**
     * 
     * @param args
     * @author piaohailin
     * @date   2014-1-15
    */
    public static void main(String[] args) throws Exception {
        byte[] b1 = getM(2);
        byte[] b2 = getM(2);
        byte[] b3 = getM(3);
        System.out.println("minor gc");
        byte[] b4 = getM(1);
        TimeUnit.SECONDS.sleep(8);
    }

    public static byte[] getM(int m) {
        return new byte[1024 * 1024 * m];
    }

}
/*
minor gc
0.199: [GC 0.199: [ParNew: 7511K->176K(9216K), 0.0057871 secs] 7511K->7346K(19456K), 0.0058452 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
2.204: [GC [1 CMS-initial-mark: 7170K(10240K)] 8619K(19456K), 0.0004038 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2.205: [CMS-concurrent-mark-start]
2.208: [CMS-concurrent-mark: 0.003/0.003 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
2.208: [CMS-concurrent-preclean-start]
2.209: [CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2.209: [CMS-concurrent-abortable-preclean-start]
 CMS: abort preclean due to time 7.221: [CMS-concurrent-abortable-preclean: 0.059/5.012 secs] [Times: user=0.05 sys=0.00, real=5.01 secs] 
7.221: [GC[YG occupancy: 1449 K (9216 K)]7.221: [Rescan (parallel) , 0.0001736 secs]7.221: [weak refs processing, 0.0000050 secs] [1 CMS-remark: 7170K(10240K)] 8619K(19456K), 0.0002317 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
7.221: [CMS-concurrent-sweep-start]
7.221: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
7.221: [CMS-concurrent-reset-start]
7.222: [CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 par new generation   total 9216K, used 1613K [0x00000000f9a00000, 0x00000000fa400000, 0x00000000fa400000)
  eden space 8192K,  17% used [0x00000000f9a00000, 0x00000000f9b675a8, 0x00000000fa200000)
  from space 1024K,  17% used [0x00000000fa300000, 0x00000000fa32c110, 0x00000000fa400000)
  to   space 1024K,   0% used [0x00000000fa200000, 0x00000000fa200000, 0x00000000fa300000)
 concurrent mark-sweep generation total 10240K, used 7170K [0x00000000fa400000, 0x00000000fae00000, 0x00000000fae00000)
 concurrent-mark-sweep perm gen total 21248K, used 3082K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
*/

通过启动参数CMSScheduleRemarkEdenSizeThreshold我们可以知道,当eden区使用超过1M的时候,CMS垃圾收集触发以后,就会启动preclean(这个是JDK1.5的新特性),当并发执行到CMSScheduleRemarkEdenPenetration百分比值时候直接触发remark,如果设置了XX:CMSMaxAbortablePrecleanTime,则在CMSMaxAbortablePrecleanTime时间后,直接触发remark,忽略CMSScheduleRemarkEdenPenetration。
其中可以看到 CMS: abort preclean due to time 7.221:表示触发了preclean

案例七:设置CMS的preclean容量触发
package com.chinaso.phl;

import java.util.concurrent.TimeUnit;

/**
 * 案例七:设置CMS的preclean容量触发
 * -Xms20m -Xmx20m -Xmn10m -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:CMSMaxAbortablePrecleanTime=5000 -XX:CMSScheduleRemarkEdenSizeThreshold=1M -XX:CMSScheduleRemarkEdenPenetration=35
 * @author piaohailin
 * @date   2014-1-15
*/
public class Server6 {

    /**
     * 
     * @param args
     * @author piaohailin
     * @date   2014-1-15
    */
    public static void main(String[] args) throws Exception {
        byte[] b1 = getM(2);
        byte[] b2 = getM(2);
        byte[] b3 = getM(3);
        System.out.println("minor gc");
        byte[] b4 = getM(1);
        TimeUnit.SECONDS.sleep(2);
        byte[] b5 = getM(1);
        TimeUnit.SECONDS.sleep(2);
        byte[] b6 = getM(1);
        TimeUnit.SECONDS.sleep(8);
    }

    public static byte[] getM(int m) {
        return new byte[1024 * 1024 * m];
    }

}
/*
minor gc
0.185: [GC 0.185: [ParNew: 7511K->176K(9216K), 0.0057790 secs] 7511K->7346K(19456K), 0.0058398 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
2.191: [GC [1 CMS-initial-mark: 7170K(10240K)] 8619K(19456K), 0.0004258 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2.192: [CMS-concurrent-mark-start]
2.195: [CMS-concurrent-mark: 0.003/0.003 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2.195: [CMS-concurrent-preclean-start]
2.196: [CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2.196: [CMS-concurrent-abortable-preclean-start]
4.216: [CMS-concurrent-abortable-preclean: 0.023/2.020 secs] [Times: user=0.02 sys=0.00, real=2.02 secs] 
4.216: [GC[YG occupancy: 3497 K (9216 K)]4.216: [Rescan (parallel) , 0.0001836 secs]4.216: [weak refs processing, 0.0000058 secs] [1 CMS-remark: 7170K(10240K)] 10667K(19456K), 0.0002418 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.216: [CMS-concurrent-sweep-start]
4.216: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.216: [CMS-concurrent-reset-start]
4.217: [CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.266: [GC [1 CMS-initial-mark: 7170K(10240K)] 10667K(19456K), 0.0002891 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.266: [CMS-concurrent-mark-start]
4.269: [CMS-concurrent-mark: 0.003/0.003 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.269: [CMS-concurrent-preclean-start]
4.269: [CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.269: [CMS-concurrent-abortable-preclean-start]
4.270: [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.270: [GC[YG occupancy: 3497 K (9216 K)]4.270: [Rescan (parallel) , 0.0001925 secs]4.270: [weak refs processing, 0.0000050 secs] [1 CMS-remark: 7170K(10240K)] 10667K(19456K), 0.0002479 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.270: [CMS-concurrent-sweep-start]
4.270: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
4.270: [CMS-concurrent-reset-start]
4.270: [CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
6.271: [GC [1 CMS-initial-mark: 7170K(10240K)] 10667K(19456K), 0.0003114 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
6.271: [CMS-concurrent-mark-start]
6.274: [CMS-concurrent-mark: 0.003/0.003 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
6.274: [CMS-concurrent-preclean-start]
6.274: [CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
6.274: [CMS-concurrent-abortable-preclean-start]
6.274: [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
6.274: [GC[YG occupancy: 3497 K (9216 K)]6.274: [Rescan (parallel) , 0.0002117 secs]6.275: [weak refs processing, 0.0000042 secs] [1 CMS-remark: 7170K(10240K)] 10667K(19456K), 0.0002752 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
6.275: [CMS-concurrent-sweep-start]
6.275: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
6.275: [CMS-concurrent-reset-start]
6.275: [CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
8.275: [GC [1 CMS-initial-mark: 7170K(10240K)] 10667K(19456K), 0.0002918 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
8.276: [CMS-concurrent-mark-start]
8.279: [CMS-concurrent-mark: 0.003/0.003 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
8.279: [CMS-concurrent-preclean-start]
8.279: [CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
8.279: [CMS-concurrent-abortable-preclean-start]
8.279: [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
8.279: [GC[YG occupancy: 3497 K (9216 K)]8.279: [Rescan (parallel) , 0.0001401 secs]8.279: [weak refs processing, 0.0000042 secs] [1 CMS-remark: 7170K(10240K)] 10667K(19456K), 0.0001936 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
8.279: [CMS-concurrent-sweep-start]
8.279: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
8.279: [CMS-concurrent-reset-start]
8.280: [CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
10.280: [GC [1 CMS-initial-mark: 7170K(10240K)] 10667K(19456K), 0.0003064 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
10.280: [CMS-concurrent-mark-start]
10.283: [CMS-concurrent-mark: 0.003/0.003 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
10.283: [CMS-concurrent-preclean-start]
10.283: [CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
10.283: [CMS-concurrent-abortable-preclean-start]
10.283: [CMS-concurrent-abortable-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
10.283: [GC[YG occupancy: 3497 K (9216 K)]10.283: [Rescan (parallel) , 0.0001428 secs]10.284: [weak refs processing, 0.0000042 secs] [1 CMS-remark: 7170K(10240K)] 10667K(19456K), 0.0001940 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
10.284: [CMS-concurrent-sweep-start]
10.284: [CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
10.284: [CMS-concurrent-reset-start]
10.284: [CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 par new generation   total 9216K, used 3661K [0x00000000f9a00000, 0x00000000fa400000, 0x00000000fa400000)
  eden space 8192K,  42% used [0x00000000f9a00000, 0x00000000f9d675c8, 0x00000000fa200000)
  from space 1024K,  17% used [0x00000000fa300000, 0x00000000fa32c110, 0x00000000fa400000)
  to   space 1024K,   0% used [0x00000000fa200000, 0x00000000fa200000, 0x00000000fa300000)
 concurrent mark-sweep generation total 10240K, used 7170K [0x00000000fa400000, 0x00000000fae00000, 0x00000000fae00000)
 concurrent-mark-sweep perm gen total 21248K, used 3082K [0x00000000fae00000, 0x00000000fc2c0000, 0x0000000100000000)
*/

本次实验,设置了XX:CMSScheduleRemarkEdenPenetration=35,只有2秒的时候,优先于-XX:CMSMaxAbortablePrecleanTime=5000设置的5秒触发了remark,可以观察
2.196: [CMS-concurrent-abortable-preclean-start]
4.216: [CMS-concurrent-abortable-preclean: 0.023/2.020 secs] [Times: user=0.02 sys=0.00, real=2.02 secs]
时间停顿有2秒钟。

附录
参考文章
http://www.cnblogs.com/redcreen/archive/2011/05/04/2037057.html
http://szhnet.iteye.com/blog/1423894
http://book.51cto.com/art/201011/235590.htm


文章更新日志
2014-01-24
完善个别CMS参数的说明


作者简介
昵称:澳洲鸟
姓名:朴海林
QQ:85977328
MSN:6301655@163.com
分享到:
评论

相关推荐

    JVM初探- 内存分配、GC原理与垃圾收集器

    JVM内存管理是Java虚拟机的核心机制之一,其主要包含对象的创建、内存分配、...通过对内存分配策略、对象生死判定、垃圾收集算法和垃圾收集器的理解与应用,可以更好地掌握JVM的内存管理,从而提升应用性能和稳定性。

    JVM体系结构与GC调优

    - **垃圾收集器**:不同的JVM版本有多种GC实现,如Serial、Parallel、Concurrent Mark Sweep (CMS)、G1、ZGC、Shenandoah等,它们各有特点和适用场景。 4. **内存分配与GC策略** - **年轻代与老年代**:新生代...

    JVM_GC调优

    通过对JVM_GC调优的深入探讨,我们可以看出JVM内存管理和垃圾回收机制的复杂性。合理的GC策略和参数调整对于提高Java应用的性能至关重要。理解不同GC算法的特点和适用场景,可以帮助开发者选择最适合特定应用场景的...

    JVM性能调优-JVM内存整理及GC回收.pdf_java_jvm_

    总结来说,JVM性能调优是多方面的工作,包括理解内存结构、选择合适的垃圾收集器、调整内存参数以及优化代码实现。通过细致入微的调优,可以显著提升Java应用的性能和稳定性。这份PDF资料将详细介绍这些关键点,帮助...

    jvm性能调优-垃圾收集器parnew&CMS底层三色标记算-performance-gc-parnew-cms.zip

    CMS收集器,全称并发标记扫描,是一种用于老年代的垃圾收集器,特别适合于内存大且需要低暂停时间的应用。CMS分为四个阶段:初始标记、并发标记、最终标记和并发清除。在初始和最终标记阶段,GC会暂停应用,但这两个...

    JVM内存管理白皮书

    详细说明了J2SE 5.0版本中HotSpot JVM所实现的垃圾收集器类型,例如串行收集器、并行收集器、并行整理收集器和并发标记-清除(CMS)收集器等。每种收集器都有其特定的应用场景和性能特点。 4. 舒适性(Ergonomics)...

    JVM初探内存分配GC原理与垃圾收集器共16页.pdf.z

    深入理解JVM内存分配、垃圾收集(Garbage Collection, GC)原理以及垃圾收集器的工作方式对于优化程序性能至关重要。 首先,我们要了解JVM内存结构。在Java中,内存主要分为以下几个区域: 1. **堆内存(Heap)**...

    java -jvm 内存分配和jvm调优

    5. CMS收集器设置:对于响应时间敏感的应用,可以使用CMS收集器,通过-XX:+UseConcMarkSweepGC和-XX:+UseParNewGC启用,并调整相关参数如-XX:CMSInitiatingOccupancyFraction来控制触发CMS的时间点。 6. G1收集器:...

    CMS垃圾收集器1

    4. **并发清理(Concurrent Sweeping)**:这个阶段也是并发的,CMS收集器会清理未被标记的对象,释放内存。由于这个阶段用户线程仍在运行,新的垃圾可能会产生,这部分垃圾将在下一次GC时处理。 5. **预清理...

    JVM调优与内存管理总结

    Java虚拟机(JVM)调优与内存管理是优化Java应用程序性能的关键环节。JVM内存主要分为新生代、老年代和持久代,每个区域都有其特定的垃圾回收策略。 1. 引用计数法(Reference Counting):这是一种简单的垃圾回收...

    JVM 监控 调优 工具

    - `-XX:CMSInitiatingOccupancyFraction`:设置CMS收集器启动的阈值。 **GC优化** 垃圾收集是JVM性能的关键因素,优化GC主要是减少停顿时间并提高整体效率。常见的GC调优策略包括: 1. 选择合适的GC算法:如...

    jvm-full-gc调优-jvm-full-gc.zip

    通过设置JVM参数可以影响GC行为,如`-Xms`和`-Xmx`控制堆内存大小,`-XX:NewRatio`设置新生代与老年代的比例,`-XX:MaxPermSize`或`-XX:MetaspaceSize`控制方法区大小,`-XX:+UseConcMarkSweepGC`启用CMS收集器等。...

    gc调优,和jvm调优,特别详细,这是本人花人民币买的

    1. **垃圾收集器选择**:JVM提供了多种垃圾收集器,如Serial、Parallel、CMS、G1和ZGC等,每种收集器有不同的性能特征,需要根据应用的特性选择合适的GC策略。 2. **内存区域设置**:包括新生代、老年代、永久代...

    JVM内存设置与调优指南

    在Java世界中,Java虚拟机(JVM)是运行所有Java应用程序的核心。JVM内存设置与调优是提升应用性能的...理解内存结构、选择合适的垃圾收集器、合理设置参数,并结合监控工具进行调优,是优化Java应用性能的关键步骤。

    jvm调优实战经验

    通过监控JVM内存使用、垃圾回收情况和系统性能指标,分析性能瓶颈,进行针对性优化,最终评估调优效果。 8. **性能问题举例** 遇到性能问题时,应分析症状(如频繁Full GC、内存溢出等),查看监控结果,理解原因...

    JVM、GC详解及调优_jvm_JVM、GC详解及调优_

    《JVM、GC详解及调优》是一份深入解析Java虚拟机(JVM)和垃圾收集(Garbage Collection,简称GC)的详细资料。本文将根据提供的信息,深入阐述JVM的工作原理,GC的机制以及如何进行JVM的性能调优。 首先,JVM是...

    深入理解JVM性能调优和内存模型,垃圾回收,虚拟机原理,经典视频教程

    在性能调优方面,JVM提供了许多可调整的参数,如堆大小、新生代与老年代的比例、垃圾收集器的选择等。这些参数的合理配置可以显著提高应用的运行效率。例如,通过增大堆内存以容纳更多对象,或选择合适的垃圾收集器...

    mac mat jvm gc 内存分析

    JVM(Java Virtual Machine)的垃圾收集器(GC,Garbage Collector)扮演着核心角色,负责自动管理应用程序的内存,防止内存泄漏和性能问题。MAT(Memory Analyzer Tool)是由Eclipse基金会提供的一个强大的分析工具...

    jvmgc日志分析工具

    为了有效地使用这类工具,你需要了解一些基本的JVM内存管理概念,如新生代、老年代、永久代(对于较旧的JVM)或元空间(对于Java 8及以上版本),以及不同的垃圾收集器,如Serial、Parallel、CMS、G1、ZGC和...

Global site tag (gtag.js) - Google Analytics