2

I have been trying to use G1 on my applications, and noticed it takes more time to start an application compared to default garbage collector on java 7u91. On the other hand, less collections were execute as G1 is supposed to be.

Is there any reason why G1 is slower? My application is using a minimum and maximum heap of 128mb, over Solaris 64bits version with no custom parameters to VM. (Java server edition)

Aditya W
  • 636
  • 8
  • 18
Carlos Alberto
  • 5,745
  • 10
  • 44
  • 68

1 Answers1

3

and noticed it takes more time to start an application

That has several reasons

First: In most cases the default collector is the parallel collector, also known as throughput collector. It is the most efficient one in terms of wall time spent in GC relative to wall time spent in application code.[1]. It does not have to bear the extra costs of performing concurrent work.

G1 primarily optimizes for lower pause times on large heaps by expending additional CPU cycles on partially concurrent collections, which requires that you have CPU cycles to spare. Throughput is only a secondary goal.

Second: enabling G1 changes more than the algorithm used, many default settings are also changed.

diff <(java -XX:+UseG1GC -XX:+PrintFlagsFinal) <(java -XX:+PrintFlagsFinal) shows how other flags are changed

On java 8 there are the following differences that significantly affect GC behavior, among several others:

<     uintx GCTimeRatio                               = 9                                   {product}
>     uintx GCTimeRatio                               = 99                                  {product}
<     uintx MaxGCPauseMillis                          = 200                                 {product}
>     uintx MaxGCPauseMillis                          = 18446744073709551615                    {product}

Third: Application startup is not exactly a good way to measure anything since that's a transient event and the heap still has to settle into its final size. Collectors aim for steady-state operation and may handle such transients differently.


On an "old RISC server" and a heap size of 128 MB you definitely want to stick to either the parallel or serial collectors. Such a configuration does not benefit from what G1 has to offer.

[1] For CPU cycles instead of wall time it would be the serial collector.

the8472
  • 35,110
  • 4
  • 54
  • 107