Java Application Problems: Diagnostics

3,422 views

Published on

Have you got a problem in your running application? Learn how to use standard tools to get root cause.

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • If you're interested in realtime garbage collection monitoring you can also take a look at this free VisualVM plugin: http://www.spyglasstools.com/documentation/spyglass-garbage-collector-analyzer/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total views
3,422
On SlideShare
0
From Embeds
0
Number of Embeds
2,320
Actions
Shares
0
Downloads
28
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Java Application Problems: Diagnostics

  1. 1. Java Application Problems Diagnostics Vitalii Tymchyshyn Twitter: @tivv00 Email: tivv00@gmail.com
  2. 2. ContentsProblem typesProblem causesPrepare in advanceDiagnostics checklistStack tracesJava memory
  3. 3. Common Problem typesResource underutilizationSlowness in long runSudden haltsDisappearing applicationsProblems under load
  4. 4. Common Root CausesDeadlocks / Wrong lock orderingNarrow points / Wide locksLeaksHidden exceptionsUnhandled exceptionsInvalid OS/JVM configuration
  5. 5. Prepare: Logging hintsLog stdout/stderr – it has JVM outputLog application start/stop with error codeEnable GC loggingLog exception if you dont rethrow or process itLog FATAL in any place you call System.exitLog all thread stacks in multithreading guard code
  6. 6. Prepare: Setting up VM-verbose:gc – output GC to stderr-XX:+HeapDumpOnOutOfMemoryError-XX:+PrintClassHistogram – print class histogram along with thread stacks on Ctrl- / kill -3-XX:MaxNewSize – tame new generation for large heaps
  7. 7. Diagnostics checklistCheck your host: CPU/IO/Network usage, serious swappingCheck your VM: Heap/GC times, finalizer thread blockDeadlocks/Lock contentionExternal servicesLeaks / Peaks / Working set increase
  8. 8. Unix OS metricstop, vmstat, iostat Load average < Cores * 10 System time < 30% Context switches < Cores * 10000 Wait time means IO Swap Used < RAM/4 Swap IN/OUT < 1mb/1
  9. 9. Listing running java VMsjps -vvm For current user (as most of JVM tools) Shows PID Shows full command line including JVM options, system variables, full class name and program options Especially useful if program was started with a script
  10. 10. Getting stack tracesCtrl-Break (windows) / Ctrl- (Unix)Kill -3 <PID>jstackjconsoleIDEdebugger
  11. 11. What stack can tell youObvious deadlocksNarrow pointsSimplistic CPU profilingExternal resource overutilization/deadlock
  12. 12. JVM memory structureJava HeapThread StacksNative memory (UI can eat quite a lot)Permanent generation (classes / interned strings)Byte Buffers (often used as off-heap storage)Mapped files
  13. 13. Java HeapHas fixed upper limitStarts to take a lot of time when almost fullCan be tuned a lot (and often should be)GC activity logging should be enabledYou can enable printing overview on “kill -3”You can enable heap dump on OOM
  14. 14. Utilities to get heap informationjstack: some totalsjstat: detailed totalsjmap: get heap overview / dumpjconsole: force GC, collect GUI stats, make dump...Eclipse MAT: my preferred tool to analyze heap dumps

×