Java & Coherence Simon Cook - Sales Consultant, FMW for Financial Services

Similar documents
The Garbage-First Garbage Collector

Fundamentals of GC Tuning. Charlie Hunt JVM & Performance Junkie

Do Your GC Logs Speak To You

Java Performance Tuning

Java Performance Tuning From A Garbage Collection Perspective. Nagendra Nagarajayya MDE

JVM Troubleshooting MOOC: Troubleshooting Memory Issues in Java Applications

JVM Memory Model and GC

G1 Garbage Collector Details and Tuning. Simone Bordet

10/26/2017 Universal Java GC analysis tool - Java Garbage collection log analysis made easy

Low latency & Mechanical Sympathy: Issues and solutions

The Fundamentals of JVM Tuning

Garbage Collection. Hwansoo Han

2011 Oracle Corporation and Affiliates. Do not re-distribute!

Understanding Garbage Collection

Attila Szegedi, Software

Finally! Real Java for low latency and low jitter

The G1 GC in JDK 9. Erik Duveblad Senior Member of Technical Staf Oracle JVM GC Team October, 2017

Algorithms for Dynamic Memory Management (236780) Lecture 4. Lecturer: Erez Petrank

HBase Practice At Xiaomi.

Exploiting the Behavior of Generational Garbage Collector

The C4 Collector. Or: the Application memory wall will remain until compaction is solved. Gil Tene Balaji Iyengar Michael Wolf

NG2C: Pretenuring Garbage Collection with Dynamic Generations for HotSpot Big Data Applications

Contents. Created by: Raúl Castillo

Garbage collection. The Old Way. Manual labor. JVM and other platforms. By: Timo Jantunen

Understanding Java Garbage Collection

Concurrent Garbage Collection

Garbage-First Garbage Collection by David Detlefs, Christine Flood, Steve Heller & Tony Printezis. Presented by Edward Raff

Enabling Java-based VoIP backend platforms through JVM performance tuning

Runtime. The optimized program is ready to run What sorts of facilities are available at runtime

Understanding Java Garbage Collection

Kodewerk. Java Performance Services. The War on Latency. Reducing Dead Time Kirk Pepperdine Principle Kodewerk Ltd.

Garbage Collection. Akim D le, Etienne Renault, Roland Levillain. May 15, CCMP2 Garbage Collection May 15, / 35

Automatic Memory Management

One-Slide Summary. Lecture Outine. Automatic Memory Management #1. Why Automatic Memory Management? Garbage Collection.

Understanding Java Garbage Collection

Understanding Java Garbage Collection

The Application Memory Wall

Java Application Performance Tuning for AMD EPYC Processors

Java Memory Management. Märt Bakhoff Java Fundamentals

Understanding Java Garbage Collection

JVM Performance Study Comparing Oracle HotSpot and Azul Zing Using Apache Cassandra

OS-caused Long JVM Pauses - Deep Dive and Solutions

JVM Performance Tuning with respect to Garbage Collection(GC) policies for WebSphere Application Server V6.1 - Part 1

High Performance Managed Languages. Martin Thompson

Typical Issues with Middleware

Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java)

JVM Performance Study Comparing Java HotSpot to Azul Zing Using Red Hat JBoss Data Grid

Part I Garbage Collection Modeling: Progress Report

Garbage Collection Algorithms. Ganesh Bikshandi

It s Good to Have (JVM) Options

Azul Pauseless Garbage Collection

TECHNOLOGY WHITE PAPER. Azul Pauseless Garbage Collection. Providing continuous, pauseless operation for Java applications

Debugging Your Production JVM TM Machine

Lecture 15 Garbage Collection

High Performance Managed Languages. Martin Thompson

Acknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides

Garbage Collection (aka Automatic Memory Management) Douglas Q. Hawkins. Why?

CMSC 330: Organization of Programming Languages

Memory management has always involved tradeoffs between numerous optimization possibilities: Schemes to manage problem fall into roughly two camps

Shenandoah An ultra-low pause time Garbage Collector for OpenJDK. Christine H. Flood Roman Kennke

THE TROUBLE WITH MEMORY

Lecture 13: Garbage Collection

Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide. Release 10

Generational Garbage Collection Theory and Best Practices

CMSC 330: Organization of Programming Languages

Enabling Java in Latency Sensitive Environments

Java Garbage Collector Performance Measurements

Java Performance Tuning and Optimization Student Guide

Java Garbage Collection Best Practices For Tuning GC

New Java performance developments: compilation and garbage collection

Java Without the Jitter

CMSC 330: Organization of Programming Languages. Memory Management and Garbage Collection

Garbage Collection (2) Advanced Operating Systems Lecture 9

A JVM Does What? Eva Andreasson Product Manager, Azul Systems

Running class Timing on Java HotSpot VM, 1

Garbage Collection. Steven R. Bagley

A new Mono GC. Paolo Molaro October 25, 2006

Generation scavenging: A non-disruptive high-performance storage reclamation algorithm By David Ungar

CS61C : Machine Structures

Hard Real-Time Garbage Collection in Java Virtual Machines

A Generational Mostly-concurrent Garbage Collector. Tony Printezis and David Detlefs

SAP ENTERPRISE PORTAL. Scalability Study - Windows

ACM Trivia Bowl. Thursday April 3 rd (two days from now) 7pm OLS 001 Snacks and drinks provided All are welcome! I will be there.

Compiler construction 2009

Run-Time Environments/Garbage Collection

Habanero Extreme Scale Software Research Project

CA341 - Comparative Programming Languages

Towards High Performance Processing in Modern Java-based Control Systems. Marek Misiowiec Wojciech Buczak, Mark Buttner CERN ICalepcs 2011

Shenandoah: An ultra-low pause time garbage collector for OpenJDK. Christine Flood Principal Software Engineer Red Hat

The Z Garbage Collector Scalable Low-Latency GC in JDK 11

Garbage Collection. Weiyuan Li

Automatic Garbage Collection

Garbage Collection (1)

CS Computer Systems. Lecture 8: Free Memory Management

Inside the Garbage Collector

IBM Research Report. Efficient Memory Management for Long-Lived Objects

How to keep capacity predictions on target and cut CPU usage by 5x

Garbage-First Garbage Collection

JBoss Performance Tuning. Bill Meyer JBoss Sr. Solutions Architect

Programming Language Implementation

Transcription:

Java & Coherence Simon Cook - Sales Consultant, FMW for Financial Services with help from Adrian Nakon - CMC Markets & Andrew Wilson - RBS 1 Coherence Special Interest Group Meeting 1 st March 2012

Presentation Agenda An Overview of the Java Memory Management Java Garbage Collectors Tuning Garbage Collection for Coherence The Next Generation Garbage Collector Questions and Answers 2 Coherence Special Interest Group Meeting 1 st March 2012

Tuning the Underlying Platform is Important Efficiency is the key Coherence is extremely fast even with restricted resources Operational efficiency has many advantages Better run-time performance Fewer resources to manage Fewer Oracle Coherence licenses to buy Remember to take a holistic when tuning The hardware and the operating system The Java Virtual Machine Coherence configuration Application code Database tuning and optimisation 3 Coherence Special Interest Group Meeting 1 st March 2012

Tuning the Java Virtual Machine Lots and lots and lots of options Current generation JVMs have many tuning options Some will give small efficiencies Some will give massive efficiencies Tuning your GC to minimise pause time will be key Reduce the number of Full GCs Reduce the latency overhead of GCs Long GCs are disastrous for a distributed caches such as Coherence Understand your latency requirements and work towards them You will have to make compromises in some way 4 Coherence Special Interest Group Meeting 1 st March 2012

Generational Garbage Collection Employed by all HotSpot GC algorithms The majority of JVMs use generational collectors The heap is split into generations Young, newly created objects Old, longer lived objects Weak generational hypothesis Proved by observation and it s extremely accurate for Java Applications Most objects are very short lived 80-98% of all newly allocated objects die within a few million instructions 80-98% of all newly allocated objects die before another megabyte has been allocated 5 Coherence Special Interest Group Meeting 1 st March 2012

Some Quick Words on Garbage Collectors Dealing with the rubbish There are two classes of GC algorithms in Java The Throughput Collectors The Low Pause (latency) Collectors Throughput collectors are the default They reorganise the old heap during a collection They are not suitable for Coherence CMS is a low pause collector Aims to keep application pauses to a minimum Is a suitable collector for Coherence G1 is still in development do not use for Coherence today * 6 Coherence Special Interest Group Meeting 1 st March 2012

The Java Heap Layout For all collector algorithms Promoted after YGC Promoted after n swaps Eden * Survivor 1 * Survivor 2* Old Perm ** Objects are created here Swapped n times Old objects live and die here Classes etc. go here * Young Space is composed of Eden and the two Survivor Spaces. ** Perm Space is going away! 7 Coherence Special Interest Group Meeting 1 st March 2012

Compacted Old Space Throughput Collectors Serial and Parallel (and G1) Before FGC Occupied Space After FGC Occupied Space Free Space Object Allocation Pointer 8 Coherence Special Interest Group Meeting 1 st March 2012

Fragmented Old Space CMS Collector Occupancy Threshold Before FGC Occupied Space Free Space After FGC Free Space Free List 9 Coherence Special Interest Group Meeting 1 st March 2012

You may think it s impossible to run large heaps with CMS on restricted hardware. This is simply not true, it s very possible! Adrian Nakon Coherence Architect, CMC Markets 10 Coherence Special Interest Group Meeting 1 st March 2012

A List of Stop the World Pauses Know your enemy 1. Young space collections 2. Full GCs All collectors 3. System GCs Called via JMX or the application 4. CMS Initial Mark Phase 5. CMS Remark Phase 6. CMS Concurrent Mode Failure 11 Coherence Special Interest Group Meeting 1 st March 2012

Tuning the CMS Collector The collector of choice for Coherence CMS will enable large heaps, even on restricted hardware CMS is not like the other collectors Concurrent collections with multiple, small STW pauses Running with defaults can be fine for small heaps For larger heaps you need to consider tuning CMS for best results Should you use NIO or 64 bit JVMs? CMS can perform very well will large heaps when correctly tuned NIO has limitations and garbage collection a manual task 12 Coherence Special Interest Group Meeting 1 st March 2012

Tuning the CMS Collector Good performance will take some thought A different collector is used for the Young Space The ParNew Collector The aim is to minimise the STW pauses The Young Space Collections The Initial Mark The Remark CMS is concurrent and will therefore require CPU It will compete with your application during collections It fragments the Old Space Object allocations are more complicated 13 Coherence Special Interest Group Meeting 1 st March 2012

Tuning the CMS Collector The Weak Generational Hypothesis It is important to give objects the opportunity to die young Young Collections are fast and efficient Only live objects are copied Most objects will be dead (transient) so it is fast Space is cleared quickly with minimal application pauses Sizing the Young ratio is key Size the survivor spaces appropriately Configure the Tenuring Threshold appropriately Think about your cache expiry settings if appropriate (remember backups!) 14 Coherence Special Interest Group Meeting 1 st March 2012

Tuning the CMS Collector Minimise the marking phases pause times Minimise your pause times The Initial Mark Phase The Remark Phase CMS has to scan Young Space to look for relationships If Young Space is not empty this will take time You can instruct CMS to wait for a Young GC before starting An empty Young Space will dramatically reduce marking times 15 Coherence Special Interest Group Meeting 1 st March 2012

Tuning the CMS Collector Worst case scenario Concurrent Mode Failure All bets are off No new objects can be allocated into the Old Space The heap will be compacted to recover fragmented space This may take some time, grab a coffee Sizing your heap correctly is key to avoiding this Undersized heaps will make CMS work overtime Allowing objects to die in the young space will help avoid this Remember The Weak Generational Hypothesis Most objects die young and can be collected easily 16 Coherence Special Interest Group Meeting 1 st March 2012

Recommended Settings There may be some more, HotSpot has many Limited CPU resource results in... Fewer JVM s per server (less possible context switching) Strive to keep as much garbage out of tenured space as possible Maximum size of Young Space is limited by Young Gen collection time. Low latency requirements Ensure Young gens and CMS operations (mark / remark phases) are tightly integrated. Large data heaps required Use 64 bit JVM Every Application is different, do not just rely on the default JVM settings 17 Coherence Special Interest Group Meeting 1 st March 2012

Recommended Base Settings Generic JVM settings -verbose:gc -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=coherence/logs/<filename> -XX:+UseNUMA 18 Coherence Special Interest Group Meeting 1 st March 2012

Recommended Logging Settings Logging related JVM settings -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -Xloggc:/opt/oracle/admin/coherence/logs/<filename> 19 Coherence Special Interest Group Meeting 1 st March 2012

Recommended CMS Settings CMS tuning JVM Settings -XX:MaxTenuringThreshold=15 -XX:CMSWaitDuration=300000 -XX:+CMSScavengeBeforeRemark -XX:CMSInitiatingOccupancyFraction=65 -XX:+UseCMSInitiatingOccupancyOnly -XX:SurvivorRatio=4 -Xms<x>m Xmx<x>m -Xmn<y>m 20 Coherence Special Interest Group Meeting 1 st March 2012

Sizing your heap The Goldilocks Heap You re looking for The Goldilocks Heap Not too small Not too big Just right Profile your applications and it s object allocation and de-allocation Coherence Caches, expiry, processing, proxies, monitoring, etc. You have control over Initial and maximum overall heap size Perm space size Young space/old space ratio Survivor spaces/young space ratio 21 Coherence Special Interest Group Meeting 1 st March 2012

If your heap is 80% full after a full GC then your application performance will drop off a cliff. Andrew Wilson Coherence Architect, RBS 22 Coherence Special Interest Group Meeting 1 st March 2012

Sizing Your Heap 23 Coherence Special Interest Group Meeting 1 st March 2012

Sizing the Young Space If possible, allow objects to die young Remember the Weak Generational Hypothesis The vast majority of objects die very young Young collections are cheaper than old You need to meet the following criteria Make the young space large enough so objects die young Do not make the young space too large long GCs It s a balancing act You need to understand your application s memory profile 24 Coherence Special Interest Group Meeting 1 st March 2012

About Survivor Spaces Wait for short-lived objects to die Survivor spaces give objects more opportunity to die You have full control over this You can set the Survivor Space Ratio -XX:SurvivorRatio=<n> You can set the Maximum Tenuring Threshold (number of swaps) -XX:MaxTenuringThreshold=15 If you get this right Your young GCs will remain efficient More objects will die in young 25 Coherence Special Interest Group Meeting 1 st March 2012

Tenuring Distributions The flow of objects through the survivor spaces [GC 526703.667: [ParNew Desired survivor size 53673984 bytes, new threshold 8 (max 8) - age 1: 19709184 bytes, 19709184 total - age 2: 382384 bytes, 20091568 total - age 3: 435072 bytes, 20526640 total - age 4: 486544 bytes, 21013184 total - age 5: 725872 bytes, 21739056 total - age 6: 541144 bytes, 22280200 total - age 7: 741464 bytes, 23021664 total - age 8: 523912 bytes, 23545576 total : 852844K->26740K(943744K), 0.1001560 secs] 2780990K->1959523K(8283776K), 0.1003690 secs] [Times: user=0.26 sys=0.00, real=0.10 secs] 26 Coherence Special Interest Group Meeting 1 st March 2012

Tools There are many tools, some free, some not. OS Level Tools sar - ksar vmstat iostat Free nmon Log management tools vi, more, less, grep GCViewer Splunk Logscape LogMX Java Tools -verbose:gc gcstat jvisualvm jconsole Payware Tools Oracle Enterprise Manager Wily Introscope (CA) ITRS Geneos SL RTView Evident Clearstone 27 Coherence Special Interest Group Meeting 1 st March 2012

Further Reading Lots of good material out there A Generational Mostly-concurrent Garbage Collector by Tony Printezis and David Detlefs The guys who wrote CMS! http://labs.oracle.com/techrep/2000/abstract-88.html 28 Coherence Special Interest Group Meeting 1 st March 2012

The Garbage First (G1) Collector The next generation HotSpot Collector CMS Replacement (early access JRE 6 u14 onwards*) Server Style Garbage Collector Parallel Mostly Concurrent Generational Good Throughput Compacting Improved ease-of-use Predictable (though not hard real-time) 29 Coherence Special Interest Group Meeting 1 st March 2012

Colour Key for Heap Spaces Non-Allocated Space Young Generation Old Generation Recently Copied in Young Generation Recently Copied in Old Generation 30 Coherence Special Interest Group Meeting 1 st March 2012

Young GCs in CMS Young generation, split into Eden Survivor spaces Old generation In-place de-allocation Managed by free lists Heap fragmentation 31 Coherence Special Interest Group Meeting 1 st March 2012

Young GCs in CMS End of young generation GC 32 Coherence Special Interest Group Meeting 1 st March 2012

Young GCs in G1 Heap split into regions Currently 1MB regions Young generation A set of regions Old generation A set of regions 33 Coherence Special Interest Group Meeting 1 st March 2012

Young GCs in G1 During a young generation GC Survivors from the young regions are evacuated to: Survivor regions Old regions 34 Coherence Special Interest Group Meeting 1 st March 2012

Young GCs in G1 End of young generation GC 35 Coherence Special Interest Group Meeting 1 st March 2012

Summary: Young GCs in G1 Single physical heap, split into regions Set of contiguous regions allocated for large ( humongous ) objects No physically separate young generation A set of (non-contiguous) regions Very easy to resize Young GCs Done with evacuation pauses Stop-the-world Parallel Evacuate surviving objects from one set of regions to another 36 Coherence Special Interest Group Meeting 1 st March 2012

Old GCs in CMS (Sweeping After Marking) Concurrent marking phase Two stop-the-world pauses Initial mark Remark Marks reachable (live) objects Unmarked objects are deduced to be unreachable (dead) CMS 37 Coherence Special Interest Group Meeting 1 st March 2012

Old GCs in CMS (Sweeping After Marking) End of concurrent sweeping phase All unmarked objects are deallocated CMS 38 Coherence Special Interest Group Meeting 1 st March 2012

Old GCs in G1 (After Marking) Concurrent marking phase One stop-the-world pause Remark (Initial mark piggybacked on an evacuation pause) Calculates liveness information per region Empty regions can be reclaimed immediately 39 Coherence Special Interest Group Meeting 1 st March 2012

Old GCs in G1 (After Marking) End of remark phase 40 Coherence Special Interest Group Meeting 1 st March 2012

Old GCs in G1 (After Marking) Reclaiming old regions Pick regions with low live ratio Collect Only a few old regions collected per such GC 41 Coherence Special Interest Group Meeting 1 st March 2012

Old GCs in G1 (After Marking) We might leave some garbage objects in the heap In regions with very high live ratio We might collect them later 42 Coherence Special Interest Group Meeting 1 st March 2012

CMS vs. G1 Comparison CMS G1 43 Coherence Special Interest Group Meeting 1 st March 2012

In Summary Don t just accept the defaults, every application differs Strive to keep garbage out of Tenured/Old Space Size young accordingly Too big and your pauses will be too long Too small and too much garbage will be tenured Think about your Survivor Spaces Allow objects to die young Look at the object distributions Synchronise young and old collections with CMS Overall Heap size is important Don t give the GCs too much work to do 44 Coherence Special Interest Group Meeting 1 st March 2012

Q&A 45 Coherence Special Interest Group Meeting 1 st March 2012

46 Coherence Special Interest Group Meeting 1 st March 2012

47 Coherence Special Interest Group Meeting 1 st March 2012