21
Taming the JVM Tuning Tools/Techniques Mike Prasad ..can be adventurous! Or downright grimacing!

Taming The JVM

Embed Size (px)

DESCRIPTION

Mike Prasad's IGNITE presentation at DOSUG about tuning the JVM parameters for optimal performance.

Citation preview

Page 1: Taming The JVM

Taming the JVM

Tuning Tools/Techniques

Mike Prasad

..can be adventurous! Or downright grimacing!

Page 2: Taming The JVM

Objectives

!   Application challenges

!   JVM Configuration

!   Heap Analysis Tools

!   Future/Alternate Solutions

!   Case Study

Page 3: Taming The JVM

Application Challenges

!  Java environment dramatically changed

!  Multi-core, multi-GB environments

!  Understanding JVM important

Page 4: Taming The JVM

Java Memory !   Divided into two areas – Stack & Heap

Stack

!   associated with methods

!   intermediate calcs

Heap

!   All objects created using “new” keyword

!   GC responsible for cleaning dead/unwanted objects

!   Heap sizes controlled by command line options

Page 5: Taming The JVM

Java Garbage Collector

!   Objects either in young or tenured generations

!   Minor GC when young objects die

!   Surviving objects moved to tenured gen

!   Full GC when tenured gen needs to be collected http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

Page 6: Taming The JVM

Generation Sizing

!  Default values typically used

!  This not always sufficient

!  Requires adjusting generation size

Page 7: Taming The JVM

Stack

-Xss set stack size

Heap

-Xms initial heap size

-Xmx maximum heap size

-Xmn young generation heap size

VM Options New Space

-XX:NewSize new gen heap size

-XX:MaxNewSize max new gen heap size

-XX:NewRatio ratio of new/old gen size

-XX:SurvivorRatio eden/survivor space size

Perm Space

-XX:PermSize initial perm size

-XX:MaxPermSize max perm size

-Xnoclassgc eliminates load/unload overhead

Behavioral

-XX:-UseConcMarkSweepGC old gen concurrent mark-sweep

-XX:-UseParallelGC parallel garbage collection

-XX:-UseSerialGC serial garbage collection

Debugging

-XX:-PrintConcurrentLocks Prints concurrent locks

-XX:-PrintGCTimeStamps Print timestamps at gc

-XX:-PrintTenuringDistribution Print tenuring age info

Page 8: Taming The JVM

Memory Analysis Tools

!   JMap

!   JConsole

!   Visual GC

!   JRockit Mission Control

!   Others !   JStat

!   HPROF

Page 9: Taming The JVM

jmap

!   Prints memory–related statistics

!   Other options !   –heap !   –histo !   -permstat

!  To programmatically monitor use: - java.lang.Runtime.totalMemory()

- java.lang.Runtime.freeMemory()

Page 10: Taming The JVM

jmap-heap

Used to obtain :

!   gc name

!   algorithm details !   #threads used for parallel gc

!   heap configuration

!   heap usage summary

Page 11: Taming The JVM

jmap -histo

!  Class-wise histogram of the heap

!  Prints out: !  the number of instances !  total amount of memory consumed !  the fully qualified class name

Page 12: Taming The JVM

jmap -permstat

!  Get perm gen statistics

!  Configuring perm gen size important

!  Web apps load large number of classes (JPs etc)

!  “too many” classes = OutOfMemoryError

Page 13: Taming The JVM

JConsole

!   Monitoring and management tool

!   JMX–compliant attaches to a running JVM

!   JDK 5.0 and above

Page 14: Taming The JVM

Visual GC

!   Monitors !   Garbage Collector

!   Compiler

!   Class loader

!   Superior to JConsole

Page 15: Taming The JVM

JRockit Mission Control

!   Associated with JRockit JVM

!   Tool Suite : –  visualize gc and other perf stats –  runtime performance profiling tool –  memory-analysis tool

Page 16: Taming The JVM

Future !  G1 a new GC in JDK 7

Supports

!  Parallelism : Uses all available CPUs

!  Generational: same as HotSpot GC's

!  Compaction : performs heap compaction

Page 17: Taming The JVM

Appliance Solution

!   Theoretical heap limit of 32-bit JVM is 4G

!   Azul appliance provides !  hardware-assisted pauseless gc feature

!   Up to 864 cores with 768GB heap!

!   Xfer workload from app server to appliance

Page 18: Taming The JVM

Case Study

!  JEE App – Struts/EJB

!  On WebLogic

!  High volume app

!  Overnight performance issues

!  Full GCs every 1.5 minutes

Page 19: Taming The JVM

Original VM Settings

-Server

–Xms2048M

–Xmx2048M

–Xmn512M

Attempted # of Settings

-XX:-UseConcMarkSweepGC

-XX:-UseParallelGC

-XX:-UseHailMaryGC (made it worse!)

Problem solved ?

否, いいえ, нет , nein, αριθ. Pizza + Coke = solution

Problem was with the code!

Case Study

Page 20: Taming The JVM

Apply rigor – unit test, profile, load test

Moral Of the Story

Don’t look for garbage in the wrong place! Spare the JVM, tame the developer!

Why women live longer!

Finally

Page 21: Taming The JVM