SlideShare a Scribd company logo
Heap Off Memory

          WTF ??

Reducing Heap memory stress
Abstract
* Java memory fundamental

* heap off memory principles

* heap-off cache with Apache DirectMemory
/me
Olivier Lamy

* Open Source Architect @Talend Apache Team
* Apache Member : Maven, Archiva, Tomcat,
DirectMemory, Build Infra, etc..
* Jenkins
* Add bugs in various OpenSource projects
* twitter.com/olamy olamy.blogspot.com
Java Memory Fundamental
Java Memory Fundamental

                The cool part

* Automatic memory allocation (do you remember
when you used malloc)

* Garbage collector (GC) (no more free)
Java Memory Fundamental

                  The bad part

* stop-the-world mode

* proportionnal to memory's size

* unpredictable unresponsive application :
complicated with tight SLA
Heap Off Memory


Not in the Heap process

   Limited GC stop

 « Unlimited storage »
Heap Off Memory
              How to use that ?
           Native libraries with JNA
          https://github.com/twall/jna

        ByteBuffer @since 1.4 with nio
    ByteBuffer.allocate( size ) (not off heap)
        ByteBuffer.allocateDirect( size )

You can use sun.misc.Unsafe but can cause issue
               and not portable
Heap Off Memory
              How to use that ?

You can manipulate only Buffer (ByteBuffer byte[]
                    etc..) !

   So you must serialize/deserialize your datas

Maximum size with -XX:MaxDirectMemorySize=
Our use case : Cache


       RAM : 10-60 ns
 Network : 10000-30000 ns
SSD Disk : 70000-120000 ns
Disk : 3000000-10000000 ns

 Cache must use memory !
On-Heap Cache


           Objects stored by reference (no
                   de/serialisation)

GC storm effect when refreshing/removing objects!
Off-Heap Cache


 de/serialisation overhead (hopefully some very
       performant libraries exist for that)

Cache objects payload no more affecting GC
Solutions :


* Terracotta BigMemory (off-heap storage on
top of ehcache)

* Infinispan (by Jboss)

* Huge collections

* Apache DirectMemory
Apache Direct Memory


                    Goals :
Apache Direct Memory is a multi layered cache
   implementation featuring off-heap memory
storage to enable caching of java objects without
          degrading jvm performance.
Apache Direct Memory


Joined Apache Incubator end 2011
12 developpers ATM
Under development :
  Memory allocation service just rewrite
  APIs are subject to be changed and bugs to be
   found !
Design & principles


ByteBuffer.allocateDirect is the foundation of the
 cache
ByteBuffers are allocated in big chunk and
 splitted for internal use
Design & principles
Build on layers
  CachingService : serialize object (pluggable)

  MemoryManagerService: Compute
   ByteBuffer access

  ByteBufferAllocatorService: Eventually deals
   with ByteBuffer
ByteBuffers Allocation
Merging Strategy
  No memory wasted
  Suffers from fragmentation
  Need synchronization at de/allocation


Fixed Size buffers allocation
  Memory wasted if size not correctly configured
  No fragmentation
Use case (1)
Multi layers cache
Most used objects are cached on heap, the rest
 off-heap (maybe overflow to disk)
Sounds like ehcache with BigMemory
Hard coded class to use :
 net.sf.ehcache.store.offheap.OffHeapStore
So same package class name in Apache
 DirectMemory
 (https://jira.terracotta.org/jira/browse/EHC-940)
                       Demo
Use case (2)
Cache Server
« à la » memcache tru http(s)
But with a REST Api and written in Java
Client API available
Demo
> PUT /dm/cache/bordeaux HTTP/1.1
> Content-Type:text/plain
{"millesime":"2003","description":"so good so
 good"}
< HTTP/1.1 200 OK
< X-DirectMemory-SerializeSize: 58
< Content-Length: 0
> GET /dm/cache/bordeaux HTTP/1.1
> Accept:text/plain
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Content-Length: 51
{"millesime":"2003","description":"so good so
 good"}
> DELETE /dm/cache/foo HTTP/1.1
Next Steps

JSR 107 ?
Benchmarks
Components Integration (Cassandra, Tomcat etc..)
Dynamic cache size modification
Management/Monitoring
Links
http://incubator.apache.org/directmemory/
https://issues.apache.org/jira/browse/DIRECTMEMORY
Demo project : https://bitbucket.org/olamy/heap-off-memory-
 wtf
Slides : http://www.slideshare.net/olamy
Thanks
  &&
Questions

More Related Content

PDF
Java 8 Launch - MetaSpaces
PPTX
Varnish caching technique
PDF
Django book15 caching
PDF
java-monitoring-troubleshooting
PDF
QCon 2017 - Java/JVM com Docker em produção: lições das trincheiras
PDF
Containerization Is More than the New Virtualization
PDF
Achieving the ultimate performance with KVM
ZIP
CHI-YAPC-2009
Java 8 Launch - MetaSpaces
Varnish caching technique
Django book15 caching
java-monitoring-troubleshooting
QCon 2017 - Java/JVM com Docker em produção: lições das trincheiras
Containerization Is More than the New Virtualization
Achieving the ultimate performance with KVM
CHI-YAPC-2009

What's hot (20)

PPT
Caching Data For Performance
KEY
CHI - YAPC NA 2012
PDF
Cache all the things - A guide to caching Drupal
PDF
Tools for Metaspace
KEY
MySQL Performance - SydPHP October 2011
PDF
Memcached Presentation
PPT
High Performance Wordpress
PPTX
Building Scalable Web Apps - LVL.UP KL
PPT
Performance and Scalability
PDF
Storage based snapshots for KVM VMs in CloudStack
PDF
Varnish Configuration Step by Step
PPTX
Nginx [engine x] and you (and WordPress)
PDF
The SPDY Protocol
PPT
Speeding Up The Snail
PDF
Vagrant for Virtualized Development
PDF
Travel with your mock server
PDF
Cobbler, Func and Puppet: Tools for Large Scale Environments
PDF
Using cobbler in a not so small environment 1.77
PPTX
PDF
Optimize drupal
Caching Data For Performance
CHI - YAPC NA 2012
Cache all the things - A guide to caching Drupal
Tools for Metaspace
MySQL Performance - SydPHP October 2011
Memcached Presentation
High Performance Wordpress
Building Scalable Web Apps - LVL.UP KL
Performance and Scalability
Storage based snapshots for KVM VMs in CloudStack
Varnish Configuration Step by Step
Nginx [engine x] and you (and WordPress)
The SPDY Protocol
Speeding Up The Snail
Vagrant for Virtualized Development
Travel with your mock server
Cobbler, Func and Puppet: Tools for Large Scale Environments
Using cobbler in a not so small environment 1.77
Optimize drupal
Ad

Viewers also liked (20)

PDF
Portfolio PlusAnimations 2009 NL
PPT
PAPER 2 2010
KEY
Building a Mega Community with PressWork
PPTX
ISoLA 2010: SADI Taverna plug-in
PPTX
Semana de la biblioteca 2011 final
PPTX
SWAT4LS 2011: SADI Knowledge Explorer Plug-in
PPTX
Design Studio
PPTX
How SADI & SHARE help restore the Scientific Method to in silico science
PDF
Tumor Type Search
PPS
Sin ropa
PDF
Leveraging trade associations
PDF
Tutorial 1.1 - Import Intogen tumor types
KEY
The Evolution of Live Preview Environment Design
PPT
2007 11 07 Presentazione Ir In Asm
PDF
Cs For Mk Brochure[1]
PPS
¡LA BELLEZA DE LOS ARBOLES!
PDF
Glanz Industries, Inc.
PPT
Internet Protocol
Portfolio PlusAnimations 2009 NL
PAPER 2 2010
Building a Mega Community with PressWork
ISoLA 2010: SADI Taverna plug-in
Semana de la biblioteca 2011 final
SWAT4LS 2011: SADI Knowledge Explorer Plug-in
Design Studio
How SADI & SHARE help restore the Scientific Method to in silico science
Tumor Type Search
Sin ropa
Leveraging trade associations
Tutorial 1.1 - Import Intogen tumor types
The Evolution of Live Preview Environment Design
2007 11 07 Presentazione Ir In Asm
Cs For Mk Brochure[1]
¡LA BELLEZA DE LOS ARBOLES!
Glanz Industries, Inc.
Internet Protocol
Ad

Similar to Heapoff memory wtf (20)

PPTX
Jug Lugano - Scale over the limits
PDF
Scale ColdFusion with Terracotta Distributed Caching for Ehchache
PDF
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
ODP
Caching technology comparison
PDF
Java and cgroups eng
PDF
Caching with Memcached and APC
PDF
HBase: Extreme Makeover
PPTX
Mini-Training: To cache or not to cache
PDF
My Old Friend Malloc
PDF
Caching principles-solutions
PPT
Java programing considering performance
ODP
Caching technology comparison
PDF
Inside The Java Virtual Machine
PDF
Developing High Performance and Scalable ColdFusion Application Using Terraco...
PDF
Developing High Performance and Scalable ColdFusion Applications Using Terrac...
PPTX
Rails caching
PPTX
Exploring .NET memory management - JetBrains webinar
PPTX
Javasession10
ODP
JBUG.be Infinispan
PDF
OOPs, OOMs, oh my! Containerizing JVM apps
Jug Lugano - Scale over the limits
Scale ColdFusion with Terracotta Distributed Caching for Ehchache
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Caching technology comparison
Java and cgroups eng
Caching with Memcached and APC
HBase: Extreme Makeover
Mini-Training: To cache or not to cache
My Old Friend Malloc
Caching principles-solutions
Java programing considering performance
Caching technology comparison
Inside The Java Virtual Machine
Developing High Performance and Scalable ColdFusion Application Using Terraco...
Developing High Performance and Scalable ColdFusion Applications Using Terrac...
Rails caching
Exploring .NET memory management - JetBrains webinar
Javasession10
JBUG.be Infinispan
OOPs, OOMs, oh my! Containerizing JVM apps

More from Olivier Lamy (6)

ODP
Apache sirona
ODP
Maven university-course
ODP
The Apache Way olamy
ODP
Juc paris olivier lamy talk
PDF
Direct memory @ devoxxfr
PDF
Tomcat Maven Plugin
Apache sirona
Maven university-course
The Apache Way olamy
Juc paris olivier lamy talk
Direct memory @ devoxxfr
Tomcat Maven Plugin

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
Teaching material agriculture food technology
PPTX
A Presentation on Artificial Intelligence
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Encapsulation theory and applications.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Electronic commerce courselecture one. Pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
MYSQL Presentation for SQL database connectivity
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Understanding_Digital_Forensics_Presentation.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Teaching material agriculture food technology
A Presentation on Artificial Intelligence
Network Security Unit 5.pdf for BCA BBA.
Encapsulation theory and applications.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
NewMind AI Weekly Chronicles - August'25 Week I
“AI and Expert System Decision Support & Business Intelligence Systems”
Electronic commerce courselecture one. Pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Unlocking AI with Model Context Protocol (MCP)
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm

Heapoff memory wtf

  • 1. Heap Off Memory WTF ?? Reducing Heap memory stress
  • 2. Abstract * Java memory fundamental * heap off memory principles * heap-off cache with Apache DirectMemory
  • 3. /me Olivier Lamy * Open Source Architect @Talend Apache Team * Apache Member : Maven, Archiva, Tomcat, DirectMemory, Build Infra, etc.. * Jenkins * Add bugs in various OpenSource projects * twitter.com/olamy olamy.blogspot.com
  • 5. Java Memory Fundamental The cool part * Automatic memory allocation (do you remember when you used malloc) * Garbage collector (GC) (no more free)
  • 6. Java Memory Fundamental The bad part * stop-the-world mode * proportionnal to memory's size * unpredictable unresponsive application : complicated with tight SLA
  • 7. Heap Off Memory Not in the Heap process Limited GC stop « Unlimited storage »
  • 8. Heap Off Memory How to use that ? Native libraries with JNA https://github.com/twall/jna ByteBuffer @since 1.4 with nio ByteBuffer.allocate( size ) (not off heap) ByteBuffer.allocateDirect( size ) You can use sun.misc.Unsafe but can cause issue and not portable
  • 9. Heap Off Memory How to use that ? You can manipulate only Buffer (ByteBuffer byte[] etc..) ! So you must serialize/deserialize your datas Maximum size with -XX:MaxDirectMemorySize=
  • 10. Our use case : Cache RAM : 10-60 ns Network : 10000-30000 ns SSD Disk : 70000-120000 ns Disk : 3000000-10000000 ns Cache must use memory !
  • 11. On-Heap Cache Objects stored by reference (no de/serialisation) GC storm effect when refreshing/removing objects!
  • 12. Off-Heap Cache de/serialisation overhead (hopefully some very performant libraries exist for that) Cache objects payload no more affecting GC
  • 13. Solutions : * Terracotta BigMemory (off-heap storage on top of ehcache) * Infinispan (by Jboss) * Huge collections * Apache DirectMemory
  • 14. Apache Direct Memory Goals : Apache Direct Memory is a multi layered cache implementation featuring off-heap memory storage to enable caching of java objects without degrading jvm performance.
  • 15. Apache Direct Memory Joined Apache Incubator end 2011 12 developpers ATM Under development : Memory allocation service just rewrite APIs are subject to be changed and bugs to be found !
  • 16. Design & principles ByteBuffer.allocateDirect is the foundation of the cache ByteBuffers are allocated in big chunk and splitted for internal use
  • 17. Design & principles Build on layers CachingService : serialize object (pluggable) MemoryManagerService: Compute ByteBuffer access ByteBufferAllocatorService: Eventually deals with ByteBuffer
  • 18. ByteBuffers Allocation Merging Strategy No memory wasted Suffers from fragmentation Need synchronization at de/allocation Fixed Size buffers allocation Memory wasted if size not correctly configured No fragmentation
  • 19. Use case (1) Multi layers cache Most used objects are cached on heap, the rest off-heap (maybe overflow to disk) Sounds like ehcache with BigMemory Hard coded class to use : net.sf.ehcache.store.offheap.OffHeapStore So same package class name in Apache DirectMemory (https://jira.terracotta.org/jira/browse/EHC-940) Demo
  • 20. Use case (2) Cache Server « à la » memcache tru http(s) But with a REST Api and written in Java Client API available Demo
  • 21. > PUT /dm/cache/bordeaux HTTP/1.1 > Content-Type:text/plain {"millesime":"2003","description":"so good so good"} < HTTP/1.1 200 OK < X-DirectMemory-SerializeSize: 58 < Content-Length: 0 > GET /dm/cache/bordeaux HTTP/1.1 > Accept:text/plain < HTTP/1.1 200 OK < Content-Type: text/plain < Content-Length: 51 {"millesime":"2003","description":"so good so good"} > DELETE /dm/cache/foo HTTP/1.1
  • 22. Next Steps JSR 107 ? Benchmarks Components Integration (Cassandra, Tomcat etc..) Dynamic cache size modification Management/Monitoring
  • 23. Links http://incubator.apache.org/directmemory/ https://issues.apache.org/jira/browse/DIRECTMEMORY Demo project : https://bitbucket.org/olamy/heap-off-memory- wtf Slides : http://www.slideshare.net/olamy