Databases Reference
In-Depth Information
The most important options that control garbage collection are these:
Heap size
Generation heap size
Garbage collection algorithm used by the JVM
The heap size controls how much memory is allocated to the overall Java
heap. The heap size also controls how often the JVM performs garbage collection.
Finding the ideal heap size is a balancing act. When the heap size is set to a
large value, garbage collection occurs less frequently, but collection pauses are
longer because there's more heap to scan. In contrast, small heap sizes cause
garbage collection to occur more frequently, but result in shorter pauses.
If garbage collection occurs too frequently, performance can be severely
impacted. For example, suppose that your application uses a heap size that is too
small to handle every live object being used by your application plus new ones
that need to be created. Once the maximum heap size is reached, your applica-
tion attempts to allocate a new object and fails. This failure triggers the garbage
collector, which frees up memory. Your application tries again to allocate a new
object. If the garbage collector failed to recover enough memory the first time,
the second attempt fails, triggering the garbage collector to run again. Even if the
garbage collector reclaims enough memory to satisfy the immediate request, the
wait won't be long before another allocation failure occurs, triggering yet another
garbage collection cycle. As a result, instead of servicing your application, the
JVM constantly scavenges the heap for memory.
Performance Tip
As a general rule, try increasing the heap size so that garbage collection
is not triggered as frequently, keeping in mind that you don't want to run
out of physical memory (RAM). See the section, “Memory,” page 107, for
information about how running out of RAM affects performance. If
garbage collection pauses seem unnecessarily long, try decreasing the
heap size.
Older JVMs often treat the heap as one big repository, requiring the garbage
collector to inspect each object in the heap to determine whether it is a dead
object and can be cleaned up. Newer JVMs use generational garbage collection
to separate objects into different memory pools within the heap based on the
object's lifetime.
Search WWH ::




Custom Search