Sun Microsystems Logo
First Previous Next Last Overview
 

LAB-1205: Java Application Performance Analysis

Exercise 4: Bad young/old gen 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.

There are several ways to set the ratio of young gen to max heap.  The technique used in these exercises is the most straightforward: we simply set the young gen and max heap sizes directly.  It's also possible to set this ratio with -XX:NewRatio

Steps to follow

  1. For this exercise we reduce the maximum heap size to 12 MB.  We keep the young gen at our optimal 4 MB setting.
    compiler=
    heap=-XX:NewSize=4m -XX:MaxNewSize=4m -Xms12m -Xmx12m
    gc=
    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. You should see the Java 2D Shear moving very slowly with uneven movements.  Will will also notice in the Graph window that the number of full GC events tracks the number of minor GC events.

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

  5. Wow, we had 20 full collections that took 10% of the run time!

Summary

How do you know when you have a bad young/old gen ratio?  The best way is to calculate the ratio based on your command line arguments (or monitor the real application).  In this example we set 12 MB for the heap with 4 MB for the new gen.  That leaves 8 MB for the old gen.  We notice that about 5.1 MB worth of objects stay alive in the old gen (leaving only 2.9 MB for promoted objects).  But the size of Eden and one survivor space are just under 4 MB!!!  That means that when a minor GC starts the collector realizes that if all those young objects get promoted it will run out of space!  That's why a major collection happens to insure that we can handle all objects that may still be alive.  Other signs of this 'promotion guarantee problem' are if the number of minor GC's tracks the number of full GC's very closely (and if you notice that a full GC occurs at the same time as a minor GC).

Why is small old gen (bad NewRatio) a problem?  As you can tell we are spending 5x the amount of time optimally spent in GC (a whopping 10%).  When the NewRatio is too big then all the efficiency of minor collections is lost.  Of course another potential problem in having the old gen too small is that there simply may not be enough space for all the live objects.  This can be true even if the NewRatio is set appropriately.  In this case look for "out of memory" errors in the log file. In fact, this is the focus of the next exercise.

Next Steps