jvm垃圾回收性能测试

JVM性能测试:
-verbose:gc -Xms1200M -Xmx1200M -Xmn1024M -XX:+PrintGCDetails -XX:SurvivorRatio=8
-XX:+PrintGCTimeStamps
-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC
-XX:ParallelGCThreads=2

总结:对于堆中,如果大量对象在新生代,创建完,使用掉后,能够立即回收的话,那么垃圾回收会比较快。
否则,由于要从eden拷对象到s0,之后整理s0和s1时,又涉及到从s0拷到s1,再后面,如果对象还活着,且到达进入老年代的条件
(如对象年龄到达时)又涉及到从s0拷到老年代,这部分是个瓶颈。


另外测试一个大对象100M,和10个对象加起来为100M,分别测试这两个值
前者需要100ms时间,后者则需要10ms。


1.存在95M,对象无法及时回收时,回收1024M新生代堆花费大约100ms
代码:
 public static void testAllocation() {  
        byte[] allocation1, allocation2, allocation3, allocation4,allocation5,
        allocation6, allocation7, allocation8, allocation9,allocation10;  
        System.gc();
        allocation1 = new byte[20 * _1MB];  
        allocation2 = new byte[20 * _1MB];  
        allocation3 = new byte[20 * _1MB];
        allocation3 = new byte[10 * _1MB];
        allocation4 = new byte[5 * _1MB];  
        allocation5 = new byte[5 * _1MB];  
        allocation6 = new byte[5 * _1MB];  
        allocation7 = new byte[3 * _1MB];
        allocation8 = new byte[3 * _1MB];
        allocation9 = new byte[3 * _1MB];  
        allocation10 = new byte[1 * _1MB];  
        
        for(int i=0;i<1000;i++){
            byte[] a=new byte[2* _1MB];
        }
        
}


0.800: [GC 0.800: [ParNew: 837796K->76808K(943744K), 0.0709274 secs] 838377K->77388K(1123968K), 0.0709765 secs] [Times: user=0.11 sys=0.02, real=0.06 secs]
1.292: [GC 1.292: [ParNew: 914811K->0K(943744K), 0.0989450 secs] 915392K->77383K(1123968K), 0.0989934 secs] [Times: user=0.12 sys=0.03, real=0.09 secs]



0.803: [GC 0.803: [ParNew: 837796K->76808K(943744K), 0.0734739 secs] 838377K->77388K(1123968K), 0.0735326 secs] [Times: user=0.12 sys=0.03, real=0.08 secs]
1.296: [GC 1.296: [ParNew: 914811K->0K(943744K), 0.0842247 secs] 915392K->77383K(1123968K), 0.0842869 secs] [Times: user=0.14 sys=0.02, real=0.08 secs]



0.787: [GC 0.788: [ParNew: 837796K->76808K(943744K), 0.0685509 secs] 838377K->77388K(1123968K), 0.0686061 secs] [Times: user=0.11 sys=0.01, real=0.06 secs]
1.254: [GC 1.254: [ParNew: 914811K->0K(943744K), 0.0988940 secs] 915392K->77383K(1123968K), 0.0989382 secs] [Times: user=0.13 sys=0.05, real=0.09 secs]

0.208: [Full GC (System) 0.208: [CMS: 0K->580K(180224K), 0.0199693 secs] 16778K->580K(1123968K), [CMS Perm : 1565K->1563K(12288K)], 0.0200572 secs] [Times: user=0.02 sys=0.00, real=0.02 secs]
0.841: [GC 0.841: [ParNew: 837796K->76808K(943744K), 0.0704789 secs] 838377K->77388K(1123968K), 0.0705380 secs] [Times: user=0.16 sys=0.00, real=0.08 secs]
1.366: [GC 1.366: [ParNew: 914811K->0K(943744K), 0.0988410 secs] 915392K->77383K(1123968K), 0.0989155 secs] [Times: user=0.14 sys=0.06, real=0.10 secs]
Heap
 par new generation   total 943744K, used 522116K [0x03ce0000, 0x43ce0000, 0x43ce0000)
  eden space 838912K,  62% used [0x03ce0000, 0x23ac1100, 0x37020000)
  from space 104832K,   0% used [0x37020000, 0x37020000, 0x3d680000)
  to   space 104832K,   0% used [0x3d680000, 0x3d680000, 0x43ce0000)
 concurrent mark-sweep generation total 180224K, used 77383K [0x43ce0000, 0x4ece0000, 0x4ece0000)
 concurrent-mark-sweep perm gen total 12288K, used 1570K [0x4ece0000, 0x4f8e0000, 0x52ce0000)


2.不存在相应对象无法及时回收时,回收1024M新生代堆花费大约2ms
代码:
 byte[] allocation1, allocation2, allocation3, allocation4,allocation5,
        allocation6, allocation7, allocation8, allocation9,allocation10;  
        System.gc();
        allocation1 = new byte[20 * _1MB];  
        allocation2 = new byte[20 * _1MB];  
        allocation3 = new byte[20 * _1MB];
        allocation3 = new byte[10 * _1MB];
        allocation4 = new byte[5 * _1MB];  
        allocation5 = new byte[5 * _1MB];  
        allocation6 = new byte[5 * _1MB];  
        allocation7 = new byte[3 * _1MB];
        allocation8 = new byte[3 * _1MB];
        allocation9 = new byte[3 * _1MB];  
        allocation10 = new byte[1 * _1MB];  
        
        allocation1 = null;  
        allocation2 = null;  
        allocation3 = null;
        allocation3 = null;
        allocation4 = null;  
        allocation5 = null;  
        allocation6 = null;  
        allocation7 = null;
        allocation8 = null;
        allocation9 = null;  
        allocation10 =null;  
       
        
        for(int i=0;i<1000;i++){
            byte[] a=new byte[2* _1MB];
        }

0.820: [GC 0.821: [ParNew: 837796K->8K(943744K), 0.0011000 secs] 838377K->588K(1123968K), 0.0011446 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
1.195: [GC 1.195: [ParNew: 838011K->4K(943744K), 0.0010843 secs] 838592K->584K(1123968K), 0.0011238 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]


0.798: [GC 0.798: [ParNew: 837796K->8K(943744K), 0.0011321 secs] 838377K->588K(1123968K), 0.0011716 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
1.202: [GC 1.202: [ParNew: 838011K->4K(943744K), 0.0010192 secs] 838592K->584K(1123968K), 0.0010574 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]

0.783: [GC 0.783: [ParNew: 837796K->8K(943744K), 0.0010962 secs] 838377K->588K(1123968K), 0.0011966 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
1.163: [GC 1.163: [ParNew: 838011K->4K(943744K), 0.0010449 secs] 838592K->584K(1123968K), 0.0010824 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]

Heap
 par new generation   total 943744K, used 522120K [0x03d80000, 0x43d80000, 0x43d80000)
  eden space 838912K,  62% used [0x03d80000, 0x23b61100, 0x370c0000)
  from space 104832K,   0% used [0x370c0000, 0x370c1000, 0x3d720000)
  to   space 104832K,   0% used [0x3d720000, 0x3d720000, 0x43d80000)
 concurrent mark-sweep generation total 180224K, used 580K [0x43d80000, 0x4ed80000, 0x4ed80000)
 concurrent-mark-sweep perm gen total 12288K, used 1569K [0x4ed80000, 0x4f980000, 0x52d80000)

你可能感兴趣的:(jvm垃圾回收性能测试)