Sun Microsystems Logo
First Previous Next Last Overview
 

LAB-1205: Java Application Performance Analysis

Exercise 14: Use the concurrent garbage collector (tune tenuring and survivor ratio)

Learning goals of this exercise

In this exercise you will learn:

Background for this exercise

Please see Exercise 1 for an overview of running the javaperf GUI launcher.

To make best use of the various areas of the heap sometimes it may be necessary to tune the survivor ratio (the size of the survivor spaces) and the maximum tenuring threshold (how long objects must live before getting promoted to the old gen).  There is a good discussion of this topic in the Tuning Garbage Collection with the 5.0 Java™ Virtual Machine document

In Exercise 13 we found that the survivor spaces turned out to be only 64 K???  To make the size more reasonable we will use the option -XX:SurvivorRatio=6.  This means the size of each survivor space is the  YoungGen / (SurvivorRatio + 2) = 512 KB (when YoungGen is set to 4 MB).  That's a much more reasonable size....

However if there is no tenuring it doesn't matter!  We found that in Exercise 13 the tenuring threshold was set to zero.  After examining prior exercises it seems that most objects get promoted to the old gen by about the second or third minor GC.  So let's set -XX:MaxTenuringThreshold=4 so that any objects that get to the forth minor GC might as well get promoted (but at least we will use the survivor spaces!).

Steps to follow

  1. For this exercise we keep the settings the same as Exercise 13, but tune the MaxTenuringThreshold and SurvivorRatio.
    compiler=-server
    heap=-XX:PermSize=12m -XX:MaxPermSize=12m -XX:NewSize=4m -XX:MaxNewSize=4m -Xms16m -Xmx16m
    gc=-XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:MaxTenuringThreshold=4 -XX:SurvivorRatio=6
    other=

  2. Click [Start]. You will see the Java 2D Demo application start....  Immediately click on the "Transforms" tab. Then click into the "Shear" area so it fills the entire window.

  3. Notice how survivor spaces are now being used and we get back to the great behavior of Exercise 9.... Did you find the application was any smoother?

  4. When you see that the application runtime goes just over one minute click [Stop]

  5. This is among the best scores we have had for GC.  We pay a small price for using the low pause time collector... was it worth it?

Summary

By looking at the behavior in the application we were able to tune the survivor spaces and tenuring threshold to eliminate prematurely promoting objects to the old generation.

Of course every application has different object allocation behavior and lifetimes....  Fine tuning heap sizing for performance often involves sizing the survivor spaces (larger or smaller) as well as the tenuring threshold (how much the survivor spaces are used, if at all).  For more on these topics please check out the Young Generation Guarantee section of the Tuning Garbage Collection with the 5.0 Java™ Virtual Machine document.

Next Steps