Java Reference
In-Depth Information
the application will end up with a very small old generation: for example, one that can be
cleaned in 50 ms. That will cause the JVM to perform very, very frequent full GCs, and per-
formance will be dismal. So be realistic: set the value to something that can actually be
achieved. By default, this flag is not set.
The GCTimeRatio flag specifies the amount of time you are willing for the application to
spend in GC (compared to the amount of time its application-level threads should run). It is a
ratio, so the value for N takes a little thought. The value is used in the following equation to
determine the percentage of time the application threads should ideally run:
The default value for GCTimeRatio is 99. Plugging that value into the equation yields 0.99,
meaning that the goal is to spend 99% of time in application processing, and only 1% of time
in GC. But don't be confused by how those numbers line up in the default case. A
GCTimeRatio of 95 does not mean that GC should run up to 5% of the time: it means that
GC should run up to 1.94% of the time.
I find it easier to decide what percentage of time I'd like the application to spend performing
useful work (say, 95%), and then calculate the value of the GCTimeRatio from this equation:
For a throughput goal of 95% (0.95), this equation yields a GCTimeRatio of 19.
The JVM uses these two flags to set the size of the heap within the boundaries established by
the initial ( -Xms ) and maximum ( -Xmx ) heap sizes. The MaxGCPauseMillis flag takes pre-
cedence: if it is set, the sizes of the young and old generation are adjusted until the pause
time goal is met. Once that happens, the overall size of the heap is increased until the time
ratio goal is met. Once both goals are met, the JVM will attempt to reduce the size of the
heap so that it ends up with the smallest possible heap that meets these two goals.
Because the pause time goal is not set by default, the usual effect of automatic heap sizing is
that the heap (and generation) sizes will increase until the GCTimeRatio goal is met. In prac-
tice, though, the default setting of that flag is quite optimistic. Your experience will vary, of
course, but I am much more used to seeing applications that spend 3% to 6% of their time in
Search WWH ::




Custom Search