SlideShare a Scribd company logo
1 of 10
Download to read offline
Bill Au
CBS Interactive
http://www.apache.org/~billa/oscon2012/
Troubleshooting Slow or Hung Java Applications
2
Agenda
» Tools of the Trade
» Case Studies
2
3
Tools – Out Of The Box
» jinfo, jmap, jstack, jstat
» JConsole, VisualVM
–  Monitor CPU usage by using JTop plug-in ($JAVA_HOME/
demo/management/JTop)
» java.lang.management
–  Platform MXBeans: runtime, operating system, class loading,
compilation, garbage collection, memory, thread
–  Sample code in $JAVA_HOME/demo/management
–  JDK demo and sample was part of JDK download for
jdk6u31 or older, separate download for u32+
3
4
Tools – java.lang.management
» Sample code:
import java.lang.management.*;
ThreadMXBean tb=ManagementFactory.getThreadMXBean();
if (tb.isThreadCpuTimeSupported()) {
long[] tids=tb.getAllThreadIds();
for (long tid : tids) {
System.out.println(“cputime:”+tb.getThreadCpuTime(tid));
System.out.println(“usertime:”+tb.getThreadUserTime(tid));
}
}
4
5
Tools
» Garbage collection log
–  -Xloggc:<filename>
–  Timestamp and duration of GC events
–  Sizes before and after GC events
–  More options to explore:
− -XX:+PrintGCDateStamps
− -XX:+PrintGCDetails
− -XX:+PrintTenuringDistribution
− -XX:+PrintGCApplicationsStoppedTime
–  Some GC flags can be set dynamically by jinfo/JConsole/
VisualVM:
PrintGC, PrintGCDetails, PrintGCTimeStamps
» visualgc – GUI for garbage collection monitoring
5
6
Tools
» Thread dump
–  kill -3 (or kill –SIGHUP)
–  JConsole, VisualVM
–  ThreadMXBean
–  jstack (-F)
» Consecutive thread dumps
–  Stop motion animation
6
7
Hung or Slow App
» Long GC pauses and/or high GC overhead
–  Basic GC tuning
− max heap size: -Xmx
− type of collector used
−  -XX:+UserSerialGC
−  -XX:+UseParallelGC/-XX:+UseParallelOldGC
−  -XX:+UseConcMarkSweepGC
−  -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC (jdk6u14+)
–  Advanced GC tuning
− young generation size: -Xmn
–  Baseline, tune, measure one change at a time
» Demo: HPjmeter – garbage collection analysis (and
more…)
7
8
Hung or Slow App
» Deadlock
–  Take thread dump to run the JVM’s deadlock detector
» Looping Threads
–  Monitor CPU times of running threads
− ThreadMXBean
− JTop plug-in for JConsole/VisualVM
–  Inspect stack trace of suspicious threads
8
9
Slow or Hung App
» Blocked threads
–  Look for blocked threads waiting on the same condition
–  Identify bottleneck for resource contention
–  Inspect code for incautious and/or improper synchronization
» Demo: samurai – thread dump analysis tool
» Stuck threads
–  Look for runnable threads with the same stack trace across
consecutive thread dumps
–  Some common causes:
− Blocking for a network call without specifying connect and/or
read timeout (default may be no timeout)
− Long execution time for calls to backend servers
9
10
Links
» Presentation
http://www.apache.org/~billa/oscon2012
» HPjmeter
https://h20392.www2.hp.com/portal/swdepot/
displayProductInfo.do?productNumber=HPJMETER
» samurai
http://yusuke.homeip.net/samurai/en/index.html
https://github.com/yusuke/samurai
10

More Related Content

What's hot

Using Flame Graphs
Using Flame GraphsUsing Flame Graphs
Using Flame GraphsIsuru Perera
 
Monitoring services at scale.
Monitoring services at scale.Monitoring services at scale.
Monitoring services at scale.Talina Shrotriya
 
Don't dump thread dumps
Don't dump thread dumpsDon't dump thread dumps
Don't dump thread dumpsTier1 App
 
Galaxy CloudMan performance on AWS
Galaxy CloudMan performance on AWSGalaxy CloudMan performance on AWS
Galaxy CloudMan performance on AWSEnis Afgan
 
Become a Garbage Collection Hero
Become a Garbage Collection HeroBecome a Garbage Collection Hero
Become a Garbage Collection HeroTier1app
 
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupДоклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupBadoo Development
 
New Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using TracingNew Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using TracingScyllaDB
 
Tips on High Performance Server Programming
Tips on High Performance Server ProgrammingTips on High Performance Server Programming
Tips on High Performance Server ProgrammingJoshua Zhu
 
Odoo Performance Limits
Odoo Performance LimitsOdoo Performance Limits
Odoo Performance LimitsOdoo
 
Memory management for_android_apps
Memory management for_android_appsMemory management for_android_apps
Memory management for_android_appsBin Shao
 
Optimizing High Performance Big Data Cancer Workflows
Optimizing High Performance Big Data Cancer WorkflowsOptimizing High Performance Big Data Cancer Workflows
Optimizing High Performance Big Data Cancer WorkflowsIvan Jimenez
 
อ จฉร ยะภาพสร_างได_
อ จฉร ยะภาพสร_างได_อ จฉร ยะภาพสร_างได_
อ จฉร ยะภาพสร_างได_Taew Chom
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examplesPeter Lawrey
 
Test for 'Libre Office' format support
Test for 'Libre Office' format supportTest for 'Libre Office' format support
Test for 'Libre Office' format supportViktorShepel
 

What's hot (20)

Hypertable Nosql
Hypertable NosqlHypertable Nosql
Hypertable Nosql
 
Using Flame Graphs
Using Flame GraphsUsing Flame Graphs
Using Flame Graphs
 
Java performance
Java performanceJava performance
Java performance
 
Monitoring services at scale.
Monitoring services at scale.Monitoring services at scale.
Monitoring services at scale.
 
[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe
 
Don't dump thread dumps
Don't dump thread dumpsDon't dump thread dumps
Don't dump thread dumps
 
Java GC, Off-heap workshop
Java GC, Off-heap workshopJava GC, Off-heap workshop
Java GC, Off-heap workshop
 
Galaxy CloudMan performance on AWS
Galaxy CloudMan performance on AWSGalaxy CloudMan performance on AWS
Galaxy CloudMan performance on AWS
 
Become a Garbage Collection Hero
Become a Garbage Collection HeroBecome a Garbage Collection Hero
Become a Garbage Collection Hero
 
jps & jvmtop
jps & jvmtopjps & jvmtop
jps & jvmtop
 
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupДоклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
 
New Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using TracingNew Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using Tracing
 
Tips on High Performance Server Programming
Tips on High Performance Server ProgrammingTips on High Performance Server Programming
Tips on High Performance Server Programming
 
Odoo Performance Limits
Odoo Performance LimitsOdoo Performance Limits
Odoo Performance Limits
 
Zk meetup talk
Zk meetup talkZk meetup talk
Zk meetup talk
 
Memory management for_android_apps
Memory management for_android_appsMemory management for_android_apps
Memory management for_android_apps
 
Optimizing High Performance Big Data Cancer Workflows
Optimizing High Performance Big Data Cancer WorkflowsOptimizing High Performance Big Data Cancer Workflows
Optimizing High Performance Big Data Cancer Workflows
 
อ จฉร ยะภาพสร_างได_
อ จฉร ยะภาพสร_างได_อ จฉร ยะภาพสร_างได_
อ จฉร ยะภาพสร_างได_
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Test for 'Libre Office' format support
Test for 'Libre Office' format supportTest for 'Libre Office' format support
Test for 'Libre Office' format support
 

Viewers also liked

12mostbeautifulvillagesineurope 140211052016-phpapp01 (1)
12mostbeautifulvillagesineurope 140211052016-phpapp01 (1)12mostbeautifulvillagesineurope 140211052016-phpapp01 (1)
12mostbeautifulvillagesineurope 140211052016-phpapp01 (1)Luciana Teixeira
 
Ecological anthropology
Ecological anthropologyEcological anthropology
Ecological anthropologyOktari Aneliya
 
Resta de números decimales
Resta de números decimalesResta de números decimales
Resta de números decimalesSabio Online
 
Asset valuation &amp; corporate finance
Asset valuation &amp; corporate financeAsset valuation &amp; corporate finance
Asset valuation &amp; corporate financevasishta bhargava
 
NFC - Uma Nova Possibilidade - TDC Porto Alegre 2014
NFC - Uma Nova Possibilidade - TDC Porto Alegre 2014NFC - Uma Nova Possibilidade - TDC Porto Alegre 2014
NFC - Uma Nova Possibilidade - TDC Porto Alegre 2014Jorge Maia
 
Listening and discourse analysis
Listening and discourse analysisListening and discourse analysis
Listening and discourse analysisMatheus de Castro
 
Everything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap DumpsEverything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap DumpsAndrei Pangin
 
Intensive listening activities
Intensive listening activitiesIntensive listening activities
Intensive listening activitiesDavid Deubelbeiss
 
Softskills
SoftskillsSoftskills
Softskills혁 권
 

Viewers also liked (15)

Flujo de efectivo
Flujo de efectivo Flujo de efectivo
Flujo de efectivo
 
Youth Meetup
Youth MeetupYouth Meetup
Youth Meetup
 
S4 tarea4 esmam
S4 tarea4 esmamS4 tarea4 esmam
S4 tarea4 esmam
 
Presentación1
Presentación1Presentación1
Presentación1
 
12mostbeautifulvillagesineurope 140211052016-phpapp01 (1)
12mostbeautifulvillagesineurope 140211052016-phpapp01 (1)12mostbeautifulvillagesineurope 140211052016-phpapp01 (1)
12mostbeautifulvillagesineurope 140211052016-phpapp01 (1)
 
ELOY ALFARO
ELOY ALFAROELOY ALFARO
ELOY ALFARO
 
Ecological anthropology
Ecological anthropologyEcological anthropology
Ecological anthropology
 
Resta de números decimales
Resta de números decimalesResta de números decimales
Resta de números decimales
 
Asset valuation &amp; corporate finance
Asset valuation &amp; corporate financeAsset valuation &amp; corporate finance
Asset valuation &amp; corporate finance
 
NFC - Uma Nova Possibilidade - TDC Porto Alegre 2014
NFC - Uma Nova Possibilidade - TDC Porto Alegre 2014NFC - Uma Nova Possibilidade - TDC Porto Alegre 2014
NFC - Uma Nova Possibilidade - TDC Porto Alegre 2014
 
Listening and discourse analysis
Listening and discourse analysisListening and discourse analysis
Listening and discourse analysis
 
Patinatge(1)
Patinatge(1)Patinatge(1)
Patinatge(1)
 
Everything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap DumpsEverything you wanted to know about Stack Traces and Heap Dumps
Everything you wanted to know about Stack Traces and Heap Dumps
 
Intensive listening activities
Intensive listening activitiesIntensive listening activities
Intensive listening activities
 
Softskills
SoftskillsSoftskills
Softskills
 

Similar to OSCON2012TroubleShootJava

JavaOne2011BOF18246
JavaOne2011BOF18246JavaOne2011BOF18246
JavaOne2011BOF18246William Au
 
Solr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approachSolr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approachAlexandre Rafalovitch
 
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...Lucidworks
 
Java 어플리케이션 성능튜닝 Part1
Java 어플리케이션 성능튜닝 Part1Java 어플리케이션 성능튜닝 Part1
Java 어플리케이션 성능튜닝 Part1상욱 송
 
7 jvm-arguments-Confoo
7 jvm-arguments-Confoo7 jvm-arguments-Confoo
7 jvm-arguments-ConfooTier1 app
 
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020Jelastic Multi-Cloud PaaS
 
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...Jelastic Multi-Cloud PaaS
 
jcmd #javacasual
jcmd #javacasualjcmd #javacasual
jcmd #javacasualYuji Kubota
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageJelastic Multi-Cloud PaaS
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunningguest1f2740
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance TunningTerry Cho
 
java-monitoring-troubleshooting
java-monitoring-troubleshootingjava-monitoring-troubleshooting
java-monitoring-troubleshootingWilliam Au
 
Hadoop cluster performance profiler
Hadoop cluster performance profilerHadoop cluster performance profiler
Hadoop cluster performance profilerIhor Bobak
 
Mastering java in containers - MadridJUG
Mastering java in containers - MadridJUGMastering java in containers - MadridJUG
Mastering java in containers - MadridJUGJorge Morales
 
Adopting GraalVM - NE Scala 2019
Adopting GraalVM - NE Scala 2019Adopting GraalVM - NE Scala 2019
Adopting GraalVM - NE Scala 2019Petr Zapletal
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvmPrem Kuppumani
 
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...srisatish ambati
 
Software Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaSoftware Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaIsuru Perera
 

Similar to OSCON2012TroubleShootJava (20)

JavaOne2011BOF18246
JavaOne2011BOF18246JavaOne2011BOF18246
JavaOne2011BOF18246
 
Solr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approachSolr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approach
 
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
Solr Troubleshooting - Treemap Approach: Presented by Alexandre Rafolovitch, ...
 
Java 어플리케이션 성능튜닝 Part1
Java 어플리케이션 성능튜닝 Part1Java 어플리케이션 성능튜닝 Part1
Java 어플리케이션 성능튜닝 Part1
 
7 jvm-arguments-Confoo
7 jvm-arguments-Confoo7 jvm-arguments-Confoo
7 jvm-arguments-Confoo
 
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
 
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
 
Heap & thread dump
Heap & thread dumpHeap & thread dump
Heap & thread dump
 
jcmd #javacasual
jcmd #javacasualjcmd #javacasual
jcmd #javacasual
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 
jvm goes to big data
jvm goes to big datajvm goes to big data
jvm goes to big data
 
java-monitoring-troubleshooting
java-monitoring-troubleshootingjava-monitoring-troubleshooting
java-monitoring-troubleshooting
 
Hadoop cluster performance profiler
Hadoop cluster performance profilerHadoop cluster performance profiler
Hadoop cluster performance profiler
 
Mastering java in containers - MadridJUG
Mastering java in containers - MadridJUGMastering java in containers - MadridJUG
Mastering java in containers - MadridJUG
 
Adopting GraalVM - NE Scala 2019
Adopting GraalVM - NE Scala 2019Adopting GraalVM - NE Scala 2019
Adopting GraalVM - NE Scala 2019
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
 
Software Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaSoftware Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in Java
 

OSCON2012TroubleShootJava

  • 2. 2 Agenda » Tools of the Trade » Case Studies 2
  • 3. 3 Tools – Out Of The Box » jinfo, jmap, jstack, jstat » JConsole, VisualVM –  Monitor CPU usage by using JTop plug-in ($JAVA_HOME/ demo/management/JTop) » java.lang.management –  Platform MXBeans: runtime, operating system, class loading, compilation, garbage collection, memory, thread –  Sample code in $JAVA_HOME/demo/management –  JDK demo and sample was part of JDK download for jdk6u31 or older, separate download for u32+ 3
  • 4. 4 Tools – java.lang.management » Sample code: import java.lang.management.*; ThreadMXBean tb=ManagementFactory.getThreadMXBean(); if (tb.isThreadCpuTimeSupported()) { long[] tids=tb.getAllThreadIds(); for (long tid : tids) { System.out.println(“cputime:”+tb.getThreadCpuTime(tid)); System.out.println(“usertime:”+tb.getThreadUserTime(tid)); } } 4
  • 5. 5 Tools » Garbage collection log –  -Xloggc:<filename> –  Timestamp and duration of GC events –  Sizes before and after GC events –  More options to explore: − -XX:+PrintGCDateStamps − -XX:+PrintGCDetails − -XX:+PrintTenuringDistribution − -XX:+PrintGCApplicationsStoppedTime –  Some GC flags can be set dynamically by jinfo/JConsole/ VisualVM: PrintGC, PrintGCDetails, PrintGCTimeStamps » visualgc – GUI for garbage collection monitoring 5
  • 6. 6 Tools » Thread dump –  kill -3 (or kill –SIGHUP) –  JConsole, VisualVM –  ThreadMXBean –  jstack (-F) » Consecutive thread dumps –  Stop motion animation 6
  • 7. 7 Hung or Slow App » Long GC pauses and/or high GC overhead –  Basic GC tuning − max heap size: -Xmx − type of collector used −  -XX:+UserSerialGC −  -XX:+UseParallelGC/-XX:+UseParallelOldGC −  -XX:+UseConcMarkSweepGC −  -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC (jdk6u14+) –  Advanced GC tuning − young generation size: -Xmn –  Baseline, tune, measure one change at a time » Demo: HPjmeter – garbage collection analysis (and more…) 7
  • 8. 8 Hung or Slow App » Deadlock –  Take thread dump to run the JVM’s deadlock detector » Looping Threads –  Monitor CPU times of running threads − ThreadMXBean − JTop plug-in for JConsole/VisualVM –  Inspect stack trace of suspicious threads 8
  • 9. 9 Slow or Hung App » Blocked threads –  Look for blocked threads waiting on the same condition –  Identify bottleneck for resource contention –  Inspect code for incautious and/or improper synchronization » Demo: samurai – thread dump analysis tool » Stuck threads –  Look for runnable threads with the same stack trace across consecutive thread dumps –  Some common causes: − Blocking for a network call without specifying connect and/or read timeout (default may be no timeout) − Long execution time for calls to backend servers 9