using java mission control & java flight recorder
TRANSCRIPT
![Page 1: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/1.jpg)
Great tools in Java Development Kit
05 November 2014
Senior Software Engineer
M. Isuru Tharanga Chrishantha Perera
Using Java Mission Control & Java Flight Recorder
![Page 2: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/2.jpg)
2
Agenda
๏ What is Java Mission Control (JMC)
๏ Java Flight Recorder (JFR)
๏ Using JMC
๏ Demos
![Page 3: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/3.jpg)
What is Java Mission Control?
๏ A set of powerful tools running on the Oracle JDK to monitor and manage Java applications
๏ Less performance overhead
๏ Free for development use (Oracle Binary Code License)
๏ Available in JDK since Java 7 update 40
๏ Two main tools: JMX Console & JFR
๏ Supports Plugins
3
![Page 4: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/4.jpg)
Java Process Browser
๏ Uses the Java Discovery Protocol (JDP).
๏ Allows to list and connect to both locally and remotely running Java applications.
๏ JMC provides full secure access with encrypted communication and configurable user access restrictions.
4
![Page 5: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/5.jpg)
JMX Console
๏ A tool for monitoring and managing multiple Oracle JDK instances via JMX interface
๏ Captures and presents live data about:
๏ Garbage Collection (GC) Pauses
๏ Memory (Heap Usage)
๏ CPU Usage
๏ Other attributes exposes via Mbeans
๏ Provides triggers that can monitor Mbeans and trigger an action
5
![Page 6: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/6.jpg)
Java Flight Recorder
๏ A profiling and event collection framework built into the Oracle JDK
๏ Gather low level information about the JVM and application are behaving without performance impact (less than 2%)
๏ Always on Profiling in Production Environments
๏ It’s like the “black box” used in aircraft
6
![Page 7: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/7.jpg)
Data Collection
๏ JFR stores data in a hierarchy of in-memory buffers.
๏ The data is moved to the disk when the buffers are full
๏ Initially the JFR stores data in thread-local buffers. (Improves throughput, no synchronization for every event)
๏ Once the thread-local buffer has been filled, the data is transferred to a global buffer. (Requires synchronization)
๏ After the buffers are full, the data is written to the disk
7
![Page 8: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/8.jpg)
Data Analysis
๏ JFR Plugin in JMC provides dynamic and in-depth analysis of all collected JFR data.
๏ JFR enables users to analyze all aspects of a Java application
๏ Can analyze the Code, Memory, Threads, Locks and I/O
8
![Page 9: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/9.jpg)
Type of Events in JFR
๏ Instant events – Events with only one time
๏ Requestable events – Events with a user configurable period
๏ Duration events – Event with a start and end time
๏ Timed events – Duration events with a user configurable threshold
9
![Page 10: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/10.jpg)
Starting Java Mission Control
๏ Run “jmc” command in $JAVA_HOME/bin
๏ It runs on Eclipse
๏ It can also be installed on your existing Eclipse
๏ If it crashes with SIGSEGV on Ubuntu, try following
๏ sudo -E sh -c 'echo org.eclipse.swt.browser.DefaultType=mozilla >> $JAVA_HOME/lib/missioncontrol/configuration/config.ini'
10
![Page 11: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/11.jpg)
JMC Overview
11
![Page 12: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/12.jpg)
Enabling Java Flight Recorder
๏ The server VM needs to be started with following options
๏ -XX:+UnlockCommercialFeatures -XX:+FlightRecorder
๏ To produce a Flight Recording from the command line, you can use “- XX:StartFlightRecording” option. For example
๏ -XX:StartFlightRecording=delay=20s,duration=60s,name=Test,filename=d.jfr,settings=profile
๏ Use following to change log level
๏ -XX:FlightRecorderOptions=loglevel=info
๏ The command “jcmd” can also be used
12
![Page 13: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/13.jpg)
Flight Recording from JMC
๏ Right click on JVM and select “Start Flight Recording”
๏ Select the type of recording: Time fixed / Continuous
๏ Select the flight recording template
๏ Modify the event options for the selected flight recording template (Optional)
๏ Modify the event details (Optional)
13
![Page 14: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/14.jpg)
Start Flight Recording Wizard
14
![Page 15: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/15.jpg)
Event Options for Profiling
15
![Page 16: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/16.jpg)
Event Details for Profiling
16
![Page 17: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/17.jpg)
Demo
๏ Enable JFR in WSO2 ESB
๏ Sample applications from Marcus Hirt’s Tutorials (http://hirt.se/blog/?p=611) to demonstrate:
๏ CPU Usage viewing in JMC
๏ How to view deadlocked threads in JMC
๏ Flight recording and observing Memory/Garbage Collections tab
17
![Page 18: Using Java Mission Control & Java Flight Recorder](https://reader034.vdocuments.pub/reader034/viewer/2022052603/55d57872bb61ebae2f8b45b0/html5/thumbnails/18.jpg)
References
๏ Java Mission Control
๏ Marcus Hirt’s Blog
๏ Advanced Java Diagnostics and Monitoring Without Performance Overhead - Oracle Whitepaper
๏ Oracle Java SE Advanced
๏ InfoQ - Mission Control and Flight Recorder on HotSpotJVM
๏ JMC & JFR - Diagnostic Tools
18