Friday, June 27, 2014

Monitor Java Garbage Collection using jstat

After understanding the garbage collection concept in JAVA, this article lists the "jstat" commands&options to monitor JAVA GC.

-gc

It shows the current size for each heap area and its current usage (Eden, survivor, old, etc.), total number of GC performed, and the accumulated time for GC operations.
[root@admin]# jps
2304 ResourceManager
[root@admin]# jstat -gc 2304 1000
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       PC     PU    YGC     YGCT    FGC    FGCT     GCT
8064.0 8064.0  0.0   388.5  65088.0  61409.2   163520.0    8074.1   31616.0 31553.6      9    0.149   0      0.000    0.149
8064.0 8064.0  0.0   388.5  65088.0  61409.3   163520.0    8074.1   31616.0 31553.6      9    0.149   0      0.000    0.149
Above commands firstly find out the vmid of "Resource Manager", and check the overall GC situation every 1000 ms(1 second).
Below are the description for each column.
ColumnDescription
S0CCurrent size of Survivor0 area in KB
S1CCurrent size of Survivor1 area in KB
S0UUsed Survivor0 area in KB
S1UUsed Survivor1 area in KB
ECCurrent size of Eden area in KB
EUUsed Eden area in KB
OCCurrent size of old area in KB
OUUsed old area in KB
PCCurrent size of permanent area in KB
PUUsed permanent area in KB
YGCThe number of GC event occurred in young area
YGCTThe accumulated time for GC operations for Yong area
FGCThe number of full GC event occurred
FGCTThe accumulated time for full GC operations
GCTThe total accumulated time for GC operations
Above example output shows: YGC=9, YGCT=0.149(seconds), which means each GC in Young area took 0.149/9=0.0166(seconds).

-gcutil

Shows the usage for each heap area in percentage. Also shows the total number of GC performed and the accumulated time for GC operations.
[root@admin]# jstat -gcutil 2304 1000
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT
  5.00   0.00   5.87   4.94  99.84     12    0.164     0    0.000    0.164
  5.00   0.00   5.87   4.94  99.84     12    0.164     0    0.000    0.164

-gccause

It shows the "information provided by -gcutil" + reason for the last GC and the reason for the current GC.
[root@admin ~]# jstat -gccause 2304 1000
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC
  5.00   0.00  32.97   4.94  99.84     12    0.164     0    0.000    0.164 Allocation Failure   No GC
  5.00   0.00  33.29   4.94  99.84     12    0.164     0    0.000    0.164 Allocation Failure   No GC
ColumnDescription
LGCCThe cause for the last GC occurrence
GCCThe cause for the current GC occurrence

-gcnew

Shows the GC performance data for the new area.
[root@admin ~]# jstat -gcnew 2304 1000
 S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
8064.0 8064.0  403.4    0.0  6   6 4032.0  65088.0  30030.4     12    0.164
8064.0 8064.0  403.4    0.0  6   6 4032.0  65088.0  30030.4     12    0.164
ColumnDescription
TTTenuring threshold.
If copied this amount of times in young area (S0 ->S1, S1->S0), they are then moved to old area.
MTTMaximum Tenuring threshold.
DSSDesired survivor size in KB.

-gcold

Shows the GC performance data for the old area.
[root@admin ~]# jstat -gcold 2304 1000
   PC       PU        OC          OU       YGC    FGC    FGCT     GCT
 31616.0  31565.9    163520.0      8074.1     12     0    0.000    0.164
 31616.0  31565.9    163520.0      8074.1     12     0    0.000    0.164

-gcpermcapacity

Shows statistics for the permanent area.
[root@admin ~]# jstat -gcpermcapacity 2304 1000
  PGCMN      PGCMX       PGC         PC      YGC   FGC    FGCT     GCT
   21248.0    83968.0    31616.0    31616.0    12     0    0.000    0.164
   21248.0    83968.0    31616.0    31616.0    12     0    0.000    0.164
ColumnDescription
PGCMNThe minimum size of permanent area in KB.
PGCMXThe maximum size of permanent area in KB.
PGCCurrent size of permanent generation area in KB.

-printcompilation

HotSpot Compiler Method Statistics.
[root@admin ~]# jstat -printcompilation 2304 1000
Compiled  Size  Type Method
     568    178    1 org/mortbay/jetty/HttpFields destroy
     568    178    1 org/mortbay/jetty/HttpFields destroy
ColumnDescription
CompiledNumber of compilation tasks performed by the most recently compiled method.
SizeNumber of bytes of bytecode of the most recently compiled method.
TypeCompilation type of the most recently compiled method.
MethodClass name and method name identifying the most recently compiled method. Class name uses "/" instead of "." as namespace separator. Method name is the method within the given class. The format for these two fields is consistent with the HotSpot - XX:+PrintComplation option.

-class

Show Class Loader Statistics.This is to detect ClassLoader leaks.
[root@admin ~]# jstat -class 2304 1000
Loaded  Bytes  Unloaded  Bytes     Time
  5798 11127.9        0     0.0       4.46
  5798 11127.9        0     0.0       4.46
ColumnDescription
LoadedNumber of classes loaded.
BytesNumber of Kbytes loaded.
UnloadedNumber of classes unloaded.
BytesNumber of Kbytes unloaded.
TimeTime spent performing class load and unload operations.


No comments:

Post a Comment

Popular Posts