my dog learned polymorphism
The moose likes Performance and the fly likes Concurrent Mark Sweep Vs Garbage 1 GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Concurrent Mark Sweep Vs Garbage 1 GC " Watch "Concurrent Mark Sweep Vs Garbage 1 GC " New topic

Concurrent Mark Sweep Vs Garbage 1 GC

Manju Prabhu

Joined: Dec 22, 2008
Posts: 3
I am comparing Concurrent Mark Sweep Vs Garbage 1 GC in JDK 7
These are the test that I ran -
I am profiling 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) -

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?

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?

[Thumbnail for G1GC profile.jpg]

[Thumbnail for CMS.jpg]

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

calling System.gc() does not guarantee that the GC is merely a suggestion to the JVM that you think now might be a good time - but the JVM is free to ignore the request.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rojan punn

Joined: Nov 29, 2011
Posts: 17


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.

I agree. Here's the link:
subject: Concurrent Mark Sweep Vs Garbage 1 GC
It's not a secret anymore!