Java Reference
In-Depth Information
figuration: a point at which it has loaded anything it caches, has created a maximum number
of client connections, and so on. Then connect to the application with jconsole , force a full
GC, and observe how much memory is used when the full GC completes. (Alternately, for
throughput GC, you can consult the GC log if it is available.)
Be aware that automatic sizing of the heap occurs even if you explicitly set the maximum
size: the heap will start at its default initial size, and the JVM will grow the heap in order to
meet the performance goals of the GC algorithm. There isn't necessarily a memory penalty
for specifying a larger heap than is needed: it will only grow enough to meet the GC per-
formance goals.
On the other hand, if you know exactly what size heap the application needs, then you may
as well set both the initial and maximum values of the heap to that value (e.g., -Xms4096m -
Xmx4096m ). That makes GC slightly more efficient, because it never needs to figure out
whether the heap should be resized.
1. The JVM will attempt to find a reasonable minimum and maximum heap size
based on the machine it is running on.
2. Unless the application needs a larger heap than the default, consider tuning the
performance goals of a GC algorithm (given in the next chapter) rather than fine-
tuning the heap size.
Sizing the Generations
Once the heap size has been determined, you (or the JVM) must decide how much of the
heap to allocate to the young generation, and how much to allocate to the old generation. The
performance implication of this should be clear: if there is a relatively larger young genera-
tion, then it will be collected less often, and fewer objects will be promoted into the old gen-
eration. But on the other hand, because the old generation is relatively smaller, it will fill up
more frequently and do more full GCs. Striking a balance here is the key.
Different GC algorithms attempt to strike this balance in different ways. However, all GC al-
gorithms use the same set of flags to set the sizes of the generations; this section covers those
common flags.
Search WWH ::

Custom Search