I am comparing Concurrent Mark Sweep Vs Garbage 1 GC in JDK 7
These are the
test that I ran -
TEST1
I am profiling GCTest.java using VisualVM that is provided in jdk.
The code creates 150 integer Arrays into an Arraylist. Each integer array reservers 4 MB of memory i.e. 1*1024*1024*4 Bytes.= 4MB *150(iterations) = 600 MB.
then I am removing the arrays. At every 10th iteration, I am explicitly calling the garbage collector - System.gc();
command line used :
For G1:
java -XX:+UseG1GC -XX:+PrintGCDetails -Xloggc:G1GC.log -XX:GCTimeRatio=49 -XX:MaxGCPauseMillis=50 GCTest
For CMS:
java -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:G1GC.log -XX:GCTimeRatio=49 -XX:MaxGCPauseMillis=50 GCTest
The results from the execution can be found here(Please download original) -
https://docs.google.com/open?id=0B_MpilGzweULNTQ0NzE4YzMtOTFhMS00NTllLWJhNDYtNjZlNmE3OGMyYzU0
My First question is -
Since i am calling GC explicitly, Is this the right approach to compare Garbage collectors ?
These are the conclusions from the tests -
1) If a server has good CPU and RAM then G1 is a good option
2) If a server has average CPU and good RAM, then CMS is better.
3) Application Performance is better in CMS than G1 owing to high CPU utilization.
Second question -
Are the conclusions correct ? What other conclusions can be derived from the results?
TEST2
I ran a second test. I tweaked class a bit. The results were surprising -
1) When G1 collector is used, the Max heap size is reclaimed, but in case of CMS it is not reclaimed
2) In CMS Max used heap size is around around 20 MB, but in G1 it is 600 MB!!. Max heap size(available) in case of G1 it is 750 MB and CMS it is 65 MB
3) Max Throughput of G1 was 2.8% , but in case of CMS was well within 2%
The results can be seen in the attachment - G1GC profile and CMS Profile
Questions -
Why is the Max used heap size 600 MB in case of G1 collector?