WHO AM I.

Similar documents
Heap Off Memory WTF?? Reducing Heap memory stress

High Performance Managed Languages. Martin Thompson

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

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

High Performance Managed Languages. Martin Thompson

THE TROUBLE WITH MEMORY

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

Java Memory Management. Märt Bakhoff Java Fundamentals

JVM Memory Model and GC

G1 Garbage Collector Details and Tuning. Simone Bordet

A program execution is memory safe so long as memory access errors never occur:

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

Attila Szegedi, Software

Running class Timing on Java HotSpot VM, 1

Present but unreachable

Habanero Extreme Scale Software Research Project

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

Lecture 13: Garbage Collection

Compiler construction 2009

Garbage Collection Algorithms. Ganesh Bikshandi

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

High-Level Language VMs

Concurrent Garbage Collection

Garbage Collection. Hwansoo Han

JAVA PERFORMANCE. PR SW2 S18 Dr. Prähofer DI Leopoldseder

Memory. don t forget to take out the

JVM Troubleshooting MOOC: Troubleshooting Memory Issues in Java Applications

Standardize caching in Java. Introduction to JCache and In-Memory data grid solutions

CS Computer Systems. Lecture 8: Free Memory Management

A new Mono GC. Paolo Molaro October 25, 2006

Low latency & Mechanical Sympathy: Issues and solutions

The Z Garbage Collector Low Latency GC for OpenJDK

Exploiting the Behavior of Generational Garbage Collector

CMSC 330: Organization of Programming Languages

Dynamic Memory Management

Compact Off-Heap Structures in the Java Language

Windows Java address space

The Z Garbage Collector An Introduction

Dynamic Memory Management

LANGUAGE RUNTIME NON-VOLATILE RAM AWARE SWAPPING

Run-time Environments -Part 3

Heap Management. Heap Allocation

JamaicaVM Java for Embedded Realtime Systems

Memory Management: The Details

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

Dynamic Memory Allocation: Basic Concepts

Debugging Your Production JVM TM Machine

Memory management. Johan Montelius KTH

Dynamic Storage Allocation

CMSC 330: Organization of Programming Languages

HBase Practice At Xiaomi.

Dynamic Memory Management! Goals of this Lecture!

Dynamic Memory Allocation

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

New Java performance developments: compilation and garbage collection

Managed runtimes & garbage collection. CSE 6341 Some slides by Kathryn McKinley

Java Performance Tuning

Managed runtimes & garbage collection

Run-Time Environments/Garbage Collection

Name, Scope, and Binding. Outline [1]

SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine p. 1

MultiJav: A Distributed Shared Memory System Based on Multiple Java Virtual Machines. MultiJav: Introduction

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

Dynamic Memory Allocation: Basic Concepts

GridGain and Apache Ignite In-Memory Performance with Durability of Disk

Lesson 2 Dissecting Memory Problems

ECE 598 Advanced Operating Systems Lecture 10

/** * Gimme Caching * The JCache Way */

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

6.172 Performance Engineering of Software Systems Spring Lecture 9. P after. Figure 1: A diagram of the stack (Image by MIT OpenCourseWare.

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

Garbage Collection. Weiyuan Li

Pause-Less GC for Improving Java Responsiveness. Charlie Gracie IBM Senior Software charliegracie

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package

Deallocation Mechanisms. User-controlled Deallocation. Automatic Garbage Collection

Java Performance: The Definitive Guide

CPSC 213. Introduction to Computer Systems. Winter Session 2017, Term 2. Unit 1c Jan 24, 26, 29, 31, and Feb 2

NUMA in High-Level Languages. Patrick Siegler Non-Uniform Memory Architectures Hasso-Plattner-Institut

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100

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

Apple. Massive Scale Deployment / Connectivity. This is not a contribution

Manual Allocation. CS 1622: Garbage Collection. Example 1. Memory Leaks. Example 3. Example 2 11/26/2012. Jonathan Misurda

the gamedesigninitiative at cornell university Lecture 9 Memory Management

Hard Real-Time Garbage Collection in Java Virtual Machines

Fundamentals of GC Tuning. Charlie Hunt JVM & Performance Junkie

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

Shenandoah: Theory and Practice. Christine Flood Roman Kennke Principal Software Engineers Red Hat

Jaguar: Enabling Efficient Communication and I/O in Java

Software Speculative Multithreading for Java

code://rubinius/technical

Memory Management: The process by which memory is shared, allocated, and released. Not applicable to cache memory.

Dynamic Data Structures. CSCI 112: Programming in C

A Tour to Spur for Non-VM Experts. Guille Polito, Christophe Demarey ESUG 2016, 22/08, Praha

Runtime Defenses against Memory Corruption

Inside the Garbage Collector

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package

Introduction to Computer Systems /18 243, fall th Lecture, Oct. 22 th

Requirements, Partitioning, paging, and segmentation

Easy Distributed Systems Using Hazelcast. Peter Veentjer

Complex, concurrent software. Precision (no false positives) Find real bugs in real executions

Transcription:

WHO AM I Christoph Engelbert (@noctarius2k) 8+ years of professional Java development Specialized to performance, GC, traffic topics Apache DirectMemory PMC Previous companies incl. Ubisoft and HRS Official Inhabitant of Hazelcastia CastMapR MapReduce for Hazelcast 3 Co-Author Java Off-heap JEP Proposal

TOPICS Java Memory Layout Definition of Off-Heap? Direct Memory Access? Why do we need Off-Heap Memory? Options for Off-Heap Storage Advantages and Disadvantages of (Off- )Heap Available Frameworks (Not so) Secret Future Small demonstration

JAVA MEMORY LAYOUT A FAST WALK-THROUGH

JAVA MEMORY LAYOUT (1/5)

JAVA MEMORY LAYOUT (2/5) YOUNG GENERATION - EDEN SPACE Only used for Object-Allocation TLAB¹ allocation available Affected by Minor and Major GC Objects moved to Survivor on Minor GC ¹ TLAB: Thread Local Allocation Buffer

JAVA MEMORY LAYOUT (3/5) YOUNG GENERATION - SURVIVOR SPACES Always one From-Space and one To-Space From-Space contains living objects on last GC Minor GC switches the Survivor Spaces Alive Objects are moved to To-Space Affected by Minor and Major GC Long living objects eventually moved to Tenured

JAVA MEMORY LAYOUT (4/5) TENURED SPACE Contains only long living objects Affected only by Major GC More objects means more GC spend time Concurrent object inspectation available Long Stop-The-World pauses possible Not optimal for big datasets

JAVA MEMORY LAYOUT (5/5) PERMGEN / META SPACE Class bytecodes Class metadata Runtime information Code Compilation Cache etc.

G1 (GARBAGE FIRST COLLECTOR) Generational GC Heap splitted into same sized regions Every region is either Eden, Survivor or Tenured space

DEFINITION OF OFF-HEAP?

DEFINITION OF OFF-HEAP? Off-Heap is a (continuously) self allocated, managed and freed direct memory region. It is not under control of the Java GarbageCollector and needs custom written allocation and cleanup of data-regions. Off-Heap can not be used for allocation of Java objects.

I'M DUKE SKYWALKER I'M HERE TO RESCUE YOU!

DIRECT MEMORY ACCESS? GIVE YOURSELF TO THE DARK SIDE

DIRECT MEMORY ACCESS? ARE YOU SERIOUS? Fast memory area Not affecting the GC Officially available since Java 1.4 Serialization overhead when storing objects Limited by -XX:MaxDirectMemorySize

WHY DO WE NEED OFF-HEAP MEMORY?

WHY DO WE NEED OFF-HEAP MEMORY? Storing of huge datasets Zero-Copy writes to channels Lower pressure on GC / less GC pauses Storage Space only limited by RAM Compact data representation possible IPC SharedMemory with Memory-Mapped-Files

OPTIONS FOR OFF-HEAP STORAGE

OPTIONS FOR OFF-HEAP STORAGE (1/3) JNI (Java Native Interface) int* buffer = ( int* ) malloc( 1024 * sizeof(int) ); if( buffer == NULL ) throwoutofmemoryexception(); for( int i = 0; i < 1024; i++ ) buffer[sizeof(int) * i] = i; free( buffer );

OPTIONS FOR OFF-HEAP STORAGE (2/3) (Direct)ByteBuffer ByteBuffer buffer = ByteBuffer.allocateDirect( 1024 * 4 ); for( int i = 0; i < 1024; i++) buffer.putint( i ); // buffer is automatically freed by GC

OPTIONS FOR OFF-HEAP STORAGE (3/3) sun.misc.unsafe Unsafe unsafe = tricktoretrieveunsafe(); long address = unsafe.allocatememory( 1024 * 4 ); for( int i = 0; i < 1024; i++ ) unsafe.putint( address + 4 * i, i ); unsafe.freememory( address );

ADVANTAGES AND DISADVANTAGES OF (OFF-)HEAP

ADVANTAGES ON-HEAP No messing with malloc Automatic Garbage Collection No need for Serialization

DISADVANTAGES ON-HEAP Slowdown on high allocation rate Big overhead on small objects (header) Heavily depending on GC Combination

ADVANTAGES OFF-HEAP No limitation* in size Compact data layout Zero-Copy socket read/write possible Frameworks available to manage memory

DISADVANTAGES OFF-HEAP Allocation is up to you Deallocation is up to you Data layout is up to you Serialization may be required JNI requires native library

AVAILABLE FRAMEWORKS

AVAILABLE FRAMEWORKS (1/5) Apache DirectMemory Terracotta BigMemory Hazelcast ElasticMemory MapDB.org etc.

AVAILABLE FRAMEWORKS (2/5) Apache DirectMemory CacheService<String, String> cacheservice = new DirectMemory<...>().setNumberOfBuffers( 10 ).newcacheservice(); cacheservice.put( "MyKey", "SomeValue" ); String value = cacheservice.get( "MyKey" );

AVAILABLE FRAMEWORKS (3/5) Terracotta BigMemory <ehcache xml:nonamespaceschemalocation="..." name="mycachedefinition"> <cache name="myoffheapcache" maxbyteslocaloffheap="2g" /> </ehcache> CacheManager cachemanager = new CacheManager(); Cache datastore = cachemanager.get( "MyOffheapCache" ); Element element = new Element( "MyKey", "SomeValue" ); datastore.put( element ); String value = (String) datastore.get( "MyKey" ).getobjectvalue();

AVAILABLE FRAMEWORKS (4/5) Hazelcast Offheap <hazelcast xml:nonamespaceschemalocation="..."> <map name="mymap"> <storage-type>offheap</storage-type> </map> </hazelcast> HazelcastInstance hz = Hazelcast.newInstance(); // Returns a IMap extends ConcurrentMap Map<String, String> map = hz.getmap( "MyMap" ); map.put( "MyKey", "SomeValue" ); String value = map.get( "MyKey" );

AVAILABLE FRAMEWORKS (5/5) MapDB.org DB db = DBMaker.newDirectMemoryDB().sizeLimit( 2 ).make(); // Returns a HTreeMap extends ConcurrentMap Map<String, String> map = db.createhashmap( "cache" ).make(); map.put( "MyKey", "SomeValue" ); String value = map.get( "MyKey" );

FURTHER INFORMATION AVAILABLE The Must-Read for Off-Heap http://bit.ly/must-read-off-heap PacketObject Description from IBM http://bit.ly/packet-objects Compact Datastructures (Martin Thompson) http://bit.ly/compact-datastructures C++ Like Performance for Serialization http://bit.ly/serialization-performance Tricks with Direct Memory Access in Java http://bit.ly/direct-memory-tricks

THE OFF-HEAP JEP PROPOSAL MAY THE FORCE BE WITH YOU. THE FORCE IS STRONG WITH THIS ONE.

OFF-HEAP JEP PROPOSAL ByteBuffer like interface Fully 64-bit sizes and offsets Compare-And-Swap operations Volatile and ordered operations Optional bounding checks Supports Memory mapping Support Foreign Function Interface (FFI) JEP

OFF-HEAP JEP PROPOSAL - CODE EXAMPLE DISCLAIMER: PROVISIONAL API import javax.direct.*; BytesFactory factory = createbytesfactory(); Bytes bytes = factory.boundschecking( false ).deallocationchecks( false ).freeongc( false ).create( ByteOrder.LITTLE_ENDIAN, 1024 * 4 ); for( int i = 0; i < 1024; i++ ) bytes.putvolatileint( i ); bytes.release();

OFF-HEAP JEP PROPOSAL Proposal Discussion Group http://bit.ly/offheap-ml Proposal Text http://bit.ly/proposal-text FFI JEP 191 http://bit.ly/ffi-jep

THANK YOU! ANY QUESTIONS? @noctarius2k @hazelcast http://www.sourceprojects.com http://github.com/noctarius Images: www.clipartist.info, Gnome Nebula Theme, KDE theme, www.grabsteine-klnt.de