G1 Garbage Collector Considered Slow?
I was recently considering trying out the new G1 garbage collector, see if it was any better than current real time CMS garbage collector. A concurrent soft real-time garbage collector that can compact? Awesome!
I switched one of my production applications to use the new G1 garbage collector and noticed a spike in CPU and diminishing throughput almost instantaniously, what gives? I googled around and stumbled upon this blog post and decided to do my own benchmarking.
I hacked up the following scala script based off the blog post to compare the two garbage collectors. The JDK that was used was JDK7u3 on Solaris on a quad core box.
time scala -J-XX:+UseConcMarkSweepGC GC.scala
time scala -J-XX:+UseG1GC GC.scala
Just what I saw with my production application, the throughput substantially diminished and the CPU cores spiked. I won’t be using the G1 garbage collector any time soon, hopefully Oracle will improve the G1 garbage collector with subsequent releases.