SlideShare a Scribd company logo
1 of 10
Download to read offline
Bill Au
CBS Interactive
http://www.apache.org/~billa/javaone2011/
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
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>
–  Sizes before and after GC events
–  Timestamp and duration of GC events
–  More options to explore:
− -XX:+PrintGCDateStamps
− -XX:+PrintGCDetails
− -XX:+PrintTenuringDistribution
−  -XX:+PrintGCApplicationsStoppedTime
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
Source: TBD
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/javaone2011
» HPjmeter
https://h20392.www2.hp.com/portal/swdepot/
displayProductInfo.do?productNumber=HPJMETER
» samurai
http://yusuke.homeip.net/samurai/en/index.html
10

More Related Content

Viewers also liked

Phoebe Certificate
Phoebe CertificatePhoebe Certificate
Phoebe CertificatePhoebe Leong
 
Water Conservation
Water ConservationWater Conservation
Water ConservationMadhav Biju
 
Employee retention-tipsheet
Employee retention-tipsheetEmployee retention-tipsheet
Employee retention-tipsheetAmanda Winstead
 
EECS 441 - Lapka (Company Presentations)
EECS 441 - Lapka (Company Presentations)EECS 441 - Lapka (Company Presentations)
EECS 441 - Lapka (Company Presentations)Avery McIntyre
 
Understanding Informix Network Performance Features
Understanding Informix Network Performance FeaturesUnderstanding Informix Network Performance Features
Understanding Informix Network Performance FeaturesJohn Miller
 
informix Embeddability and Autonomics
informix Embeddability and Autonomicsinformix Embeddability and Autonomics
informix Embeddability and AutonomicsJohn Miller
 
java-monitoring-troubleshooting
java-monitoring-troubleshootingjava-monitoring-troubleshooting
java-monitoring-troubleshootingWilliam Au
 
Informix 1210 feature overview
Informix 1210 feature overviewInformix 1210 feature overview
Informix 1210 feature overviewJohn Miller
 

Viewers also liked (9)

Leading lean
Leading leanLeading lean
Leading lean
 
Phoebe Certificate
Phoebe CertificatePhoebe Certificate
Phoebe Certificate
 
Water Conservation
Water ConservationWater Conservation
Water Conservation
 
Employee retention-tipsheet
Employee retention-tipsheetEmployee retention-tipsheet
Employee retention-tipsheet
 
EECS 441 - Lapka (Company Presentations)
EECS 441 - Lapka (Company Presentations)EECS 441 - Lapka (Company Presentations)
EECS 441 - Lapka (Company Presentations)
 
Understanding Informix Network Performance Features
Understanding Informix Network Performance FeaturesUnderstanding Informix Network Performance Features
Understanding Informix Network Performance Features
 
informix Embeddability and Autonomics
informix Embeddability and Autonomicsinformix Embeddability and Autonomics
informix Embeddability and Autonomics
 
java-monitoring-troubleshooting
java-monitoring-troubleshootingjava-monitoring-troubleshooting
java-monitoring-troubleshooting
 
Informix 1210 feature overview
Informix 1210 feature overviewInformix 1210 feature overview
Informix 1210 feature overview
 

Similar to JavaOne2011BOF18246

Hadoop cluster performance profiler
Hadoop cluster performance profilerHadoop cluster performance profiler
Hadoop cluster performance profilerIhor Bobak
 
JBoss Enterprise Application Platform 6 Troubleshooting
JBoss Enterprise Application Platform 6 TroubleshootingJBoss Enterprise Application Platform 6 Troubleshooting
JBoss Enterprise Application Platform 6 TroubleshootingAlexandre Cavalcanti
 
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
 
First Flink Bay Area meetup
First Flink Bay Area meetupFirst Flink Bay Area meetup
First Flink Bay Area meetupKostas Tzoumas
 
jcmd #javacasual
jcmd #javacasualjcmd #javacasual
jcmd #javacasualYuji Kubota
 
Jdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsJdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsDror Bereznitsky
 
Web Sphere Problem Determination Ext
Web Sphere Problem Determination ExtWeb Sphere Problem Determination Ext
Web Sphere Problem Determination ExtRohit Kelapure
 
Adopting GraalVM - NE Scala 2019
Adopting GraalVM - NE Scala 2019Adopting GraalVM - NE Scala 2019
Adopting GraalVM - NE Scala 2019Petr Zapletal
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time OptimizationKan-Ru Chen
 
Adopting GraalVM - Scala eXchange London 2018
Adopting GraalVM - Scala eXchange London 2018Adopting GraalVM - Scala eXchange London 2018
Adopting GraalVM - Scala eXchange London 2018Petr Zapletal
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
7 jvm-arguments-v1
7 jvm-arguments-v17 jvm-arguments-v1
7 jvm-arguments-v1Tier1 app
 
Best Practices for performance evaluation and diagnosis of Java Applications ...
Best Practices for performance evaluation and diagnosis of Java Applications ...Best Practices for performance evaluation and diagnosis of Java Applications ...
Best Practices for performance evaluation and diagnosis of Java Applications ...IndicThreads
 
this-is-garbage-talk-2022.pptx
this-is-garbage-talk-2022.pptxthis-is-garbage-talk-2022.pptx
this-is-garbage-talk-2022.pptxTier1 app
 
QA Fest 2019. Антон Молдован. Load testing which you always wanted
QA Fest 2019. Антон Молдован. Load testing which you always wantedQA Fest 2019. Антон Молдован. Load testing which you always wanted
QA Fest 2019. Антон Молдован. Load testing which you always wantedQAFest
 

Similar to JavaOne2011BOF18246 (20)

Hadoop cluster performance profiler
Hadoop cluster performance profilerHadoop cluster performance profiler
Hadoop cluster performance profiler
 
JBoss Enterprise Application Platform 6 Troubleshooting
JBoss Enterprise Application Platform 6 TroubleshootingJBoss Enterprise Application Platform 6 Troubleshooting
JBoss Enterprise Application Platform 6 Troubleshooting
 
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, ...
 
[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe
 
First Flink Bay Area meetup
First Flink Bay Area meetupFirst Flink Bay Area meetup
First Flink Bay Area meetup
 
jcmd #javacasual
jcmd #javacasualjcmd #javacasual
jcmd #javacasual
 
Jdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsJdk Tools For Performance Diagnostics
Jdk Tools For Performance Diagnostics
 
Web Sphere Problem Determination Ext
Web Sphere Problem Determination ExtWeb Sphere Problem Determination Ext
Web Sphere Problem Determination Ext
 
Adopting GraalVM - NE Scala 2019
Adopting GraalVM - NE Scala 2019Adopting GraalVM - NE Scala 2019
Adopting GraalVM - NE Scala 2019
 
Web review
Web reviewWeb review
Web review
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
jvm goes to big data
jvm goes to big datajvm goes to big data
jvm goes to big data
 
Adopting GraalVM - Scala eXchange London 2018
Adopting GraalVM - Scala eXchange London 2018Adopting GraalVM - Scala eXchange London 2018
Adopting GraalVM - Scala eXchange London 2018
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
7 jvm-arguments-v1
7 jvm-arguments-v17 jvm-arguments-v1
7 jvm-arguments-v1
 
Best Practices for performance evaluation and diagnosis of Java Applications ...
Best Practices for performance evaluation and diagnosis of Java Applications ...Best Practices for performance evaluation and diagnosis of Java Applications ...
Best Practices for performance evaluation and diagnosis of Java Applications ...
 
this-is-garbage-talk-2022.pptx
this-is-garbage-talk-2022.pptxthis-is-garbage-talk-2022.pptx
this-is-garbage-talk-2022.pptx
 
QA Fest 2019. Антон Молдован. Load testing which you always wanted
QA Fest 2019. Антон Молдован. Load testing which you always wantedQA Fest 2019. Антон Молдован. Load testing which you always wanted
QA Fest 2019. Антон Молдован. Load testing which you always wanted
 

JavaOne2011BOF18246

  • 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 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> –  Sizes before and after GC events –  Timestamp and duration of GC events –  More options to explore: − -XX:+PrintGCDateStamps − -XX:+PrintGCDetails − -XX:+PrintTenuringDistribution −  -XX:+PrintGCApplicationsStoppedTime 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 Source: TBD
  • 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