Profiling for JVM

4ccf6c02807d06f043a71435c48ce86a?s=47 Kengo TODA
October 16, 2012

Profiling for JVM

Simple introduction about how to judge the reason why your Java program is slow

4ccf6c02807d06f043a71435c48ce86a?s=128

Kengo TODA

October 16, 2012
Tweet

Transcript

  1. PROFILING FOR JVM How to verify your hypothesis - @eller86

    1
  2. Agenda Process to detect the cause of performance problem What

    is “profiling”? Tools to profile 2
  3. Process to detect the cause of performance problem Make hypothesis

    from experience and knowledge Get Servlet’s log from middle ware like Jetty Read source code, do debugging, do profiling 3
  4. What is “profiling”? where? why? GC storm algorithm CPU Other

    reading code heap dump I/O Lock? Waiting other system? I/O GC Other thread dump IZQPUIFTJT WFSJpDBUJPO 4
  5. Tools to profile jmap jstack jstat VisualVM 5

  6. Overview 6

  7. Judging the reason why JVM uses CPU heavily $ jstat

    -gcutil [PID] 250 7 S0 S1 E O P YGC YGCT FGC FGCT GCT 12.44 0.00 27.20 9.49 96.70 78 0.176 5 0.495 0.672 12.44 0.00 62.16 9.49 96.70 78 0.176 5 0.495 0.672 12.44 0.00 83.97 9.49 96.70 78 0.176 5 0.495 0.672 0.00 7.74 0.00 9.51 96.70 79 0.177 5 0.495 0.673 0.00 7.74 23.37 9.51 96.70 79 0.177 5 0.495 0.673 0.00 7.74 43.82 9.51 96.70 79 0.177 5 0.495 0.673 0.00 7.74 58.11 9.51 96.71 79 0.177 5 0.495 0.673 GC was fired Young generation GC was fired 7
  8. Detecting method which costs too much time 8

  9. How to read method name Foo.x() means “method x of

    Foo class” Foo$Bar.x() means “method x of Bar class, and Bar is inner class of Foo” Foo.<init> means “constructor of Foo class” Foo.<clinit> means “static initializer of Foo class” 9
  10. Taking thread dump $ jstack -l [PID] > thread-dump.txt 10

  11. Checking count of objects 11

  12. Taking heap dump $ jmap -dump:format=b,file=dump.dat [PID] 12

  13. Key points Hypothesis needs verification Know “normal” performance to detect

    “abnormal” one Imagine globally, verify locally (narrow down step by step) 13
  14. Reference JDK tools and utilities Browsing heap dump VisualVM Diagnosis

    documentation @ developerWorks My gist about JVM profiling, blog article and another article 14