Taming The JVM

Embed Size (px)


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

Text of Taming The JVM

  • 1.Taming theJVM Tuning Tools/Techniques Mike PrasadOr downright grimacing! ..can be adventurous!

2. Objectives ! Application challenges ! JVM Configuration ! Heap Analysis Tools ! Future/Alternate Solutions ! Case Study 3. Application Challenges! Java environment dramaticallychanged ! Multi-core, multi-GB environments ! Understanding JVM important 4. 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 5. 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 collectedhttp://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html 6. Generation Sizing! Default values typically used ! This not always sufficient ! Requires adjusting generationsize 7. VM Options New Space Behavioral Stack -XX:NewSize -XX:-UseConcMarkSweepGCnew gen heap sizeold gen concurrent mark-sweep -Xss -XX:MaxNewSize -XX:-UseParallelGC size set stackparallel garbage collectionmax new gen heap size -XX:-UseSerialGC serial garbage collection -XX:NewRatio ratio of new/old gen size-XX:SurvivorRatioeden/survivor space size Heap Debugging-Xms initial heap size Perm Space-XX:-PrintConcurrentLocks -Xmx maximum heap sizePrints concurrent locks-XX:PermSizeinitial perm size-XX:-PrintGCTimeStamps Print timestamps at gc-Xmn-XX:MaxPermSize max perm generation heap size-XX:-PrintTenuringDistributionyoung size Print tenuring age info-Xnoclassgceliminates load/unload overhead 8. Memory Analysis Tools ! JMap ! JConsole ! Visual GC ! JRockit Mission Control ! Others! JStat! HPROF 9. jmap ! Prints memoryrelated statistics ! Other options ! heap ! histo ! -permstat! To programmatically monitor use:- java.lang.Runtime.totalMemory() - java.lang.Runtime.freeMemory() 10. jmap-heap Used to obtain :! gc name! algorithm details! #threads used for parallel gc! heap configuration! heap usage summary 11. jmap -histo ! Class-wise histogram of the heap ! Prints out: ! the number of instances ! total amount of memory consumed ! the fully qualified class name 12. jmap -permstat! Get perm gen statistics ! Configuring perm gen size important ! Web apps load large number of classes (JPs etc) ! too many classes = OutOfMemoryError 13. JConsole! Monitoring and management tool ! JMXcompliant attaches to a running JVM ! JDK 5.0 and above 14. Visual GC! Monitors! Garbage Collector! Compiler! Class loader! Superior to JConsole 15. JRockit Mission Control! Associated with JRockit JVM ! Tool Suite : visualize gc and other perf stats runtime performance profiling tool memory-analysis tool 16. Future ! G1 a new GC in JDK 7 Supports ! Parallelism : Uses all available CPUs ! Generational: same as HotSpot GC's ! Compaction : performs heap compaction 17. 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 18. Case Study! JEE App Struts/EJB ! On WebLogic ! High volume app ! Overnight performance issues ! Full GCs every 1.5 minutes 19. Case Study Original VM Settings Attempted # of Settings-Server -XX:-UseConcMarkSweepGC Xms2048M ProblemPizza + ? solved Coke = solution -XX:-UseParallelGC Xmx2048M,, , nein, . -XX:-UseHailMaryGC (made itXmn512M worse!) Problem was with the code! 20. Moral FinallyStory Of the Apply rigor forJVM, test, the developer! testDont lookthe unit tamein the wrong place!Sparegarbageprofile, loadWhy women live longer!