40
Title Slide with Java FY15 Theme Subtitle Java Mission Control and Java Flight Recorder Wolfgang Weigend Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Presenter’s Name Presenter’s Title Organization, Division or Business Unit Month 00, 2014 Note: The speaker notes for this slide include detailed instructions on how to reuse this Title Slide in another presentation. Tip! Remember to remove this text box. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Wolfgang Weigend Sen. Leitender Systemberater Java Technology and Architecture

Java mission control and java flight recorder

Embed Size (px)

Citation preview

Title Slide with Java FY15 Theme

Subtitle

Java Mission Control andJava Flight Recorder

Wolfgang Weigend

Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

Presenter’s Name

Presenter’s Title

Organization, Division or Business Unit

Month 00, 2014

Note: The speaker notes for this slide include detailed instructions on how to reuse this Title Slide in another presentation.

Tip! Remember to remove this text box.

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

Wolfgang Weigend

Sen. Leitender Systemberater

Java Technology and Architecture

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality,

and should not be relied upon in making purchasing

Disclaimer

2 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Java Mission Control 5.4

3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

Java Process Browser and JMX Console

4 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Tracer and Profiler

• Non-intrusive

• Built into the JVM itself

Java Flight Recorder

5 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• On-demand profiling

• After-the-fact capture and analysis

• First released in 7u40

• Captures both JVM and application data‒ Garbage Collections‒ Sychronization‒ Compiler‒ CPU Usage

Java Flight Recorder - Tracer & Profiler

6 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

‒ CPU Usage‒ Exceptions‒ I/O

• Sampling-based profiler‒ Very low overhead‒ Accurate data

• Typical overhead in benchmarks: 2-3%

• Often not noticeable in typical production environments

• Turn on and off in runtime

Non-Intrusive

7 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Turn on and off in runtime

• Information already available in the JVM

‒ Zero extra cost

• Core of JFR is inside the JVM

• Can easily interact with other JVM subsystems

Built into the JVM itself

8 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Optimized C++ code

• Supporting functionality written in Java

• Start from Java Mission Control

‒ Or from the command line

• Easily configure the amount of information to capture

On-Demand Profiling

9 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Easily configure the amount of information to capture

• For a profile, a higher overhead can be acceptable

• When done, no overhead

• Powerful GUI for analysis

• In its default mode, very low overhead

• Designed to be always-on

• Uses circular buffers to store data

After-the-Fact Analysis

10 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Uses circular buffers to store data

‒ In-memory or on-disk

• When an SLA breach is detected, dump the current buffers

• Dump will have information leading up to the problem

• Enable

‐‐‐‐XX:+UnlockCommercialFeatures ‐‐‐‐XX:+FlightRecorder

• Start

‐‐‐‐

Configuration

11 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

‐‐‐‐XX:StartFlightRecording=filename=<path>,duration=<time>

• Or

Jcmd <pid> JFR.start filename=<path> duration=<time>

Advanced ConfigurationPer Recording Session

Max age of data maxage=<time>

Max size to keep maxsize=<size>

12 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

Global Settings (-XX:FlightRecorderOptions)

Max stack trace depth stackdepth=<n> (default 64)

Save recording on exit dumponexit=true

Logging loglevel=[ERROR|WARN|INFO|DEBUG|TRACE]

Repository path repository=<path>

• Recordings can specify exactly which information to capture

‒ ~80 events with 3 settings each

• But: two preconfigured settings

Recording Sessions

13 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• But: two preconfigured settings

‒ “default”: provides as much information as possible while keeping

overhead to a minimum

‒ “profile”: has more information, but also higher overhead

• You can configure your own favorites in Mission Control

• Great working approach

• Each session can have its own settings

• Caveat: If there are multiple sessions all of them get the

Many Simultaneous Recording Sessions

14 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Caveat: If there are multiple sessions all of them get the

union of the enabled events

‒ Example: If event A is enabled in on recording, all recordings will see event A

‒ Example: If event B has two different thresholds, the lower value will apply

Creating Recordings Using Startup Flags

• Documentation of startup flags available in the JDK docs

• The following example starts up a 1 minute recording 20 seconds after

starting the JVM:-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -

XX:StartFlightRecording=delay=20s,duration=60s,name=MyRecording,filena

Useful for enabling continuous recordings at startup

15 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

me=C:\TEMP\myrecording.jfr,settings=profile

– The settings parameter takes either the path to, or the name of, a template

– Default templates are located in the jre/lib/jfr folder

– Note: Using the settings parameter will require JDK 7u40 or greater

• To get more information on what is going on, change the log level:-XX:FlightRecorderOptions=loglevel=info

The Default Recording

• Special short hand to start the JVM with a continuous recording

• Started with -XX:FlightRecorderOptions=defaultrecording=true

• The default recording will have the recording id 0

• Only the default recording can be used with the dumponexit and dumponexitpath

parameters

16 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

parameters

• The following example will start up the continuous recording. It will be dumped when the JVM exits to C:\demos\dumponexit.jfr.-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -

XX:FlightRecorderOptions=defaultrecording=true,dumponexit=true,dumponexitpath=C:

\demos\dumponexit.jfr

Creating Recordings Using JCMD

Usage: jcmd <pid> <command>

Example starting a recording:jcmd 7060 JFR.start name=MyRecording settings=profile

delay=20s duration=2m filename=c:\TEMP\myrecording.jfr

Example checking on recordings:

Useful for controlling JFR from the command line

17 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

Example checking on recordings:jcmd 7060 JFR.check

Example dumping a recording:jcmd 7060 JFR.dump name=MyRecording

filename=C:\TEMP\dump.jfr

Flight Recorder Inner Workings

• Extremely low overhead

– Using data already gathered

– High performance recording engine

• Testing!

Focus on performance

18 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Testing!

• Third party events

– WLS

– Dynamic Monitoring Service DMS custom WLST commands

– JavaFX

– You can add your own events, but this is not yet supported!

• Information gathering− Instrumentation calls all over the JVM

− Application information via Java API

• Collected in Thread Local buffers⇢ Global Buffers ⇢Disk

Java Flight Recorder – How is it built?

19 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

⇢ Global Buffers ⇢Disk

• Binary, proprietary file format

• Managed via JMX

• Java Flight Recorder− Start from JMC 5.4 or CLI

• Activate Flight Recorder− -XX: +UnlockCommercialFeatures

− -XX: +FlightRecorder

Java Flight Recorder – Buffers

• “Circular”

• Designed for low contention

20 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Header

• Payload

‒ Event specific data

“Everything is an Event”

21 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

‒ Event specific data

• Instant‒ Single point in time‒ Example: Thread starts

• Duration

Event Types

22 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Duration‒ Timing for something‒ Example: GC

• Requestable‒ Happens with a specified frequency‒ Example: CPU Usage every second

• For every event

‒ Name, Path, Description

Event Meta Data

23 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• For every payload item

‒ Name, Type, Description, Content Type

• Describes the semantics of a value• Used to correctly display the value in the UI

“Content Type”

Content Type Displayed as

Bytes 4 MB

24 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

Bytes 4 MB

Percentage 34 %

Address 0x23CDA540

Millis 17 ms

Nanos 4444 ns

Event Definition in Hotspot

<event id="ThreadSleep"

path="java/thread_sleep"

label="Java Thread Sleep“ ...>

<value field="time“

type="MILLIS“

label="Sleep Time"/>

25 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• XML definitions are processed into C++ classes

label="Sleep Time"/>

</event>

Event Emission in Hotspot

JVM_Sleep(int millis){

EventThreadSleep event;

… // actual sleep happens here

event.set_time(millis);

26 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Now the data will be available in JFR

event.set_time(millis);

event.commit();

}

• Enable/disable event

• Thresholds

‒ Only if duration is longer than X

Filtering Early

27 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

‒ Only if duration is longer than X

• Enable/disable stack trace

• Frequency

‒ Sample every X

• Self-contained‒ Everything needed to parse an event is included in the file‒ New events instantly viewable in the UI

• Binary, proprietary

• Designed for fast writing

File Format

28 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Designed for fast writing• Single file, no dependencies

‒ Example: 5 Minutes of recording, result in a Flight Recorder File with

a size of 957 KB

Header Event Records Event Definitions

• Can’t leak memory

‒ Can’t aggregate information eternally

‒ Can’t keep references that prohibits class unloading

Dynamic Runtime and Long-Running Recordings

29 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Dynamic Runtime

‒ Classes can come and go

‒ Threads can come and go

• Solutions: Constant Pools, Checkpoints

• If every event contained the class name as a string, we would waste

lots of space

• Solution: Class ID’s

Problem: Many Events Reference Classes

30 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• ID’s need to be part of the file

• Classes can be unloaded at any time

‒ Class may not be around until end of recording

Problem: When do we write the Class IDs?

31 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

‒ Class may not be around until end of recording

• Solution: Write Class ID when classes are unloaded

• Many classes are loaded, not all are referenced in events, we want to

save space

• Solution: When a class ID is referenced, the class is also “tagged”

Problem: Size of the Class List

32 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

‒ Write only tagged classes in the JFR file

• Over time many classes will be tagged, the size of the class list will

increase

• Solution: Reset the tags each time a class list is written to disk

Problem: Leaking Memory

33 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• We call this a “Checkpoint”

• A recording file may contain many class lists, each one is only valid for

the data immediately preceding it

• The Class List is a special case of a Constant Pool

• Classes

• Methods

Constant Pools

34 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Methods

• Threads

• Thread Groups

• Stack Traces

• Strings

• At regular intervals, a “checkpoint” iscreated in the recording

• Has everything needed to parsethe recording since the last checkpoint

Checkpoints

35 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

the recording since the last checkpoint

checkpoint =events+ constant pools+ event meta-data

Analyzing Flight Recordings in JMC

• All tab groups except for the general Events tab group are preconfigured to show a certain aspect of the recording (sometimes referred to as static or preconfigured tabs)

36 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• The pre-configured tabs highlights various areas of common interest, such as code, memory & GC, threads and IO

• General Events tab group - useful for drilling down further and for rapidly homing in on a set of events with certain properties

Java Flight Recorder Releases

• Resulted from the JRockit and HotSpot JVM Convergence

• Java Mission Control released with the 7u40 JDK

• Java Mission Control 5.4.0 released with 8u20

37 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Java Mission Control 5.4.0 released with 8u20

• Java Mission Control

�http://www.oracle.com/technetwork/java/javaseproducts/mission-control/index.html

• User Guide

�http://docs.oracle.com/javacomponents/jmc.htm

More Information

38 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

�http://docs.oracle.com/javacomponents/jmc.htm

• Forum

�https://community.oracle.com/community/java/java_hotspot_virtual_machine/java_mission_control

• JMC Tutorial

�http://hirt.se/downloads/oracle/jmc_tutorial.zip

�Do Java Flight Recordings and Analyse Flight Recordings

Summary• Java Flight Recorder provides a central view on the JVM and the Java application

– JVM Events and Java API Events

• Extremely low overhead (<= 2-3%)

– Can keep it always on, dump when necessary

• Tooling for analysing recordings built into the Oracle JDK via Java Mission Control

39 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.

• Tooling for analysing recordings built into the Oracle JDK via Java Mission Control

• Java APIs available for recording custom information into the Flight Recorder in the

Oracle JDK

• Third party integration giving holistic view of the detailed information recorded by the Flight Recorder (WebLogic Server, JavaFX)

Thanks to Marcus Hirt for his sources!

[email protected]

40 Copyright © 2015, Oracle and/or its affiliates. All rights reserved.