As menti
oned yesterday, I've been playing with jvmstat. It
allows you to visually watch garbage collection going on in your
application. It's quite fascinating to watch the difference as you try
different garbage collection algorithms. For instance, using the -XX:+AggressiveHeap algorithm makes a huge difference to the amount
of GC Time (or at least it did in my benchmark).
It's also very helpful in understanding how the various garbage
collection algorithms work – something I've always glossed over in the
past.
Below are some traces from JBoss being hit pretty hard by an increasing
number of clients. The first image shows it just starting up – note that
there has been little memory reclaimed by the old generation garbage
collector. In the second image you can see the saw tooth pattern in the old
generation memory usage. It is also interesting to see the copying of object
between the two survivor generations.
The third image shows the use of the AggressiveHeap garbage collector.
Note that most of the objects don't even make it out of the Eden pool. My
hypothesis is that this shows that most of my objects are short lived. A lot less time is
spent doing GC, too – compare the occasional spikes in the GC time graph to the almost continual GC in
the previous example.
Some useful links:
Collection with the 1.4.2 JavaTM Virtual Machine
Garbage Collection problem
Asked Questions about Garbage Collection in the HotspotTM JavaTM Virtual
Machine