Successfully reported this slideshow.
Your SlideShare is downloading. ×

Need For Speed: JVM Tooling Overview for Vilnius JUG/GDG

Need For Speed: JVM Tooling Overview for Vilnius JUG/GDG

Download to read offline

Monitoring your production JVMs is extremely important. Though, not always you have a luxury of having direct access to production servers, which suffer from performance peaks, memory leaks or concurrency issues. Not always you are able to catch JVM issues without an ability to debug the code in-place. There are quite many tools that can help analyzing performance issues of your JVMs based on real-time monitoring data as well as on logs available only post-mortem. This presentation will give an overview of these tools.

Monitoring your production JVMs is extremely important. Though, not always you have a luxury of having direct access to production servers, which suffer from performance peaks, memory leaks or concurrency issues. Not always you are able to catch JVM issues without an ability to debug the code in-place. There are quite many tools that can help analyzing performance issues of your JVMs based on real-time monitoring data as well as on logs available only post-mortem. This presentation will give an overview of these tools.

More Related Content

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Need For Speed: JVM Tooling Overview for Vilnius JUG/GDG

  1. 1. 01
  2. 2. About me 02
  3. 3. Andrey Adamovich Bio: Developer, coach, speaker, author Company: Aestas/IT (http://aestasit.com) • • 03
  4. 4. Contact details E­mail: andrey@aestasit.com Linkedin: http://www.linkedin.com/in/andreyadamovich Lanyrd: http://lanyrd.com/profile/andrey­adamovich GitHub: https://github.com/aadamovich SO: http://stackoverflow.com/users/162792/andrey­adamovich Twitter: @codingandrey, @aestasit • • • • • • 04
  5. 5. What's in this presentation? 05
  6. 6. The tools 06
  7. 7. The game 07
  8. 8. Rules Picture is shown You guess what the next topic is First one to gues gets a sticker! • • • 08
  9. 9. Let's try! 09
  10. 10. 10
  11. 11. Java's (Hash)Map 11
  12. 12. 12
  13. 13. BigData 13
  14. 14. Let the games begin! 14
  15. 15. 15
  16. 16. GC Pauses 16
  17. 17. What are the good parameters?17
  18. 18. So many options.... 18
  19. 19. So many options.... > java ‐XX:+PrintFlagsFinal ‐version | wc ‐l java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45‐b15) Java HotSpot(TM) 64‐Bit Server VM (build 25.45‐b02, mixed mode) 714 01. 02. 03. 04. 05. 19
  20. 20. So many options.... > java ‐XX:+PrintFlagsFinal ‐version | wc ‐l java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80‐b15) Java HotSpot(TM) 64‐Bit Server VM (build 24.80‐b11, mixed mode) 668 01. 02. 03. 04. 05. 20
  21. 21. So many options.... > java ‐XX:+PrintFlagsFinal ‐version | wc ‐l java version "1.6.0_45" Java(TM) SE Runtime Environment (build 1.6.0_45‐b06) Java HotSpot(TM) 64‐Bit Server VM (build 20.45‐b01, mixed mode) 670 01. 02. 03. 04. 05. 21
  22. 22. So many options.... > java ‐XX:+PrintFlagsFinal ‐version | grep GC | wc ‐l 65 01. 02. 22
  23. 23. Use cases Web application Streaming application Background job • • • 23
  24. 24. Memory tuning? ‐Xms<heap size>[g|m|k]  ‐Xmx<heap size>[g|m|k] ‐XX:PermSize=<perm gen size>[g|m|k]  ‐XX:MaxPermSize=<perm gen size>[g|m|k] ‐Xmn<young size>[g|m|k] ‐XX:SurvivorRatio=<ratio> 01. 02. 03. 04. 05. 06. 24
  25. 25. Leverage multi­core ‐XX:+UseConcMarkSweepGC  ‐XX:+UseCMSInitiatingOccupancyOnly  ‐XX:+ScavengeBeforeFullGC  ‐XX:+CMSScavengeBeforeRemark ‐XX:+CMSConcurrentMTEnabled ‐XX:CMSInitiatingOccupancyFraction=70 01. 02. 03. 04. 05. 06. 25
  26. 26. GC logging ‐XX:+PrintGCDetails  ‐XX:+PrintGCDateStamps  ‐Xloggc:<file‐path>  ‐XX:+PrintGCApplicationConcurrentTime  ‐XX:+PrintSafepointStatistics  ‐XX:+PrintHeapAtGC 01. 02. 03. 04. 05. 06. 26
  27. 27. Log analysis 27
  28. 28. Open source: GCViewer 28
  29. 29. Comercial: Censum 29
  30. 30. Next riddle 30
  31. 31. 31
  32. 32. Memory dumps 32
  33. 33. How to take? On out of memory: ‐XX:+HeapDumpOnOutOfMemoryError  ‐XX:HeapDumpPath=<path to dump>`date`.hprof Or manually: jmap ‐dump:file=<path to dump> <java process id> 01. 02. 01. 33
  34. 34. jhat 34
  35. 35. Eclipse MAT 35
  36. 36. OQL 36
  37. 37. Useful characteristics Object Retained Size Object Shallow Size Stale Objects (not connected to GC roots) • • • 37
  38. 38. Flight Recording 38
  39. 39. Comercial YourKit jProfiler • • 39
  40. 40. Next riddle 40
  41. 41. 41
  42. 42. Thread dumps 42
  43. 43. Situations Dead locks 100% CPU load Hanging I/O • • • 43
  44. 44. jstack jstack <java process pid>01. 44
  45. 45. JMX Use MBean with name  java.lang:type=Threading Call  getAllThreadIds Loop through all retrieved IDs and call  getThreadInfo • • • 45
  46. 46. The cheapest profiler for ((a=1; a <= 60; a++)) do    jstack 7789 > thread‐dump.$a   sleep 1   echo $a done 01. 02. 03. 04. 05. 06. 46
  47. 47. Thread dump analysis 47
  48. 48. TDA 48
  49. 49. Samurai 49
  50. 50. IBM TMDA 50
  51. 51. Use custom scripts 51
  52. 52. Next riddle 52
  53. 53. 53
  54. 54. Debugging 54
  55. 55. We need it when we have... Non­reproducable issues Hard­to­understand code • • 55
  56. 56. Enable debugging ‐agentlib:jdwp=transport=dt_socket,server=y,address=133701. 56
  57. 57. Use your IDE (Eclipse) 57
  58. 58. Use your IDE (Intellij IDEA) 58
  59. 59. jdb 59
  60. 60. jdb 60
  61. 61. YouDebug 61
  62. 62. YouDebug (buggy class) public class SubStringTest {   public static void main(String[] args) {     String s = someLengthComputationOfString();     System.out.println(s.substring(5));   }   private static String someLengthComputationOfString() {     ...;   } } 01. 02. 03. 04. 05. 06. 07. 08. 09. 62
  63. 63. YouDebug (SubStringMonitor.ydb) breakpoint("com.acme.SubStringTest",3) {   println "s="+s; } 01. 02. 03. 63
  64. 64. YouDebug (run debugger) > java ‐jar youdebug.jar ‐socket 1337 SubStringMonitor.ydb s=test 01. 02. 64
  65. 65. Next riddle 65
  66. 66. 66
  67. 67. Decompiling 67
  68. 68. Java Decompiler 68
  69. 69. Java Decompiler 69
  70. 70. Issues Lack of support for latest JVM features Lack of support for other JVM langauges Obfuscation is always an issue • • • 70
  71. 71. Next riddle 71
  72. 72. 72
  73. 73. Profiling 73
  74. 74. Types of profiling Memory allocation profiling CPU profiling Lock profiling • • • 74
  75. 75. VisualVM 75
  76. 76. Comercial YourKit jProfiler • • 76
  77. 77. Next riddle 77
  78. 78. 78
  79. 79. Benchmarks 79
  80. 80. JMH MH is a Java harness for building, running, and analysing nano/micro/milli/macro benchmarks written in Java and other languages targetting the JVM. “ 80
  81. 81. JMH: example package org.openjdk.jmh.samples; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.runner.Runner; import org.openjdk.jmh.runner.RunnerException; import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; 01. 02.03. 04. 05. 06. 07. 81
  82. 82. JHM: example public class JMHSample_01_HelloWorld {   @Benchmark   public void wellHelloThere() {     // this method was intentionally left blank.   } 01. 02. 03. 04. 05. 82
  83. 83. JMH: example   public static void main(String[] args) throws RunnerException {     Options opt = new OptionsBuilder()             .include(JMHSample_01_HelloWorld.class.getSimpleName()             .forks(1)             .build();     new Runner(opt).run();   } } 01. 02. 03. 04. 05. 06. 07. 08. 83
  84. 84. JMH: example > mvn clean install > java ‐jar target/benchmarks.jar JMHSample_01_HelloWorld 01. 02. 84
  85. 85. JMH: annotations @Benchmark @BenchmarkMode @CompilerControl  @Fork @Group @GroupThreads @Level @Measurement @Mode @OperationsPerInvocation @OutputTimeUnit @Param @Scope @Setup @State @TearDown @Threads @Timeout @Warmup 01. 02. 03. 04. 05. 06. 85
  86. 86. JMH: output 86
  87. 87. Load testing tools jMeter gatling • • 87
  88. 88. Next riddle 88
  89. 89. 89
  90. 90. Monitoring 90
  91. 91. JMX is your friend! 91
  92. 92. VisualVM (again) 92
  93. 93. Mission Control 93
  94. 94. Metrics collection 94
  95. 95. JMXTrans This is effectively the missing connector between speaking to a JVM via JMX on one end and whatever logging / monitoring / graphing package that you can dream up on the other end. “ 95
  96. 96. jHiccup jHiccup is a non­intrusive instrumentation tool that logs and records platform "hiccups" ­ including the JVM stalls that often happen when Java applications are executed and/or any OS or hardware platform noise that may cause the running application to not be continuously runnable. “ 96
  97. 97. jHiccup > java ‐javaagent:jHiccup.jar MyProgram01. 97
  98. 98. jHiccup 98
  99. 99. Drop Wizard Metrics Metrics provides a powerful toolkit of ways to measure the behavior of critical components in your production environment. “ 99
  100. 100. Netflix Hysterix 100
  101. 101. Stagemonitor 101
  102. 102. 102
  103. 103. Single JVM? 103
  104. 104. Really? 104
  105. 105. 105
  106. 106. Dead JVM 106
  107. 107. 107
  108. 108. Many JVMs 108
  109. 109. Open­source tools Graphite Graphana Logstash Kibana Graylog2 Fluentd • • • • • • 109
  110. 110. Comercial tools NewRelic Plumbr AppDynamics Dyntrace Takipi Hyperic • • • • • • 110
  111. 111. Final riddle 111
  112. 112. 112
  113. 113. Links 113
  114. 114. Links: GC http://spin.atomicobject.com/2014/09/03/visualizing­garbage­ collection­algorithms/ http://techblog.netflix.com/2013/05/garbage­collection­ visualization.html http://blog.sokolenko.me/2014/11/javavm­options­production.html https://blog.codecentric.de/en/2013/10/useful­jvm­flags­part­7­cms­ collector/ • • • • 114
  115. 115. Links: GC http://blog.ragozin.info/2011/09/hotspot­jvm­garbage­collection­ options.html http://blog.tier1app.com/2014/11/19/understand­garbage­collection­ log/ http://www.tagtraum.com/gcviewer­vmflags.html • • • 115
  116. 116. Links: GC http://fasterj.com/tools/gcloganalysers.shtml https://github.com/chewiebug/GCViewer http://www.jclarity.com/censum/ • • • 116
  117. 117. Links: Tools https://github.com/akullpp/awesome­java https://github.com/aragozin/jvm­tools http://openjdk.java.net/projects/code­tools/jmh/ • • • 117
  118. 118. Links: Tools http://youdebug.kohsuke.org/ https://java.net/projects/tda http://samuraism.jp/samurai/en/index.html • • • 118
  119. 119. Links: Tools https://github.com/jmxtrans/jmxtrans http://www.stagemonitor.org/ http://jamonapi.sourceforge.net/ https://github.com/Netflix/Hystrix • • • • 119
  120. 120. Links: Tools http://www.eclipse.org/tptp/home/documents/tutorials/profilingtool/profilingexample• 120
  121. 121. Reading material 121
  122. 122. Java Performance 122
  123. 123. Java Performance: The Defenetive Guide 123
  124. 124. Java Performance And Scalability 124
  125. 125. This is it! 125
  126. 126. Questions? 126
  127. 127. Thank you! 127

×