Java Virtual Machine Profiling

Slides:



Advertisements
Similar presentations
JVM Internals Douglas Q. Hawkins. JVM Internals Bytecode Garbage Collection Optimizations Compile Time Run Time.
Advertisements

1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore G54PRG Programming Lecture 1 Amadeo Ascó 3 Java Programming Language.
DynaTrace Platform.
In Production Juan Marin. Agenda Introduction Reliability Availability Performance Data optimizations Runtime optimizations Measuring your environment.
Copyright 2007, Information Builders. Slide 1 Performance and Tuning Mark Nesson, Vashti Ragoonath June 2008.
Capacity Planning in a Virtual Environment
DEV300: A Tiny CPU and OS in C# Scott Hanselman Technology Evangelist/Architect Corillian Corporation
Intel® performance analyze tools Nikita Panov Idrisov Renat.
JProbe. 1. JProbe Use JProbe Profile –identify method and line level performance bottlenecks Use JProbe Memory Debugger –investigating memory leaks and.
Memory issues in production systems. Production system Restricted access Application, DB, Application server, log files Debugging, monitoring Investigation.
THE ART AND METHODOLOGY OF TROUBLESHOOTING Alexey Diomin,
The road to reliable, autonomous distributed systems
ManageEngine TM Applications Manager 8 Monitoring Custom Applications.
©Company confidential 1 Performance Testing for TM & D – An Overview.
Page 1 © 2001 Hewlett-Packard Company Tools for Measuring System and Application Performance Introduction GlancePlus Introduction Glance Motif Glance Character.
Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department.
Module 8: Monitoring SQL Server for Performance. Overview Why to Monitor SQL Server Performance Monitoring and Tuning Tools for Monitoring SQL Server.
Page 1 © 2001 Hewlett-Packard Company Tools for Measuring System and Application Performance Introduction GlancePlus Introduction Glance Motif Glance Character.
Java Security Updated May Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security.
Page 1 © 2001 Hewlett-Packard Company Tools for Measuring System and Application Performance Introduction GlancePlus Introduction Glance Motif Glance Character.
Memory Leak Overview and Tools. AGENDA  Overview of Java Heap  What is a Memory Leak  Symptoms of Memory Leaks  How to troubleshoot  Tools  Best.
Stellen besetzen. Erfolg ermöglichen. Java EE LoadBalancer.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
Copyright 2007, Information Builders. Slide 1 Performance and Tuning Tips Mark Nesson/Vashti Ragoonath October 2008.
- Tausief Shaikh (Senior Server developer). Introduction Covers sense of responsibility towards Project development in IT Focusing on memory and CPU utilizations.
Analyzing parallel programs with Pin Moshe Bach, Mark Charney, Robert Cohn, Elena Demikhovsky, Tevi Devor, Kim Hazelwood, Aamer Jaleel, Chi- Keung Luk,
Bill Au CBS Interactive Troubleshooting Slow or Hung Java Applications.
Bill Au CBS Interactive Troubleshooting Slow or Hung Java Applications.
JA-SIG 12/4/20051 JMX For Monitoring and Maintenance JA-SIG - December 4, 2005 – Atlanta, GA Eric Dalquist Division of Information Technology University.
1162 JDK 5.0 Features Christian Kemper Principal Architect Borland.
Monitoring and Management Mihail Stoynov mihail.stoynov.com mihail.stoynov.com.
© 2006, National Research Council Canada © 2006, IBM Corporation Solving performance issues in OTS-based systems Erik Putrycz Software Engineering Group.
CSC Multiprocessor Programming, Spring, 2012 Chapter 11 – Performance and Scalability Dr. Dale E. Parson, week 12.
Java Monitoring Java monitoring using Glassfish, JMX, Glassbox and JConsole by Greg Heithaus.
Vertical Profiling : Understanding the Behavior of Object-Oriented Applications Sookmyung Women’s Univ. PsLab Sewon,Moon.
Advanced Performance Forensics Uncovering the Mysteries of Performance and Scalability Incidents through Forensic Engineering Stephen Feldman Senior Director.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Lecture #20: Profiling NetBeans Profiler 6.0.
AdaptJ Sookmyung Women’s Univ. PSLAB. 1. 목차 1. Overview 2. Collecting Trace Data using the AdaptJ Agent 2.1 Recording a Trace 3. Analyzing Trace Data.
LIOProf: Exposing Lustre File System Behavior for I/O Middleware
Profile, HAT, Wireless Toolkit’s Profile Sookmyung Women’s Univ. PSLAB Choi yoonjeong.
Beyond Application Profiling to System Aware Analysis Elena Laskavaia, QNX Bill Graham, QNX.
Introduction to Performance Tuning Chia-heng Tu PAS Lab Summer Workshop 2009 June 30,
Developing annotation based monitoring framework Fedor Romanov, TomTom.
Java Flight Recorder and Java Mission Control
Java performance mistakes
Bishnu Priya Nanda , Tata Consultancy Services Ltd.
Content Coverity Static Analysis Use cases of Coverity Examples
GlassFish Performance Tuning: Tips from the Field
Software Architecture in Practice
Java 9: The Quest for Very Large Heaps
Java programming lecture one
Runtime Analysis of Hotspot Java Virtual Machine
Introduction Enosis Learning.
NVIDIA Profiler’s Guide
Software Architecture in Practice
Java Virtual Machine Complete subject details are available at:
CMPE419 Mobile Application Development
Flight Recorder in OpenJDK
Introduction Enosis Learning.
PerfView Measure and Improve Your App’s Performance for Free
ColdFusion Performance Troubleshooting and Tuning
Adaptive Code Unloading for Resource-Constrained JVMs
(Computer fundamental Lab)
CMPE419 Mobile Application Development
JIT Compiler Design Maxine Virtual Machine Dhwani Pandya
Java Virtual Machine Profiling. Agenda Introduction JVM overview Performance concepts Monitoring Profiling VisualVM demo Tuning Conclusions.
CSC Multiprocessor Programming, Spring, 2011
Presentation transcript:

Java Virtual Machine Profiling 1

Agenda Introduction JVM overview Performance concepts Monitoring Profiling VisualVM demo Tuning Conclusions Introduction JVM overview Performance basics Performance methodology Monitoring Profiling VisualVM live demo Tuning Conclusions 2

Introduction What? Monitoring JVM -> Profiling JVM -> Tuning Who? Java SE developers, Java EE developers, Java architects, Java apps admin What not? SO perf, I/O perf, Network perf, JIT perf JVM concepts: Memo JVM performance issues: Gus Profiling: Alex JDK built-in tools: Alex VisualVM live demo: Memo VisualVM plugins: Memo 3

JVM overview 4

Performance basics Memory footprint Startup time Scalability Responsiveness Memory footprint: memory used by an app, or memory used by a JVM Tune the heap size to avoid virtual memory swapping. Startup time: time taken to start. Avoid large classpaths Consider disable bytecode verification, this avoids overhead loading classes Scalability: how well an app performs under load increments Lineal increments of response time is good, exponential is bad. Stress your application in development, not in production Responsiveness: how quickly an app responds with a request. Respond in short period of time. Throughput: amount of work in a period of time. Do more work in the same time. Throughput 5

Performance methodology Monitoring Not intrusive: observe behavior, not overload For development/production For troubleshooting: identify issues Tuning info for: JVM issues (heap size, GC optimization, JIT bugs) Profiling More intrusive: analyze your code, cause overload For development: get performance data in a running app For troubleshooting: focus on the issues Tuning info for: code issues (memory leaks, lock contentions) Tuning Known performance requirements Monitoring and/or profiling, then compare with requirements Modify JVM arguments or source code Incorporating performance in development Analysis -> Design -> Code -> Benchmark -> Profile -> Deploy 6

Monitoring What to monitor? Result Tools for monitoring CPU usage Java heap usage, # of threads GC: frequency and duration JIT: frequency, duration, opt/de-opt cycles, failed compilations Result Identify Java heap tuning GC tuning Tools for monitoring -verbose: gc, -XX:+PrintGCDetails, -XX:PrintCompilation Jstat JConsole, VisualVM, VisualGC 7

Profiling CPU profiling Heap profiling When: large amount of CPU time Look for: methods with a high self-time Output: throughput issues, identify algorithm and designs issues Heap profiling When: GC runs frequently, large Java heap Look for: very large allocated objects, small objects allocated at a high rate Output: throughput/responsiveness issues, memory allocation patterns, memory strategies (alternative APIs, caching solutions) 8

Profiling (continued) Memory leaks: reference to allocated object remains unintentionally reachable and cannot be GC'ed. When: Java heap grow over time w/o bound, OOM errors Look for: abnormal memory consumption, Output: code errors Lock contention: large number of context switches, related to CPU utilization When: manual use of threads Look for: high number of context switches, many threads in wait state Output: code errors. Tools for profiling Netbeans profiler jmap, jhat -XX: +HeapDumpOnOutOfMemoryError VisualVM 9

Profiling tecniques Sampling Profiling Code modification No Yes, at bytecode level in startup time. Overhead Only when sampling, depends of frequency of sampling. Large, depends of number of instrumented methods and number of threads. Accuracy Not to much, better with high frequency Accurate Repeatability Different results in different measures Similar results When? Synchronization problems Profiling a production application Identify performance bottlenecks Analyze performance bottlenecks Precise information

Profiling tools Included in <JDK_HOME>/bin for JDK 1.5+, except jhat (JDK 6+) and jvisualvm (JDK 6 update 7+) jps: list the instrumented HotSpot VM’s for the current user in the target system. jinfo: prints system properties and command-line flags used in a JVM jmap: prints memory related statistics for a running VM or core file jhat: parses a heap dump in binary format and starts an HTTP server to browse different queries (JDK 6) jstat: provides information on performance and resource consumption of running applications using the built-in instrumentation in the HotSpot VM. jstack: prints the stack traces of all the threads attached to the JVM, including Java threads and VM internal threads. Also performs deadlock detection jconsole: uses the build-in JMX instrumentation in the JVM to provide information on performance and resource consumption of running applications jvisualvm: useful to troubleshoot applications and to monitor and improve application’s performance. It helps ot generate and analyze heap dumps, track down memory leaks, perform and monitor garbage collection, and perform lightweigth memory and CPU profiling. 11

Profiling tools (continued)

Profiling tools (continued)

VisualVM demo The bleeding-edge distribution of jvisualvm, with the latest features and bug fixes. Download software: http://visualvm.java.net/ (current version 1.3.5) Enable JVM profiling -Dcom.sun.management.jmxremote=true: Registers the JVM instrumentation MBeans and publishes the RMI connector via a private interface to allow JMX client applications to monitor a local JVM. -Xshare:off: Disable class data sharing -javaagent:<VISUALVM_HOME>/profiler/lib/jfluid-server.jar: Specify where is the profiler agent - Sampler tab columns: - Self time: time spent in all invocations on this method (excluding further method calls) - Self time [%]: expressed in percentage - Self time (CPU): estimated real CPU use time - Sampler snapshot columns: - Time: time spent in all invocations of the method - Time [%]: percentage relative to the thread time (100% is the thread total time captured in the snapshot) - Time (CPU): estimated CPU real use time - Invocations: number of times the method was called - Profiling columns (tab and snapshot): - Time [%]: time spent in all invocations of the method, expressed in percentage. The 100% is the time the thread has been running. - Time: time spent in all invocations of the method, expressed in milliseconds. - Invocations: number of times the method was called. Start VisualVM # <JVISUALVM_HOME>/bin/visualvm –-jdkhome <JDK_HOME> 14

Tuning Java heap and stack tuning 15

Tuning (continued) Heap and lock contention issues: Avoid create objects where primitives could be used (autoboxing is not for free) Avoid String concatenations, use StringBuilder with append() Avoid StringBuilder overallocation, set initial size to reduce resizing Avoid use of synchronized keyword, look for a java.util.concurrent solution Use java.util.concurrent API instead of "synchronized" Collections Don't use exceptions for flow control (Exception objects allocation), use flow control constructs (if/else, return, switch). Don't generate stack traces, they're expensive operations. Reduce number of system calls: Avoid accessing disk: use large buffers or direct buffering Avoid accessing to underlying OS Avoid processing bytes and characters individually Never implement finalize(): pain in the ass for GC GC issues: not covered 16

Conclusions JDK offers very useful utilities to troubleshoot and manage performance issues with JVM. We can use them not only when a performance issue happens, but to understand what is the behavior of the application and where could be improve it. Incorporate performance benchmarks in your development cycle. Thanks! 17

References Memory Management in the Java HotSpot Virtual Machine http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf Troubleshooting Guide for Java SE 6 with HotSpot VM http://www.oracle.com/technetwork/java/javase/toc-135973.html JDK Utilities http://download.oracle.com/javase/6/docs/technotes/tools/share/jps.html http://download.oracle.com/javase/6/docs/technotes/tools/share/jinfo.html http://download.oracle.com/javase/6/docs/technotes/tools/share/jmap.html http://download.oracle.com/javase/6/docs/technotes/tools/share/jhat.html http://download.oracle.com/javase/6/docs/technotes/tools/share/jstat.html http://download.oracle.com/javase/6/docs/technotes/tools/share/jstack.html http://download.oracle.com/javase/6/docs/technotes/tools/share/jconsole.html http://download.oracle.com/javase/6/docs/technotes/tools/share/jvisualvm.html Visual VM http://visualvm.java.net/ JVM HotSpot options http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html 18