Here we use a case study to show you what we mean by:
Proper monitoring and tuning of the Metaspace is still required in order to limit the frequency or delay the garbage collections of metaspace.
JVM Setup
We have used the following print options:
- -XX:+PrintGCDetails -XX:+PrintGCTimeStamps
- -XX:MetaspaceSize=128m
In the GC log file, you can find the following entries:
[Metaspace: 21013K->21013K(1069056K)]
The first value shows you the previously used size before GC, the second value shows you the current used size and the last value shows you the current reserved size.
Before Tuning
Below is the experiment running with all default values. As you can see, there are six Full GC events triggered by "Metadata GC Threshold" being reached. The initial high water mark was set by the default MetaspaceSize (i.e., 21807104 Bytes). So, the first Full GC event was induced when committed memory of all metaspaces reaches the initial high water mark. To find HotSpot's default option values, read [4].
3.112: [Full GC (Metadata GC Threshold) ...] [Eden: ..., [Metaspace: 21013K->21013K(1069056K)] 5.440: [Full GC (Metadata GC Threshold) ...] [Eden: ..., [Metaspace: 34645K->34645K(1081344K)] 11.921: [Full GC (Metadata GC Threshold) ...] [Eden: ..., [Metaspace: 58159K->58152K(1101824K)] 18.321: [Full GC (Metadata GC Threshold) ...] [Eden: ..., [Metaspace: 97038K->97038K(1136640K)] 51.761: [Full GC (Metadata GC Threshold) ...] [Eden: ..., [Metaspace: 160475K->155432K(1193984K)] 319.406: [Full GC (Metadata GC Threshold) ...] [Eden: ..., [Metaspace: 267854K->267854K(1288192K)]
Note that the unit on X-axis is seconds and Y-axis KBytes.
After Tuning
Here we have set the experiment with the following extra option:
- -XX:MetaspaceSize=128m
25.863: [Full GC (Metadata GC Threshold) ...] [Eden: ..., [Metaspace: 127978K->126460K(1165312K)] 81.254: [Full GC (Metadata GC Threshold) ...] [Eden: ..., [Metaspace: 213481K->209918K(1241088K)] 3486.808: [Full GC (Allocation Failure) ...] [Eden: ..., [Metaspace: 306929K->298136K(1327104K)] 3631.001: [Full GC (Allocation Failure) ...] [Eden: ..., [Metaspace: 299979K->298792K(1329152K)]
Why to Tune?
So, you may ask what's the deal with tuning MetaspaceSize. Yes, it's just setting the initial high water mark. Later HotSpot will adjust high water mark based on ergonomics. Hopefully, when HotSpot's ergonomics becomes more matured, no tuning is necessary at all. But, even in that case, you may still want to set MetaspaceSize for some occasions. One of them is when you run a benchmark in a short period and your focus may be on other GC activities than meta data being loaded or unloaded.
No comments:
Post a Comment