SlideShare une entreprise Scribd logo
1  sur  14
Télécharger pour lire hors ligne
Java Monitoring and
Troubleshooting Tools
In Action
Bill Au
billa@apache.org
http://www.apache.org/~billa/apacheconus2008/
Agenda
• Monitoring
• Thread and Heap Dump
• Hung or Slow App
• OutOfMemoryError
• JVM crashes
Monitoring - java.lang.management
• RuntimeMXBean
• OperatingSystemMXBean
• ClassLoadingMXBean
• CompilationMXBean
• GarbageCollectorMXBean
• MemoryMXBean, MemoryPoolMXBean
• ThreadMXBean
Sample code in $JAVA_HOME/demo/management/
Monitoring - 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));
}
}
Monitoring - tools
• JDK command line utilties
– jinfo, jmap, jstack
– jstat
• jconsole
– Monitor CPU usage by using JTop plug-in
($JAVA_HOME/demo/management/JTop)
• Garbage collection log: -Xloggc:<filename>
– Timestamp and duration of GC
– Heap size before and after GC
Thread and Heap Dump
• Thread dump
– kill -3 (or kill –SIGQUIT)
– ThreadMXBean
– jstack
– jconsole
• Heap dump
– -XX:+HeapDumpOnOutOfMemoryError
– jmap
– jconsole
– hprof – beware of overhead (all object
allocation is instrumented)
Hung or Slow App
• Long GC pauses and/or high GC overhead
– GC tuning (heap size, serial/parallel/concurrent
collector, etc)
– Baseline, tune, measure one change at a time
– Beware of over-optimizing
• Deadlock
– Take thread dump to run the deadlock detector
• Loop threads
– Monitor CPU times of thread (ThreadMXBean,
jconsole with JTop), inspect stack trace of
suspicious threads
Hung or Slow App
• Blocked threads
– Analyze thread dumps for resource contention
– Look for incautious and/or improper
synchronization
• 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 a
connect or read timeout (default may be no timeout)
• Long execution time for calls to backend servers
OutOfMemoryError - heap
Java heap space
GC overhead limit exceeded
Requested array size exceeds VM limit
• Heap too small
– Adjust maximum heap size (-Xms<size>)
• Excessive use of finalizers
– Monitor objects pending finalization
(MemoryMXBean, jmap, jconsole)
• look for logic error in array allocation code
• Memory leak
– Analyze heap dump
OutOfMemoryError – Permanent
Generation
PermGen space
• Permanent generation too small
– Adjust maximum permanent generation size (
-XX:MaxPermSize<size>)
• Classloader leak
– Look for leaked threads
– Use jhat to look for leaked classloader in a
heap dump
OutOfMemoryError – too many
threads
unable to create new native thread
• Each Java thread has a native thread with
its own stack
– Lower maximum number of threads
– Decrease maximum stack size (-Xss<size>)
• watch out for StackOverflowError
OutOfMemoryError – native
memory
Request <size> bytes for <reason>. Out of swap space?
<reason> <stack trace> (Native method)
• System running out of memory
– Check memory usage of other processes
• Process exceeds maximum process size
– Reduce heap or stack memory usage
• Leak in JNI or native method
• Leak in VM code
– Upgrade to the latest update release
– Check fatal error log (hs_err_<pid>.log)
JVM Crashes
• Upgrade to the latest update release
• Check fatal error log (hs_err_<pid>.log)
• Look for workaround
– Sun’s bug database (http://bugs.sun.com/)
– Sun’s Java forum
(http://forum.java.sun.com/index.jspa)
– Google
– Post to Sun’s Java forum and/or open a bug
JVM Crashes
• Possible workaround:
– Different JVM mode (server/client) on 32-bit
machine
– Different collector for GC related crashes
– Run the JVM in interpreted mode (-Xint) for
compiled Java code or compiler related crashes

Contenu connexe

Tendances

Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Ontico
 
Casual mass parallel data processing in Java
Casual mass parallel data processing in JavaCasual mass parallel data processing in Java
Casual mass parallel data processing in Java
Altoros
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
Charles Nutter
 
Tsung Intro presentation 2013
Tsung Intro presentation 2013Tsung Intro presentation 2013
Tsung Intro presentation 2013
Steffen Larsen
 
Easy distributed load test with Tsung
Easy distributed load test with TsungEasy distributed load test with Tsung
Easy distributed load test with Tsung
Ngoc Dao
 

Tendances (20)

PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
 
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
Tarantool как платформа для микросервисов / Антон Резников, Владимир Перепели...
 
Casual mass parallel data processing in Java
Casual mass parallel data processing in JavaCasual mass parallel data processing in Java
Casual mass parallel data processing in Java
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
Tsung Intro presentation 2013
Tsung Intro presentation 2013Tsung Intro presentation 2013
Tsung Intro presentation 2013
 
Streaming huge databases using logical decoding
Streaming huge databases using logical decodingStreaming huge databases using logical decoding
Streaming huge databases using logical decoding
 
Tools for Metaspace
Tools for MetaspaceTools for Metaspace
Tools for Metaspace
 
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
100500 способов кэширования в Oracle Database или как достичь максимальной ск...100500 способов кэширования в Oracle Database или как достичь максимальной ск...
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
 
Hypertable Nosql
Hypertable NosqlHypertable Nosql
Hypertable Nosql
 
Easy distributed load test with Tsung
Easy distributed load test with TsungEasy distributed load test with Tsung
Easy distributed load test with Tsung
 
Memcached B box presentation
Memcached B box presentationMemcached B box presentation
Memcached B box presentation
 
Adopting GraalVM - Scala eXchange London 2018
Adopting GraalVM - Scala eXchange London 2018Adopting GraalVM - Scala eXchange London 2018
Adopting GraalVM - Scala eXchange London 2018
 
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
PostgreSQL Configuration for Humans / Alvaro Hernandez (OnGres)
 
Scaling symfony apps
Scaling symfony appsScaling symfony apps
Scaling symfony apps
 
MongoDb scalability and high availability with Replica-Set
MongoDb scalability and high availability with Replica-SetMongoDb scalability and high availability with Replica-Set
MongoDb scalability and high availability with Replica-Set
 
Massively Scaled High Performance Web Services with PHP
Massively Scaled High Performance Web Services with PHPMassively Scaled High Performance Web Services with PHP
Massively Scaled High Performance Web Services with PHP
 
The Art of JVM Profiling
The Art of JVM ProfilingThe Art of JVM Profiling
The Art of JVM Profiling
 
Perl Dist::Surveyor 2011
Perl Dist::Surveyor 2011Perl Dist::Surveyor 2011
Perl Dist::Surveyor 2011
 
Storing 16 Bytes at Scale
Storing 16 Bytes at ScaleStoring 16 Bytes at Scale
Storing 16 Bytes at Scale
 
Ch10.애플리케이션 서버의 병목_발견_방법
Ch10.애플리케이션 서버의 병목_발견_방법Ch10.애플리케이션 서버의 병목_발견_방법
Ch10.애플리케이션 서버의 병목_발견_방법
 

En vedette

Superhero training- portfolio
Superhero training- portfolioSuperhero training- portfolio
Superhero training- portfolio
Ashton Reisner
 
INTS330 What is Integrative Studies
INTS330 What is Integrative StudiesINTS330 What is Integrative Studies
INTS330 What is Integrative Studies
Kali Morrison
 

En vedette (20)

Hackathon CrazyTechLabs Xamarin Brasília 2015 - Abertura
Hackathon CrazyTechLabs Xamarin Brasília 2015 - AberturaHackathon CrazyTechLabs Xamarin Brasília 2015 - Abertura
Hackathon CrazyTechLabs Xamarin Brasília 2015 - Abertura
 
Superhero training- portfolio
Superhero training- portfolioSuperhero training- portfolio
Superhero training- portfolio
 
COMPETING ON ANLYTICS
COMPETING ON ANLYTICSCOMPETING ON ANLYTICS
COMPETING ON ANLYTICS
 
Sexualitat amagada
Sexualitat amagadaSexualitat amagada
Sexualitat amagada
 
Down to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap DumpsDown to Stack Traces, up from Heap Dumps
Down to Stack Traces, up from Heap Dumps
 
Actividad individual 1 gerardo pai ponte
Actividad individual  1 gerardo pai ponteActividad individual  1 gerardo pai ponte
Actividad individual 1 gerardo pai ponte
 
Erasmus+ croatia(1) poland
Erasmus+ croatia(1) polandErasmus+ croatia(1) poland
Erasmus+ croatia(1) poland
 
윈도우 10 업그레이드 가이드
윈도우 10 업그레이드 가이드윈도우 10 업그레이드 가이드
윈도우 10 업그레이드 가이드
 
Reporter/a de la setmana
Reporter/a de la setmanaReporter/a de la setmana
Reporter/a de la setmana
 
Soft Skill 1
Soft Skill 1Soft Skill 1
Soft Skill 1
 
Slave Negro Pro Se Plaintiff Louis Charles Hamilton II (USN) Vs. United Sta...
  Slave Negro Pro Se Plaintiff Louis Charles Hamilton II (USN) Vs. United Sta...  Slave Negro Pro Se Plaintiff Louis Charles Hamilton II (USN) Vs. United Sta...
Slave Negro Pro Se Plaintiff Louis Charles Hamilton II (USN) Vs. United Sta...
 
Oracle hcm track manager
Oracle hcm track managerOracle hcm track manager
Oracle hcm track manager
 
Water Conservation
Water ConservationWater Conservation
Water Conservation
 
Hive NYC Project Learning Lab: TASC presentation
Hive NYC Project Learning Lab: TASC presentation Hive NYC Project Learning Lab: TASC presentation
Hive NYC Project Learning Lab: TASC presentation
 
Plantas Vintage Way Sao Conrado
Plantas Vintage Way Sao ConradoPlantas Vintage Way Sao Conrado
Plantas Vintage Way Sao Conrado
 
INTS330 What is Integrative Studies
INTS330 What is Integrative StudiesINTS330 What is Integrative Studies
INTS330 What is Integrative Studies
 
Elearning Module Creation Process and Tools
Elearning Module Creation Process and ToolsElearning Module Creation Process and Tools
Elearning Module Creation Process and Tools
 
Presentasi Knowledge Management System
Presentasi Knowledge Management SystemPresentasi Knowledge Management System
Presentasi Knowledge Management System
 
Freedom Lines
Freedom LinesFreedom Lines
Freedom Lines
 
Sonarqube 20160509
Sonarqube 20160509Sonarqube 20160509
Sonarqube 20160509
 

Similaire à java-monitoring-troubleshooting

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
 
Tomcatx troubleshooting-production
Tomcatx troubleshooting-productionTomcatx troubleshooting-production
Tomcatx troubleshooting-production
Vladimir Khokhryakov
 
OSCON2012TroubleShootJava
OSCON2012TroubleShootJavaOSCON2012TroubleShootJava
OSCON2012TroubleShootJava
William Au
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
CodeIgniter Conference
 
JavaOne2011BOF18246
JavaOne2011BOF18246JavaOne2011BOF18246
JavaOne2011BOF18246
William Au
 
Web Sphere Problem Determination Ext
Web Sphere Problem Determination ExtWeb Sphere Problem Determination Ext
Web Sphere Problem Determination Ext
Rohit Kelapure
 

Similaire à java-monitoring-troubleshooting (20)

Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
 
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, ...
 
Tomcatx troubleshooting-production
Tomcatx troubleshooting-productionTomcatx troubleshooting-production
Tomcatx troubleshooting-production
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
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...
 
#GeodeSummit - Off-Heap Storage Current and Future Design
#GeodeSummit - Off-Heap Storage Current and Future Design#GeodeSummit - Off-Heap Storage Current and Future Design
#GeodeSummit - Off-Heap Storage Current and Future Design
 
OSCON2012TroubleShootJava
OSCON2012TroubleShootJavaOSCON2012TroubleShootJava
OSCON2012TroubleShootJava
 
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
 
JBoss Enterprise Application Platform 6 Troubleshooting
JBoss Enterprise Application Platform 6 TroubleshootingJBoss Enterprise Application Platform 6 Troubleshooting
JBoss Enterprise Application Platform 6 Troubleshooting
 
Bottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMPBottom to Top Stack Optimization with LAMP
Bottom to Top Stack Optimization with LAMP
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
 
ApacheCon2010: Cache & Concurrency Considerations in Cassandra (& limits of JVM)
ApacheCon2010: Cache & Concurrency Considerations in Cassandra (& limits of JVM)ApacheCon2010: Cache & Concurrency Considerations in Cassandra (& limits of JVM)
ApacheCon2010: Cache & Concurrency Considerations in Cassandra (& limits of JVM)
 
JavaOne2011BOF18246
JavaOne2011BOF18246JavaOne2011BOF18246
JavaOne2011BOF18246
 
Apache Geode Offheap Storage
Apache Geode Offheap StorageApache Geode Offheap Storage
Apache Geode Offheap Storage
 
Web Sphere Problem Determination Ext
Web Sphere Problem Determination ExtWeb Sphere Problem Determination Ext
Web Sphere Problem Determination Ext
 
Modern Engineer’s Troubleshooting Tools, Techniques & Tricks at Confoo 2018
Modern Engineer’s Troubleshooting Tools, Techniques & Tricks at Confoo 2018Modern Engineer’s Troubleshooting Tools, Techniques & Tricks at Confoo 2018
Modern Engineer’s Troubleshooting Tools, Techniques & Tricks at Confoo 2018
 
Caching your rails application
Caching your rails applicationCaching your rails application
Caching your rails application
 
Debugging Your Production JVM
Debugging Your Production JVMDebugging Your Production JVM
Debugging Your Production JVM
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
 

java-monitoring-troubleshooting

  • 1. Java Monitoring and Troubleshooting Tools In Action Bill Au billa@apache.org http://www.apache.org/~billa/apacheconus2008/
  • 2. Agenda • Monitoring • Thread and Heap Dump • Hung or Slow App • OutOfMemoryError • JVM crashes
  • 3. Monitoring - java.lang.management • RuntimeMXBean • OperatingSystemMXBean • ClassLoadingMXBean • CompilationMXBean • GarbageCollectorMXBean • MemoryMXBean, MemoryPoolMXBean • ThreadMXBean Sample code in $JAVA_HOME/demo/management/
  • 4. Monitoring - 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)); } }
  • 5. Monitoring - tools • JDK command line utilties – jinfo, jmap, jstack – jstat • jconsole – Monitor CPU usage by using JTop plug-in ($JAVA_HOME/demo/management/JTop) • Garbage collection log: -Xloggc:<filename> – Timestamp and duration of GC – Heap size before and after GC
  • 6. Thread and Heap Dump • Thread dump – kill -3 (or kill –SIGQUIT) – ThreadMXBean – jstack – jconsole • Heap dump – -XX:+HeapDumpOnOutOfMemoryError – jmap – jconsole – hprof – beware of overhead (all object allocation is instrumented)
  • 7. Hung or Slow App • Long GC pauses and/or high GC overhead – GC tuning (heap size, serial/parallel/concurrent collector, etc) – Baseline, tune, measure one change at a time – Beware of over-optimizing • Deadlock – Take thread dump to run the deadlock detector • Loop threads – Monitor CPU times of thread (ThreadMXBean, jconsole with JTop), inspect stack trace of suspicious threads
  • 8. Hung or Slow App • Blocked threads – Analyze thread dumps for resource contention – Look for incautious and/or improper synchronization • 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 a connect or read timeout (default may be no timeout) • Long execution time for calls to backend servers
  • 9. OutOfMemoryError - heap Java heap space GC overhead limit exceeded Requested array size exceeds VM limit • Heap too small – Adjust maximum heap size (-Xms<size>) • Excessive use of finalizers – Monitor objects pending finalization (MemoryMXBean, jmap, jconsole) • look for logic error in array allocation code • Memory leak – Analyze heap dump
  • 10. OutOfMemoryError – Permanent Generation PermGen space • Permanent generation too small – Adjust maximum permanent generation size ( -XX:MaxPermSize<size>) • Classloader leak – Look for leaked threads – Use jhat to look for leaked classloader in a heap dump
  • 11. OutOfMemoryError – too many threads unable to create new native thread • Each Java thread has a native thread with its own stack – Lower maximum number of threads – Decrease maximum stack size (-Xss<size>) • watch out for StackOverflowError
  • 12. OutOfMemoryError – native memory Request <size> bytes for <reason>. Out of swap space? <reason> <stack trace> (Native method) • System running out of memory – Check memory usage of other processes • Process exceeds maximum process size – Reduce heap or stack memory usage • Leak in JNI or native method • Leak in VM code – Upgrade to the latest update release – Check fatal error log (hs_err_<pid>.log)
  • 13. JVM Crashes • Upgrade to the latest update release • Check fatal error log (hs_err_<pid>.log) • Look for workaround – Sun’s bug database (http://bugs.sun.com/) – Sun’s Java forum (http://forum.java.sun.com/index.jspa) – Google – Post to Sun’s Java forum and/or open a bug
  • 14. JVM Crashes • Possible workaround: – Different JVM mode (server/client) on 32-bit machine – Different collector for GC related crashes – Run the JVM in interpreted mode (-Xint) for compiled Java code or compiler related crashes