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 :
java -XX:+UseG1GC -XX:+PrintGCDetails -Xloggc:G1GC.log -XX:GCTimeRatio=49 -XX:MaxGCPauseMillis=50 GCTest
java -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -Xloggc:G1GC.log -XX:GCTimeRatio=49 -XX:MaxGCPauseMillis=50 GCTest
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
Why is the Max used heap size 600 MB in case of G1 collector?
Is this testing really for your application which runs in production env?Or just to learn abot the GC mechanism?Is this for a multi threaded env?
I wanst aware about G1 GC's existance in jdk6 .
The test really doesnt give an actaul performance figures .you will have a better idea if you make your program as a thread and register as a service in windows.and monitor it with defferent parameters and code cahnges.
from the picture provided the g1 GC has a very inconsisten use of Heap/or a very large amount of heap is used at a time ? which is not good for real time systems as other threads may run slowly in this case.
but the cms picture has a consistent use of heap .
So if you want to find out which is good you really have to experiment with these as you are doing now.Any way also have a look at the below lnk if you havent seen it already.