through the jmx window

Post on 08-May-2015

2.264 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Presentation delivered by Matt Brasier at DOAG German Oracle User Group Conference in Nuremberg, 19-21 November 2013. This lab will demonstrate the depth and breadth of the information available via the JMX API. We will use the JVM tools to peer deep into the workings of the JVM and understand how to identify and solve common performance bottlenecks. Attendees will get hands-on experience of using tools like VisualVM and Jstat to interrogate the JVM, and how to interpret the data returned. This lab will be a hands-on session that allows attendees to understand the power available to them in some of the overlooked core JVM tools (jstack, jstat, visualvm). The session will use a combination of slides and examples that the attendees can code-along with on their own laptops, and will focus primarily on how the tools can be used to identify performance bottlenecks, although we will also look at how you can expose your own application MBeans and use these to monitor the application. In my work as a Java performance consultant, I have found that JMX and the basic JVM tooling that uses it, is not understood by developers, so this session is about raising awareness of these tools and allowing developers to get inside the JVM and their application to understand how it works (and write better code). In my experience, once developers understand the power of JMX and VisualVM, they find it very interesting, and often the best way to demonstrate it is by allowing people to work with it. The fact that the base JDK is all that is required to demonstrate this means that there are few pre-requisites for this session, and because it is based on a low level technology, it is of interest to people working on all aspects of Java. I think this could make popular talk which will help developers understand the magic and power behind the Java Virtual Machine.

TRANSCRIPT

© C2B2 Consulting Limited 2013 All Rights Reserved

Through the JMX Window

Matt Brasier

Head of Consulting

C2B2 Consulting

© C2B2 Consulting Limited 2013 All Rights Reserved

Who am I?

• Head of consulting at C2B2

• Application server consultant

– WebLogic 5.1->Present

– JBoss 3.x -> Present

– Tomcat, etc

• Performance tuning and critical situation support

• Author

© C2B2 Consulting Limited 2013 All Rights Reserved

Agenda

• What is JMX?

• JMX tools

• What information does it expose?

• What operations can JMX expose?

• Exposing your own information and operations

© C2B2 Consulting Limited 2013 All Rights Reserved

WHAT IS JMX?

© C2B2 Consulting Limited 2013 All Rights Reserved

What is JMX

• Java Management eXtensions

• Currently at version 1.4

• http://docs.oracle.com/javase/7/docs/technotes/guides/jmx/JMX_1_4_specification.pdf

“The Java Management extensions (also called the JMX specification) define an architecture, the design patterns, the APIs, and the services for application and network management and monitoring in the Java programming language.”

© C2B2 Consulting Limited 2013 All Rights Reserved

JMX History

• 1998 – JMX starts as JSR 3. EG composed of most J2EE vendors, based on JDMK

• 2003 – J2EE 1.4 incorporates JMX in the J2EE Spec

• 2004 – With Java 5 release, JMX becomes part of the JDK/Java SE

• JMAPI – Java Management API, failed Sun project

• JDMK – Java Dynamic Management Kit, another failed Sun project

• JMX

© C2B2 Consulting Limited 2013 All Rights Reserved

What is management?

• Management Information

– Any information that is useful for the runtime management of the application.

• Management Operations

– Any operations that can assist in the runtime management of the application.

© C2B2 Consulting Limited 2013 All Rights Reserved

Why JMX?

• Application Management is important!

– If often forgotten.

• Standardise the APIs and patterns for exposing management operations and tooling.

– Tools can be sure information is in an expected format.

– Applications can take advantage of existing tooling.

© C2B2 Consulting Limited 2013 All Rights Reserved

Core Concepts

• MBean

– Management Bean

• Operations

• Attributes

• MBean Server

– Registry for MBeans

• API

– Remote and local access to MBean Server and MBeans

© C2B2 Consulting Limited 2013 All Rights Reserved

Core Concepts

• Applications/Frameworks/Containers expose MBeans

• The JVM contains an MBeanServer which registers all MBeans

• Clients use the JMX API to connect to the MBeanServer and find relevant MBeans

• Clients read/change values of attributes and invoke operations to manage the service

© C2B2 Consulting Limited 2013 All Rights Reserved

JMX TOOLS

© C2B2 Consulting Limited 2013 All Rights Reserved

JMX Tools

• JConsole

• JVisualVM

• Monitoring tools

– Hyperic HQ

– Nagios

– Etc

© C2B2 Consulting Limited 2013 All Rights Reserved

Demo

© C2B2 Consulting Limited 2013 All Rights Reserved

WHAT INFORMATION DOES IT EXPOSE?

© C2B2 Consulting Limited 2013 All Rights Reserved

Default JMX info

• Heap Use – java.lang:type=Memory

– java.lang:type=MemoryPool,name=Eden Space

– java.lang:type=MemoryPool,name=Tenured Gen

– java.lang:type=MemoryPool,name=Perm Gen

• Garbage collection – java.lang:type=GarbageCollector,name=MarkSweepCompact

– java.lang:type=GarbageCollector,name=Copy

• Operating system info – java.lang:type=OperatingSystem

© C2B2 Consulting Limited 2013 All Rights Reserved

Default JMX info

• Runtime JVM parameters – java.lang:type=Runtime

• NIO Buffers – java.nio:type=BufferPool,name=direct

• JDK Logger – java.util.logging:type=Logging

• Classloading – java.lang:type=ClassLoading

• And more!

© C2B2 Consulting Limited 2013 All Rights Reserved

In an application server

• Connection pool info

– Sizes

– Free connections

• Servlet/JSP info

– Number of requests

– Number of errors

• Thread pools

– Sizes

• JMS

– Queue sizes

– Pending messages

• EJBs

– Pool sizes

– Cache hit rates

• Connectors

– In coming request volumes

© C2B2 Consulting Limited 2013 All Rights Reserved

WHAT OPERATIONS DOES IT EXPOSE?

© C2B2 Consulting Limited 2013 All Rights Reserved

Default operations

• com.sun.management:type=HotSpotDiagnostic

– dumpHeap

– setVMOption

– getVMOption

• java.lang:type=Memory

– Gc

• java.lang:type=Threading – dumpAllThreads

– findDeadLockedThreads

© C2B2 Consulting Limited 2013 All Rights Reserved

In an application server

• Datasources

– Reset all datasources

• JMS

– Delete all messages

• Server

– Restart or stop a server

• Deployment

– Deploy or redeploy applications

© C2B2 Consulting Limited 2013 All Rights Reserved

In an application server

• Any operation you could normally perform to manage an application server!

• It is like an X-ray of your application

© C2B2 Consulting Limited 2013 All Rights Reserved

EXPOSING YOUR OWN MANAGEMENT INFORMATION AND OPERATIONS

© C2B2 Consulting Limited 2013 All Rights Reserved

Two step process

• Create MBeans

• Register with MBean server

• Profit

© C2B2 Consulting Limited 2013 All Rights Reserved

Create MBeans

• Identify where in your application you have relevant management information

• Create an MBean interface

• Implement the MBean interface

© C2B2 Consulting Limited 2013 All Rights Reserved

MBean Interface

public Interface LocationMonitorMBean

{

public void getNumberOfFiles();

public void setScanPeriod();

public void getScanPeriod();

public void resetFileCounter();

public void disable();

public void enable();

public void getEnabled();

}

Getters and Setters represent Attributes Other methods represent operations

© C2B2 Consulting Limited 2013 All Rights Reserved

Implementation class

• Implement the MBean interface

– You can do this with an existing class

• Try and avoid doing intensive work in the MBean implementation

– Pre-compute values

– Periodically check and cache values

© C2B2 Consulting Limited 2013 All Rights Reserved

Implementation class

public class LocationMonitor implements LocationMonitorMBean

{

private boolean enabled;

private long scanInterval;

private long numFiles;

public void getNumberOfFiles(

{

return numFiles;

...

Attributes are accessed via getters/setters

© C2B2 Consulting Limited 2013 All Rights Reserved

Register with MBeanServer

• Create (or get hold of) an instance of your MBean implementation

• Get hold of an MBean Server

– PlatformMBeanServer

• Create an ObjectName for your MBean

• Register the MBean

© C2B2 Consulting Limited 2013 All Rights Reserved

Register with MBeanServer

public static void main(String[] args) throws Exception

{

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

ObjectName name = new ObjectName(“uk.co.c2b2.management:type=LocationMonitor");

LocationMonitor mbean = new LocationMonitor();

mbs.registerMBean(mbean, name);

}

Get the MBean Server

Create the ObjectName Create the MBean instance Register it

© C2B2 Consulting Limited 2013 All Rights Reserved

What to monitor

• Resources that your application uses

– Including data (flow rates etc)

• Expose management operations

– Restarting components

– Re-loading configuration files

© C2B2 Consulting Limited 2013 All Rights Reserved

What is through the JMX window?

• A future with more Information

• A future with more control

© C2B2 Consulting Limited 2013 All Rights Reserved

QUESTIONS?

top related