LAB-1205: Java Application Performance Analysis
Exercise 2: Young generation too big
Learning goals of this exercise
In this exercise you will learn:
- How to recognize when the young generation is too big
- Guidelines for sizing the young generation
Background for this exercise
Please see Exercise 1 for an overview of running
the javaperf GUI launcher.
General Guidelines for sizing the young generation:
- The maximum ratio between young gen and overall heap is about 45%
If you exceed this ratio then there is a risk that if the entire young
gen contained live objects that they couldn't all be promoted to the
old gen
- For client applications
Start with a 25% ratio
- For server applications
Start with a 10% ratio - Increase ratio as needed
If the ratio is too low (young gen is too small) as shown by a sawtooth
pattern in the old gen then gradually increase the ratio by 5% or 10%.
Steps to follow
- For this exercise we keep the maximum heap size the same at 16 MB. However we set the young gen all the way to 5.5 MB.
(remember for exercise 01 we set the Young gen too small at only 1 MB)
Here are the settings for Exercise 02:
compiler=
heap=-XX:NewSize=5500k -XX:MaxNewSize=5500k -Xms16m -Xmx16m
gc=
other=
|
- Remember that you can view these settings within the javaperf GUI
by clicking on the Settings tab. In this exercise we have no compiler,
gc or other arguments. We only setting the initial and maximum Young Gen
size and the initial and maximum overall heap size.
- Click
. 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.
- Notice
that there is no longer the sawtooth pattern in the old gen graph in
the "Graph" pane of Visual GC. You may also notice that the
application is somewhat "jittery" due to the fact that each minor GC
takes longer (it has to collect 5.5 MB instead of 1 MB).
- When you see that the application runtime goes just over one minute, as shown at the top of the "Visual GC" pane then
quit the Java 2D Demo application by clicking ![[Stop]](Stop.png)
- Notice the summary statistics in the javaperf GUI. For this example run we have had 17 minor collections (vs. 105 in Exercise 1), 4 full
collections (vs. 3) and we have a spent a total of 2.45% (vs. 3.45%) of the total runtime
in GC. (PLEASE NOTE: your numbers will be different than these examples)
Summary
How do you know the young
gen is too big? One way is if you have a bad young gen to max heap ratio (we will explore this possibility in Exercise 4).
Even though you have fewer GC's, they take longer when they occur.
Why
is a big young gen a
problem? Having the young gen too big is generally not as big a
performance problem as having it too small. One concern, especially for
client applications, is that if the young gen is too big it can lead to
jittery response due to GC pauses during minor collections.
If you really do want better throughput (less time in GC) and are
willing to give up responsiveness then a larger young gen may be better.
Another concern is that the overall heap size may be bigger than
necessary (and thus wasting memory).
Next Steps