19
Great tools in Java Development Kit 05 November 2014 Senior Software Engineer M. Isuru Tharanga Chrishantha Perera Using Java Mission Control & Java Flight Recorder

Using Java Mission Control & Java Flight Recorder

Embed Size (px)

Citation preview

Page 1: Using Java Mission Control & Java Flight Recorder

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

2

Agenda

๏ What is Java Mission Control (JMC)

๏ Java Flight Recorder (JFR)

๏ Using JMC

๏ Demos

Page 3: Using Java Mission Control & Java Flight Recorder

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

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

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

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

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

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

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

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

JMC Overview

11

Page 12: Using Java Mission Control & Java Flight Recorder

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

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

Start Flight Recording Wizard

14

Page 15: Using Java Mission Control & Java Flight Recorder

Event Options for Profiling

15

Page 16: Using Java Mission Control & Java Flight Recorder

Event Details for Profiling

16

Page 17: Using Java Mission Control & Java Flight Recorder

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