java colombo meetup: java mission control & java flight recorder
DESCRIPTION
Presentation slides used at the 17th Java Colombo Meetup. http://www.meetup.com/java-colombo/events/218658123/ This presentation explains the JMX Console & Java Flight Recorder (JFR) tools in Java Mission Control (JMC)TRANSCRIPT
Java Mission Control &
Java Flight RecorderM. ISURU T. C. PERERA
1
@chrishantha
Agenda Tools in Java Development Kit
What is Java Mission Control (JMC)
Java Flight Recorder (JFR)
Demos
04/12/2014Java Colombo Meetup
2
JDK Tools
• Basic Tools (java, javac, jar)
• Security Tools (jarsigner, keytool)
• Java Web Service Tools (wsimport, wsgen)
• Java Troubleshooting, Profiling, Monitoring and Management Tools (jcmd, jconsole, jmc, jvisualvm)
04/12/2014Java Colombo Meetup
3
Image Source:
http://commons.wikimedia.org/wiki/File:Hand_tools.jpg
Java Troubleshooting, Profiling,
Monitoring and Management Tools
jcmd - JVM Diagnostic Commands tool
jconsole - A JMX-compliant graphical tool for monitoring a Java
application
jvisualvm – Provides detailed information about the Java application. It
provides CPU & Memory profiling, heap dump analysis, memory leak
detection etc.
jmc – Tools to monitor and manage Java applications without introducing
performance overhead
04/12/2014Java Colombo Meetup
4
Java Experimental Tools
Monitoring Tools
jps – JVM Process Status Tool
jstat – JVM Statistics Monitoring Tool
Troubleshooting Tools
jmap - Memory Map for Java
jhat - Heap Dump Browser
jstack – Stack Trace for Java
04/12/2014Java Colombo Meetup
5
What is Java Mission Control?
A set of powerful tools running on the Oracle JDK to
monitor and manage Java applications
Free for development use (Oracle Binary Code License)
Available in JDK since Java 7 update 40
Supports Plugins
Two main tools
JMX Console
Java Flight Recorder
04/12/2014Java Colombo Meetup
6
Starting Java Mission Control
Run “jmc” command in $JAVA_HOME/bin
It runs on Eclipse
It can also be installed on your existing Eclipse
04/12/2014Java Colombo Meetup
7
Troubleshooting Tip
If “jmc” 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'
04/12/2014Java Colombo Meetup
8
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.
04/12/2014Java Colombo Meetup
9
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
04/12/2014Java Colombo Meetup
10
JMX Console
04/12/2014Java Colombo Meetup
11
JMX Console Tabs
Overview – Dashboard, Graphs with real-time usage statistics
System – Information about the JVM
Memory – Monitor heap usage, garbage collection & active memory
pools
Threads – Live thread usage by the application
MBean Browser – Access all registered MBeans
Triggers – Manage rules that trigger events
Diagnostic Commands – Execute commands on JVM
04/12/2014Java Colombo Meetup
12
JMX Console Demo
Sample applications from Marcus Hirt’s Tutorials
(http://hirt.se/blog/?p=611)
Demonstrating
CPU Usage viewing in JMC
View deadlocked threads
04/12/2014Java Colombo Meetup
13
Image Source: https://duke.kenai.com/boxer/boxer.gif
Flight Recorder
“Black box” used in aircraft
04/12/2014Java Colombo Meetup
14
Image Source: http://commons.wikimedia.org/wiki/File:Black_box.aeroplane.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
Engine was released with Java 7 update 4
04/12/2014Java Colombo Meetup
15
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
04/12/2014Java Colombo Meetup
16
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
04/12/2014Java Colombo Meetup
17
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
04/12/2014Java Colombo Meetup
18
JFR Recoding Types
Time Fixed Recordings
Fixed duration
The recording will be opened automatically in JMC at the end(If the recording
was started by JMC)
Continuous Recordings
No end time
Must be explicitly dumped
04/12/2014Java Colombo Meetup
19
Enabling Java Flight Recorder
The server VM needs to be started with following options
-XX:+UnlockCommercialFeatures -XX:+FlightRecorder
Make sure to use JDK 7u40 or later
For remote monitoring, start with appropriate com.sun.management flags
04/12/2014Java Colombo Meetup
20
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)
04/12/2014Java Colombo Meetup
21
Start Flight Recording Wizard
04/12/2014Java Colombo Meetup
22
Event Options for Profiling
04/12/2014Java Colombo Meetup
23
Event Details for Profiling
04/12/2014Java Colombo Meetup
24
Flight Recording using startup flags
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=recording.
jfr,settings=profile
Setting are in $JAVA_HOME/jre/lib/jfr
Use following to change log level
-XX:FlightRecorderOptions=loglevel=info
04/12/2014Java Colombo Meetup
25
The Default Recording
Use default recording option to start a continuous recording
-XX:FlightRecorderOptions=defaultrecording=true
Default recording can be dumped on exit
Only the default recording can be used with the dumponexit and
dumponexitpath parameters
-
XX:FlightRecorderOptions=defaultrecording=true,dumponexit=true,dumponexit
path=/tmp/dumponexit.jfr
04/12/2014Java Colombo Meetup
26
Creating Recording with “jcmd”
command
The command “jcmd” can also be used to start flight recording
Start Recording Example:
jcmd <pid> JFR.start delay=20s duration=60s name=MyRecording
filename=/tmp/recording.jfr settings=profile
Check recording
jcmd <pid> JFR.check
Dump Recording
jcmd <pid> JFR.dump filename=/tmp/dump.jfr name=MyRecording
04/12/2014Java Colombo Meetup
27
Analyzing Flight Recordings
JFR runtime engine dumps recorded data to files with *.jfr extension
These binary files can be viewed from JMC client
There are tab groups showing certain aspects of the JVM and the Java
application runtime such as Memory, Threads, I/O etc.
04/12/2014Java Colombo Meetup
28
Analyzing Flight Recordings
04/12/2014Java Colombo Meetup
29
JFR Tab Groups
General – Details of the JVM, the system, and the recording.
Memory - Information about memory & garbage collection.
Code - Information about methods, exceptions, compilations, and class
loading.
Threads - Information about threads and locks.
I/O: Information about file and socket I/O.
System: Information about environment
Events: Information about the event types in the recording
04/12/2014Java Colombo Meetup
30
Operative Set
A global set of events
Events can be added or removed from the context menu
A check box is used to show events in the operative set
04/12/2014Java Colombo Meetup
31
Flight Recording Demo
Time fixed & continuous recordings
Analyzing
04/12/2014Java Colombo Meetup
32
Image Source: https://duke.kenai.com/gun/Gun.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 HotSpot JVM
JMC & JFR - Diagnostic Tools
JDK Development Tools
Java Mission Control and Flight Recorder Demo Series
04/12/2014Java Colombo Meetup
33
Thank you!
04/12/2014Java Colombo Meetup
34
Image Source: https://duke.kenai.com/animations/DukeTuxChristmas.gif