In this article, we will introduce you one way to monitor the health of JVM's garbage collection activities.
jstat
You can find the Java Virtual Machine Statistics Monitoring Tool named jstat in the following folder:- ${JDK_INST}/bin/jstat
jstat provides different options which determine the statistics information that jstat displays. To find the list of options for a particular platform installation that jstat displays, you type:
Note that 9852 is the process id that jstat retrieves statistics from. You can also use `pgrep java` to retrieve the process id directly. For example, you can specify the above command line as:
Then, after a little while, we print the statistics information again:
This has helped us to find out that our process was stuck because it is out of heap and all it is doing is garbage collection. In other words, O (old space) and E (eden space) are continually full.
- jstat -option
For example, it displays the following supported options for my Linux platform:
- -class
- displays statistics on the behavior of the class loader
- -compiler
- displays statistics of the behavior of the HotSpot Just-in-Time compiler
- -gc
- displays statistics of the behavior of the garbage collected heap
- -gccapacity
- displays statistics of the capacities of the generations and their corresponding spaces
- -gccause
- displays summary of garbage collection statistics (same as -gcutil), with the cause of the last and current (if applicable) garbage collection events
- -gcnew
- displays statistics of the behavior of the new generation
- -gcnewcapacity
- displays statistics of the sizes of the new generations and its corresponding spaces
- -gcold
- displays statistics of the behavior of the old and permanent generations
- -gcoldcapacity
- displays statistics of the sizes of the old generation
- -gcpermcapacity
- displays statistics of the sizes of the permanent generation
- -gcutil
- displays summary of garbage collection statistics
- -printcompilation
- displays HotSpot compilation method statistics
-gcutil Option
In this demonstration, we will choose -gcutil to display garbage collection statistics. You can find the meaning of displayed columns below:
Column | Description |
---|---|
S0 | Survivor space 0 utilization as a percentage of the space's current capacity. |
S1 | Survivor space 1 utilization as a percentage of the space's current capacity. |
E | Eden space utilization as a percentage of the space's current capacity. |
O | Old space utilization as a percentage of the space's current capacity. |
P | Permanent space utilization as a percentage of the space's current capacity. |
YGC | Number of young generation GC events. |
YGCT | Young generation garbage collection time. |
FGC | Number of full GC events. |
FGCT | Full garbage collection time. |
GCT | Total garbage collection time. |
The Finding
In our case, we have found the following statistics information:$ jstat -gcutil 9852 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 100.00 100.00 23.68 447 55.197 11 416.676 471.872 $ jstat -gcutil 9852 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 100.00 100.00 23.68 447 55.197 11 416.676 471.872 $ jstat -gcutil 9852 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 100.00 100.00 23.68 447 55.197 11 416.676 471.872 $ jstat -gcutil 9852 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 100.00 100.00 23.68 447 55.197 11 416.676 471.872
Note that 9852 is the process id that jstat retrieves statistics from. You can also use `pgrep java` to retrieve the process id directly. For example, you can specify the above command line as:
jstat -gcutil `pgrep java`
Then, after a little while, we print the statistics information again:
$ jstat -gcutil 9852 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 100.00 100.00 23.68 447 55.197 25 1008.989 1064.186 $ jstat -gcutil 9852 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 100.00 100.00 23.68 447 55.197 25 1008.989 1064.186 $ jstat -gcutil 9852 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 100.00 100.00 23.68 447 55.197 25 1008.989 1064.186 $ jstat -gcutil 9852 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 100.00 100.00 23.68 447 55.197 25 1008.989 1064.186
This has helped us to find out that our process was stuck because it is out of heap and all it is doing is garbage collection. In other words, O (old space) and E (eden space) are continually full.
No comments:
Post a Comment