HotSpot JVM TuningBy: Gilad GaronTechnicalMeeting!
-Xmx2gIt’s more than just:What is JVM Tuning?It’s a combination of:Hardware selection
Software architectureBut most of all, JVM Tuning is about:Understanding how your application works!
The IDI Test CaseChoosing the right hardwareGarbage CollectorsJVM TuningAgendaJVM Tuning
Swing desktop client applicationWicket web applicationMobile web application (In development)Multiple AS:JBoss Clusters, Apache Cluster, Tomcat & TerracottaMultiple frameworks: Spring, Guice, Wicket, Hibernate, Terracotta DSO, XStream, EJB 3.0, JMS, CGLib & Proprietary frameworks   Technical InformationThe IDI Test Case
The IDI Test Case
3000 +/- EJB Invocations per minute100+ concurrent web sessionsInternal Print servers clients Internal Mail servers clientsInternal Webservices clientsJBoss EAR cluster user load informationThe IDI Test Case
The IDI Test CaseChoosing the right hardwareGarbage CollectorsJVM TuningAgendaJVM Tuning
How many software engineers does it take to change a light bulb?Hardware choices affects code performanceHardware choices affects OS offerings (Do you really want Windows?)Hardware isn’t easily replaced, it costs a lot.Choosing the right hardwareNone. It's a hardware problem.
Which CPU architecture is right for you?Higher clock speed? (what about Moore’s law?)Higher core count?Number of hardware threads?Choosing the right hardwareRemember:Not all CPU’s are created equally
Highly computational apps relay on clock speed
Highly concurrent / multi user app relay on number of threads
Hardware benchmarking helps a lot, but it’s difficult to arrangeIntel Xeon / Itanium?AMD Operton?Sun SPARC?IBM Power?What should be your opinion?Choosing the right hardwareThe winner is….No one will ever ask for your opinion (almost)
IDI Hardware historyChoosing the right hardware @ IDI
The IDI Test CaseChoosing the right hardwareGarbage CollectorsJVM TuningAgendaJVM Tuning
Remember this?Garbage CollectorsGarbage Collection means that don’t have to anymore
When the JVM starts, the host OS assigns a dedicated memory space to that VMThe VM allocates memory to the application within that dedicated memory spaceThe VM frees memory automatically via garbage collectorsGarbage Collection is an expensive algorithmJVM Memory HandlingGarbage Collectors
The memory space is divided into three separated memory spaces:Eden SpaceWhere objects are bornSurvivor SpacesWhere objects matureTenure SpaceWhere objects grow old and dieGenerational Memory SpaceGarbage Collectors
HotSpot  VM‘s Generational Memory SpaceGarbage CollectorsEden SpaceSurvivor Space 2Survivor Space 1Tenure (Old) GenerationPermanent Generation
ConcurrencyConcurrency describes its ability to do work while application threads are still runningParallelismParallelismdescribes the collector's ability to perform its work across multiple threads of execution.Hence, a collector can be parallel but not concurrent, concurrent but not parallel, or both parallel and concurrent.Technical Terms:Garbage Collectors
Copy CollectorA collector that copies live object from one space to anotherLow Pause CollectorA collector that works along side the application threadsThroughput CollectorA collector that doesn’t add to the serial execution time of the applicationTechnical Terms:Garbage Collectors
Memory FragmentationThe amount of unusable free memory (small holes that object can’t be fitted in)Stop the world:The application threads are stopped during the garbage collectionMinor CollectionA garbage collection of the young generationMajor CollectionA garbage collection of the old generationTechnical Terms, Continued:Garbage Collectors
Types of GC Strategies (Generational):Garbage Collectors
Garbage Collectors“Parallel New” StrategyYoung generation collection is done in parallel (CMS Version)
Old generation collection is done in serial“Parallel” StrategyYoung generation collection is done in parallel
Old generation collection is done in serial“Parallel Old” StrategyYoung generation collection is done in parallelOld generation collection is done mostly in parallel
Low pause collector (short Stop the World pauses)Uses Parallel New for new generation GCUses CMS for old generation GCNon compacting old generation collectorStarts before the memory space is full (68%)Requires a larger heapConcurrent Mark-Sweep StrategyGarbage Collectors
Serial Collector (New Generation Space)Garbage Collectors
Serial GC Strategy - Young GenerationGarbage CollectorsNo more room! Promoting to Tenure spaceEden memory spaceGarbage Collection!Resuming ApplicationSurvived!Earned it’s place inTenure spaceSurvivor space (To)Survivor space (From)Tenure memory space
Serial Collector (Old Generation Space)Garbage Collectors
Concurrent Mark-SweepGarbage Collectors
CMS - Old GenerationGarbage CollectorsTenure memory spaceGarbage Collection!Resuming ApplicationStop The World!Phase:Initial MarkConcurrent MarkRemarkConcurrent SweepConcurrent Pre-Clean
High probability soft real time collectorOne memory space for the young and tenure generationEntire memory space is divided into equally sized cardsCards are managed by regions and tracked by “Remembered Sets” for changesA global card table track all the cardsGarbage First (G1) What’s the big deal?Garbage Collectors
Garbage First (G1) - Heap StructureGarbage CollectorsCard(512 Bytes)Region ACard(512 Bytes)Region BGlobal Card TableCard(512 Bytes)Region NRemembered Set (Per Region)
Garbage First - Minor CollectionGarbage CollectorsSimilar to Parallel NewCompacts young regions Also compacts old regions if there’s timeGarbage First - Major CollectionReclaims empty regions at once
Marks low lived ratio regions for collection in the minor collection phaseIDI GC Problem Related HistoryGarbage Collectors @ IDI
IDI Garbage Collection Strategy:Garbage Collectors @ IDI
The IDI Test CaseChoosing the right hardwareGarbage CollectorsJVM TuningAgendaJVM Tuning
This is JVM Tuning:JVM Tuning
-Xmx<size><units>-Xms<size><units>-d64-server-XX:MaxPermSize=<size><units>-XX:-HeapDumpOnOutOfMemoryErrorThe must know flagsJVM Tuning
-Xloggc:<file_name>-XX:+ PrintHeapAtGC-XX:+ PrintGCDateStamps-XX:+ PrintGCDetails-XX:+ PrintGCApplicationStoppedTime-XX:+ PrintGCApplicationConcurrentTimeGC LogsJVM Tuning
-XX:+ UseSerialGC-XX:+ UseParNewGC-XX:+UseConcMarkSweepGC -XX:+ UseParallelGC-XX:+UseParallelOldGC-XX:+UseG1GC (JDK 1.7)-XX:+UnlockExperimentalVMOptions(for G1 JDK 1.6_14)  Garbage Collector StrategiesJVM Tuning
Tuning GCJVM Tuning

HotSpot JVM Tuning

  • 1.
    HotSpot JVM TuningBy:Gilad GaronTechnicalMeeting!
  • 2.
    -Xmx2gIt’s more thanjust:What is JVM Tuning?It’s a combination of:Hardware selection
  • 3.
    Software architectureBut mostof all, JVM Tuning is about:Understanding how your application works!
  • 4.
    The IDI TestCaseChoosing the right hardwareGarbage CollectorsJVM TuningAgendaJVM Tuning
  • 5.
    Swing desktop clientapplicationWicket web applicationMobile web application (In development)Multiple AS:JBoss Clusters, Apache Cluster, Tomcat & TerracottaMultiple frameworks: Spring, Guice, Wicket, Hibernate, Terracotta DSO, XStream, EJB 3.0, JMS, CGLib & Proprietary frameworks Technical InformationThe IDI Test Case
  • 6.
  • 7.
    3000 +/- EJBInvocations per minute100+ concurrent web sessionsInternal Print servers clients Internal Mail servers clientsInternal Webservices clientsJBoss EAR cluster user load informationThe IDI Test Case
  • 8.
    The IDI TestCaseChoosing the right hardwareGarbage CollectorsJVM TuningAgendaJVM Tuning
  • 9.
    How many softwareengineers does it take to change a light bulb?Hardware choices affects code performanceHardware choices affects OS offerings (Do you really want Windows?)Hardware isn’t easily replaced, it costs a lot.Choosing the right hardwareNone. It's a hardware problem.
  • 10.
    Which CPU architectureis right for you?Higher clock speed? (what about Moore’s law?)Higher core count?Number of hardware threads?Choosing the right hardwareRemember:Not all CPU’s are created equally
  • 11.
    Highly computational appsrelay on clock speed
  • 12.
    Highly concurrent /multi user app relay on number of threads
  • 13.
    Hardware benchmarking helpsa lot, but it’s difficult to arrangeIntel Xeon / Itanium?AMD Operton?Sun SPARC?IBM Power?What should be your opinion?Choosing the right hardwareThe winner is….No one will ever ask for your opinion (almost)
  • 14.
    IDI Hardware historyChoosingthe right hardware @ IDI
  • 15.
    The IDI TestCaseChoosing the right hardwareGarbage CollectorsJVM TuningAgendaJVM Tuning
  • 16.
    Remember this?Garbage CollectorsGarbageCollection means that don’t have to anymore
  • 17.
    When the JVMstarts, the host OS assigns a dedicated memory space to that VMThe VM allocates memory to the application within that dedicated memory spaceThe VM frees memory automatically via garbage collectorsGarbage Collection is an expensive algorithmJVM Memory HandlingGarbage Collectors
  • 18.
    The memory spaceis divided into three separated memory spaces:Eden SpaceWhere objects are bornSurvivor SpacesWhere objects matureTenure SpaceWhere objects grow old and dieGenerational Memory SpaceGarbage Collectors
  • 19.
    HotSpot VM‘sGenerational Memory SpaceGarbage CollectorsEden SpaceSurvivor Space 2Survivor Space 1Tenure (Old) GenerationPermanent Generation
  • 20.
    ConcurrencyConcurrency describes itsability to do work while application threads are still runningParallelismParallelismdescribes the collector's ability to perform its work across multiple threads of execution.Hence, a collector can be parallel but not concurrent, concurrent but not parallel, or both parallel and concurrent.Technical Terms:Garbage Collectors
  • 21.
    Copy CollectorA collectorthat copies live object from one space to anotherLow Pause CollectorA collector that works along side the application threadsThroughput CollectorA collector that doesn’t add to the serial execution time of the applicationTechnical Terms:Garbage Collectors
  • 22.
    Memory FragmentationThe amountof unusable free memory (small holes that object can’t be fitted in)Stop the world:The application threads are stopped during the garbage collectionMinor CollectionA garbage collection of the young generationMajor CollectionA garbage collection of the old generationTechnical Terms, Continued:Garbage Collectors
  • 23.
    Types of GCStrategies (Generational):Garbage Collectors
  • 24.
    Garbage Collectors“Parallel New”StrategyYoung generation collection is done in parallel (CMS Version)
  • 25.
    Old generation collectionis done in serial“Parallel” StrategyYoung generation collection is done in parallel
  • 26.
    Old generation collectionis done in serial“Parallel Old” StrategyYoung generation collection is done in parallelOld generation collection is done mostly in parallel
  • 27.
    Low pause collector(short Stop the World pauses)Uses Parallel New for new generation GCUses CMS for old generation GCNon compacting old generation collectorStarts before the memory space is full (68%)Requires a larger heapConcurrent Mark-Sweep StrategyGarbage Collectors
  • 28.
    Serial Collector (NewGeneration Space)Garbage Collectors
  • 29.
    Serial GC Strategy- Young GenerationGarbage CollectorsNo more room! Promoting to Tenure spaceEden memory spaceGarbage Collection!Resuming ApplicationSurvived!Earned it’s place inTenure spaceSurvivor space (To)Survivor space (From)Tenure memory space
  • 30.
    Serial Collector (OldGeneration Space)Garbage Collectors
  • 31.
  • 32.
    CMS - OldGenerationGarbage CollectorsTenure memory spaceGarbage Collection!Resuming ApplicationStop The World!Phase:Initial MarkConcurrent MarkRemarkConcurrent SweepConcurrent Pre-Clean
  • 33.
    High probability softreal time collectorOne memory space for the young and tenure generationEntire memory space is divided into equally sized cardsCards are managed by regions and tracked by “Remembered Sets” for changesA global card table track all the cardsGarbage First (G1) What’s the big deal?Garbage Collectors
  • 34.
    Garbage First (G1)- Heap StructureGarbage CollectorsCard(512 Bytes)Region ACard(512 Bytes)Region BGlobal Card TableCard(512 Bytes)Region NRemembered Set (Per Region)
  • 35.
    Garbage First -Minor CollectionGarbage CollectorsSimilar to Parallel NewCompacts young regions Also compacts old regions if there’s timeGarbage First - Major CollectionReclaims empty regions at once
  • 36.
    Marks low livedratio regions for collection in the minor collection phaseIDI GC Problem Related HistoryGarbage Collectors @ IDI
  • 37.
    IDI Garbage CollectionStrategy:Garbage Collectors @ IDI
  • 38.
    The IDI TestCaseChoosing the right hardwareGarbage CollectorsJVM TuningAgendaJVM Tuning
  • 39.
    This is JVMTuning:JVM Tuning
  • 40.
  • 41.
    -Xloggc:<file_name>-XX:+ PrintHeapAtGC-XX:+ PrintGCDateStamps-XX:+PrintGCDetails-XX:+ PrintGCApplicationStoppedTime-XX:+ PrintGCApplicationConcurrentTimeGC LogsJVM Tuning
  • 42.
    -XX:+ UseSerialGC-XX:+ UseParNewGC-XX:+UseConcMarkSweepGC -XX:+UseParallelGC-XX:+UseParallelOldGC-XX:+UseG1GC (JDK 1.7)-XX:+UnlockExperimentalVMOptions(for G1 JDK 1.6_14)  Garbage Collector StrategiesJVM Tuning
  • 43.
  • 44.
  • 45.
  • 46.
    Tuning GCJVM TuningAndmany many more…
  • 47.
    Java SE 6HotSpot[tm] Virtual Machine Garbage Collection TuningMemory Management WhitepaperGarbage-First Garbage Collection WhitepaperSetting Java GC Parameters For Large HeapsJava Tuning White PaperJava HotSpot VM OptionsThe most complete list of -XX options for Java 6 JVMG1: Java's Garbage First Garbage Collector`References
  • 48.
    The Garbage-First GarbageCollector (JavaOne 2008)JVM Internals - Garbage Collection & Runtime OptimizationsGarbage Collection in the Java HotSpot Virtual MachineReferences