Thursday, December 31, 2015

Java performance tuning - standard utils


All utils from this post are located at $JAVA_HOME/bin directory

1. Java process identification

First of all we have to identify process id of our java application.
In UNIX we can use
ps -aux

In Windows - we can open TaskManager

Or in both UNIX/Windows, we can just run utility :
jps

which will show processes related with java:
13528 Jps
14056 Gems

2. jmap

jmap can be used  for checking "memory map".

Example of usage :
jmap -heap 118984

Example of results :

using thread-local object allocation.
Parallel GC with 13 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 536870912 (512.0MB)
   NewSize          = 1310720 (1.25MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 21757952 (20.75MB)
   MaxPermSize      = 85983232 (82.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 134217728 (128.0MB)
   used     = 66957592 (63.855735778808594MB)
   free     = 67260136 (64.1442642211914MB)
   49.887293577194214% used
From Space:
   capacity = 22347776 (21.3125MB)
   used     = 5406752 (5.156280517578125MB)
   free     = 16941024 (16.156219482421875MB)
   24.19369157807918% used
To Space:
   capacity = 22347776 (21.3125MB)
   used     = 0 (0.0MB)
   free     = 22347776 (21.3125MB)
   0.0% used
PS Old Generation
   capacity = 357957632 (341.375MB)
   used     = 1262024 (1.2035598754882812MB)
   free     = 356695608 (340.1714401245117MB)
   0.3525623948702398% used
PS Perm Generation
   capacity = 31588352 (30.125MB)
   used     = 31448256 (29.99139404296875MB)
   free     = 140096 (0.13360595703125MB)
   99.55649474844398% used

3. jinfo 

jinfo can be used for checking java options which were used for application. For example we found that something is wrong with PermSize on previous step, so we want to check java options :

 jinfo -flag PermSize 118984
Picked up _JAVA_OPTIONS: -XX:PermSize=21757952

4. jstat

jstat can be used for getting statistic from JVM during specified periods of time.

For example, statistic from garbage collector which were gathered 5 times with interval 1sec(1000ms) :

bash-4.1$ jstat -gc 1996103 1000 5

 S0C    S1C    S0U    S1U      EC       EU        OC         OU       PC     PU    YGC     YGCT    FGC    FGCT     GCT
768.0  1856.0  0.0    0.0   123712.0 91910.9   687232.0    3504.9   26304.0 16454.5     48    0.134   8      0.305    0.439
768.0  1856.0  0.0    0.0   123712.0 93250.5   687232.0    3504.9   26304.0 16454.5     48    0.134   8      0.305    0.439
768.0  1856.0  0.0    0.0   123712.0 94294.1   687232.0    3504.9   26304.0 16454.5     48    0.134   8      0.305    0.439
768.0  1856.0  0.0    0.0   123712.0 95926.5   687232.0    3504.9   26304.0 16454.5     48    0.134   8      0.305    0.439
768.0  1856.0  0.0    0.0   123712.0 98104.9   687232.0    3504.9   26304.0 16454.5     48    0.134   8      0.305    0.439


5. jstack

with jstack we can check which processes are now running inside our JVM session.

jstack 12264

"Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x0000000053247000 nid=0x2cec waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x0000000053246000 nid=0x22f8 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" #3 daemon prio=8 os_prio=1 tid=0x00000000531ea000 nid=0x3c18 in Object.wait() [0x000000005453f000]
   java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000fd5870b8> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
- locked <0x00000000fd5870b8> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)

"Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x00000000531e3000 nid=0x60bc in Object.wait() [0x000000005443f000]
   java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000fd586af8> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:157)
- locked <0x00000000fd586af8> (a java.lang.ref.Reference$Lock)

"VM Thread" os_prio=2 tid=0x00000000531dd000 nid=0x1934 runnable

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x000000000221d800 nid=0x4334 runnable

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x000000000221f000 nid=0x18f8 runnable

"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x0000000002220800 nid=0x23b4 runnable

"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x0000000002224000 nid=0x30a0 runnable

"VM Periodic Task Thread" os_prio=2 tid=0x00000000545e8000 nid=0x3ddc waiting on condition

6. Visual tools 

Of course, if it's possible, much more easier to open "visual" tool like JConsole or VisualVM.

No comments:

Post a Comment