Greg Luck was suffering a nine second GC pause every fifty seconds, when Sun suggested some garbage collection tunings that solved the problem (down to two major GCs every day, he says, in "How We Solved our Garbage Collection Pausing Problem
The tunings were pretty simple:
-XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:NewSize=1200m -XX:SurvivorRatio=16
As Greg says:
-XX:+DisableExplicitGC - some libs call System.gc(). This is usually a bad idea and could explain some of what we saw.
-XX:+UseConcMarkSweepGC - use the low pause collector
-XX:NewSize=1200m -XX:SurvivorRatio=16 - the black magic part. Tuning these requires emprical observation of your GC log, either from verbose gc or jstat (a JDK 1.5 tool). In particular the 1200m new size is 1/4 of our heap size of 4800MB.
This is all documented in "Tuning Garbage Collection with the 1.4.2 Java Virtual Machine
," which has a 1.3 version
and 1.5 version
. Mr. Luck also didn't quite mention which specific JDK he was running, although his reference to jstat
indicates it might have been 1.5. If it wasn't 1.5, his use of -server or -client mode might have factored in as well, because -server changes the allocation of memory to Eden and the survivor spaces as well.
It's very common to need tuning of this sort in long-running Java processes, in particular in J2EE applications. It's so common that it should be part of the tuning checklist of every application, along with a few other gems like "don't use reflection unless you really have to, and if you have to, cache the method references!" That said, are you aware of how to measure GC times, and tune it?
Mr. Luck refers to Sun engineers looking at the verbose garbage collection logs, and offering the settings based on those. Is there a deterministic (or mostly deterministic) way to determine good settings for these? Could a lack of garbage collection tuning be part of J2EE's undeserved reputation for slow runtime performance?
Message was edited by: joeo at enigmastation dot com to add the 1.5 GC tuning page, pointed out by Hack Kampbjørn