Taming the JVM Tuning Tools/Techniques Mike Prasad ..can be adventurous! Or downright grimacing!
Taming the JVM
Tuning Tools/Techniques
Mike Prasad
..can be adventurous! Or downright grimacing!
Objectives
! Application challenges
! JVM Configuration
! Heap Analysis Tools
! Future/Alternate Solutions
! Case Study
Application Challenges
! Java environment dramatically changed
! Multi-core, multi-GB environments
! Understanding JVM important
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
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
Generation Sizing
! Default values typically used
! This not always sufficient
! Requires adjusting generation size
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
Memory Analysis Tools
! JMap
! JConsole
! Visual GC
! JRockit Mission Control
! Others ! JStat
! HPROF
jmap
! Prints memory–related statistics
! Other options ! –heap ! –histo ! -permstat
! To programmatically monitor use: - java.lang.Runtime.totalMemory()
- java.lang.Runtime.freeMemory()
jmap-heap
Used to obtain :
! gc name
! algorithm details ! #threads used for parallel gc
! heap configuration
! heap usage summary
jmap -histo
! Class-wise histogram of the heap
! Prints out: ! the number of instances ! total amount of memory consumed ! the fully qualified class name
jmap -permstat
! Get perm gen statistics
! Configuring perm gen size important
! Web apps load large number of classes (JPs etc)
! “too many” classes = OutOfMemoryError
JConsole
! Monitoring and management tool
! JMX–compliant attaches to a running JVM
! JDK 5.0 and above
Visual GC
! Monitors ! Garbage Collector
! Compiler
! Class loader
! Superior to JConsole
JRockit Mission Control
! Associated with JRockit JVM
! Tool Suite : – visualize gc and other perf stats – runtime performance profiling tool – memory-analysis tool
Future ! G1 a new GC in JDK 7
Supports
! Parallelism : Uses all available CPUs
! Generational: same as HotSpot GC's
! Compaction : performs heap compaction
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
Case Study
! JEE App – Struts/EJB
! On WebLogic
! High volume app
! Overnight performance issues
! Full GCs every 1.5 minutes
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
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