SlideShare a Scribd company logo
1 of 49
Download to read offline
@AurBroszniowski @ljacomet#Caching101
Caching 101: on the JVM and beyond
Aurélien Broszniowski
@AurBroszniowski
Louis Jacomet
@ljacomet
Software AG / Terracotta
ehcache.org
@AurBroszniowski @ljacomet#Caching101
Agenda
• Caching theory
• Caching in Java
• Caching patterns
• Scaling
@AurBroszniowski @ljacomet#Caching101
Who are we?
• Aurélien Broszniowski
• Works at Software AG / Terracotta
since 2010 (startup days!)
• Coding since the teenage days, will
probably never stop
• OSS developer, see for example the
Rainfall performance testing
framework
• Louis Jacomet
• Principal Software Engineer at
Software AG / Terracotta since 2013
• Developper close to his forties who
did not dodge all things management
• Interests range from Concurrency to
API design, with learning new things
as the driving factor
@AurBroszniowski @ljacomet#Caching101
Who are you?
• Who knows nothing about caching?
• Who already uses caching in production?
• Who had caching related problems in production?
• Ehcache anyone?
@AurBroszniowski @ljacomet#Caching101
There are only two hard things in
Computer Science: 

cache invalidation and naming things.
-- Phil Karlton
@AurBroszniowski @ljacomet#Caching101
Caching theory
@AurBroszniowski @ljacomet#Caching101
What is a cache?
• Data structure holding a temporary copy of some data
• Trade off between higher memory usage for reduced latency
• Targets:
• Data which is reused
• Data which is expensive to compute or retrieve
@AurBroszniowski @ljacomet#Caching101
Locality of reference
• Same values or related ones are frequently accessed
• One form of predictable behaviour
• heavily used in CPUs for branch prediction
• Principle applied at different levels: CPUs, network and OS
• Ends up being a desirable feature in applications
• Application closer to hardware behaviour
@AurBroszniowski @ljacomet#Caching101
The long tail
• Coined by Chris Anderson
• Application of a Power Law probability distribution
• Pareto Law or 80:20 rule
@AurBroszniowski @ljacomet#Caching101
Terminology
• hit: when the cache returns a value
• miss: when the cache does not have a value
• cold: when the cache is empty
• warm-up: phase during which the cache fills up
• warm: when a cache is filled and helps the most
@AurBroszniowski @ljacomet#Caching101
Possible usages
• CPU bound applications
• Normal speedup through algorithm improvement or parallelisation
• Cache can help by storing computation results
• I/O bound applications
• Normal speedup through disk or network upgrades
• Cache can help by storing data locally
@AurBroszniowski @ljacomet#Caching101
Amdhal’s law
• Parallelisation
• P: parallel proportion
• N: processor count
@AurBroszniowski @ljacomet#Caching101
Amdhal’s law
• Sequential
• p: times a part was sped up
• f: fraction of time improved
@AurBroszniowski @ljacomet#Caching101
Cache coherence
• P write A to X, P read X => returns A when no writes happened in
between, must be valid for single processor too
• P2 writes A to X, P1 reads X => returns A if “enough time” has elapsed
• P1 writes A to X, P2 writes B to X => no one can ever see B then A at X
@AurBroszniowski @ljacomet#Caching101
Desired cache features
• Capacity control / eviction
• Data freshness / expiry
• Data consistency / invalidation
• Fault tolerant
@AurBroszniowski @ljacomet#Caching101
Caching in Java
@AurBroszniowski @ljacomet#Caching101
Google
Guava
And more …
BlazingCache
@AurBroszniowski @ljacomet#Caching101
JSR-107 aka JCache aka javax.cache
• JSR submitted in 2001
• Early draft in 2012 co-lead by Coherence and Ehcache representatives
• Specification finalised in March 2014
• Specifies API and semantics for temporary, 

in-memory caching of Java objects, including object creation, shared
access, spooling, invalidation, and consistency across JVM's
@AurBroszniowski @ljacomet#Caching101
javax.cache features
• CacheManager managing … Cache!
• Expiry
• Integration (CacheLoader and CacheWriter)
• Cache listeners
• Entry processors
• Annotations
• Statistics and MBeans
@AurBroszniowski @ljacomet#Caching101
javax.cache API
CacheManager repository,
identified by URI and ClassLoader
Named Cache repository, handles
their lifecycle
ConcurrentMap<K, V> sibling,
major interaction point for your logic
@AurBroszniowski @ljacomet#Caching101
javax.cache integration
• Spring caching abstraction since version 4.1
• Hibernate 5.2 has JCache integration for 2nd level cache
• Does not include transactional support
• More to come???
@AurBroszniowski @ljacomet#Caching101
Caching guidelines
• Immutable keys
• Favour immutable values
• store by-value or by-ref semantics
• Understand what you cache
• Think hibernate entities with lazy attributes
• Always account for a miss due to expiry or eviction
@AurBroszniowski @ljacomet#Caching101
Caching patterns
@AurBroszniowski @ljacomet#Caching101
Cache aside (miss)
Application
Cache
Database
@AurBroszniowski @ljacomet#Caching101
Cache aside (hit)
Application
Cache
Database
@YourTwitterHandle@AurBroszniowski @ljacomet#Caching101
D
em
o
@AurBroszniowski @ljacomet#Caching101
Hibernate 2nd level cache
• Stores dehydrated entities
• 4 strategies
• ReadOnly
• NonStrictReadWrite
• ReadWrite
• Transactional
@YourTwitterHandle#DVXFR14{session hashtag} @AurBroszniowski @ljacomet#Caching101
Sum
m
ary
@AurBroszniowski @ljacomet#Caching101
Cache aside conclusions
• Solution most seen out there
• Spring, Play, Grails, …
• Most often based on annotations
• Tricky to get the concurrency and / or atomicity right
• Especially when rolling you own
• Suffers from thundering herd: multiple invocations when cache is cold
@AurBroszniowski @ljacomet#Caching101
Cache through (miss)
Application Cache
Database
@AurBroszniowski @ljacomet#Caching101
Cache through (hit)
Application Cache
Database
@AurBroszniowski @ljacomet#Caching101
Cache through (write)
Application Cache
Database
@YourTwitterHandle@AurBroszniowski @ljacomet#Caching101
D
em
o
@YourTwitterHandle#DVXFR14{session hashtag} @AurBroszniowski @ljacomet#Caching101
Sum
m
ary
@AurBroszniowski @ljacomet#Caching101
Cache through conclusions
• Requires different abstraction / modelling
• Viewing the system of record through the cache may not be easy
• Provides better guarantees and consistency as invalidation is no longer
required
• Outside of external system of record modifications
• Cost of writing is paid by application thread putting in the cache
@AurBroszniowski @ljacomet#Caching101
Application Cache
Database
queue
Write behind
@YourTwitterHandle@AurBroszniowski @ljacomet#Caching101
D
em
o
@YourTwitterHandle#DVXFR14{session hashtag} @AurBroszniowski @ljacomet#Caching101
Sum
m
ary
@AurBroszniowski @ljacomet#Caching101
Write behind conclusions
• Impacts your domain modelling
• Scales out your writes
• Can benefit from batching and coalescing
• Durability function of the queue persistence
• Idempotent operations are important in a distributed setup where
failures do happen
@AurBroszniowski @ljacomet#Caching101
Scaling
@AurBroszniowski @ljacomet#Caching101
Moving off heap
• JVMs have issues with large heaps due to garbage collection
• off heap is a nice alternative for data having a well known lifecycle
• Perfect match for cache data
• Performance hit due to required serialization in place of object
reference
@AurBroszniowski @ljacomet#Caching101
Clustering
• Cache shared between multiple machines
• Different topologies
• peer to peer
• client - server
• with or without client caching
• Consistency becomes a much harder problem
@AurBroszniowski @ljacomet#Caching101
Probabilistically Bounded Staleness
• How long for a write to be readable by all?
• How many old versions are still around?
• Depending on
• network delay
• node processing time
• .. delayed replication (i.e. batching)
@AurBroszniowski @ljacomet#Caching101
Terracotta clustering
@AurBroszniowski @ljacomet#Caching101
Terracotta consistency: strong
Cache
Terracotta
client
Terracotta
server
Terracotta
client
Terracotta
client
@AurBroszniowski @ljacomet#Caching101
Terracotta consistency: eventual
Cache
Terracotta
client
Terracotta
server
Terracotta
client
Terracotta
client
@YourTwitterHandle#DVXFR14{session hashtag} @AurBroszniowski @ljacomet#Caching101
Sum
m
ary
@AurBroszniowski @ljacomet#Caching101
Conclusion
• You know it all now!
• Understand your needs and what caching could bring
• Consider it early on
• Patterns and topologies can have an impact
@YourTwitterHandle#DVXFR14{session hashtag} @AurBroszniowski @ljacomet#Caching101
Q
&
A

More Related Content

What's hot

ActiveMQ Performance Tuning
ActiveMQ Performance TuningActiveMQ Performance Tuning
ActiveMQ Performance Tuning
Christian Posta
 
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Erik Onnen
 
Camel oneactivemq posta-final
Camel oneactivemq posta-finalCamel oneactivemq posta-final
Camel oneactivemq posta-final
Christian Posta
 

What's hot (15)

The server side story: Parallel and Asynchronous programming in .NET - ITPro...
The server side story:  Parallel and Asynchronous programming in .NET - ITPro...The server side story:  Parallel and Asynchronous programming in .NET - ITPro...
The server side story: Parallel and Asynchronous programming in .NET - ITPro...
 
Coordinating Micro-Services with Spring Cloud Contract
Coordinating Micro-Services with Spring Cloud ContractCoordinating Micro-Services with Spring Cloud Contract
Coordinating Micro-Services with Spring Cloud Contract
 
Lightening Talk - PostgreSQL Worst Practices
Lightening Talk - PostgreSQL Worst PracticesLightening Talk - PostgreSQL Worst Practices
Lightening Talk - PostgreSQL Worst Practices
 
Tuenti Release Workflow
Tuenti Release WorkflowTuenti Release Workflow
Tuenti Release Workflow
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"
 
ActiveMQ Performance Tuning
ActiveMQ Performance TuningActiveMQ Performance Tuning
ActiveMQ Performance Tuning
 
Drupal commerce performance profiling and tunning using loadstorm experiments...
Drupal commerce performance profiling and tunning using loadstorm experiments...Drupal commerce performance profiling and tunning using loadstorm experiments...
Drupal commerce performance profiling and tunning using loadstorm experiments...
 
What’s the Deal with Containers, Anyway?
What’s the Deal with Containers, Anyway?What’s the Deal with Containers, Anyway?
What’s the Deal with Containers, Anyway?
 
Kafka elastic search meetup 09242018
Kafka elastic search meetup 09242018Kafka elastic search meetup 09242018
Kafka elastic search meetup 09242018
 
ActiveMQ 5.9.x new features
ActiveMQ 5.9.x new featuresActiveMQ 5.9.x new features
ActiveMQ 5.9.x new features
 
Сергей Калинец "Не SQL-ом единым..."
Сергей Калинец "Не SQL-ом единым..."Сергей Калинец "Не SQL-ом единым..."
Сергей Калинец "Не SQL-ом единым..."
 
GlobalsDB: Its significance for Node.js Developers
GlobalsDB: Its significance for Node.js DevelopersGlobalsDB: Its significance for Node.js Developers
GlobalsDB: Its significance for Node.js Developers
 
Should i break it?
Should i break it?Should i break it?
Should i break it?
 
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
Data Models and Consumer Idioms Using Apache Kafka for Continuous Data Stream...
 
Camel oneactivemq posta-final
Camel oneactivemq posta-finalCamel oneactivemq posta-final
Camel oneactivemq posta-final
 

Similar to Caching 101: Caching on the JVM (and beyond)

The Economies of Scaling Software
The Economies of Scaling SoftwareThe Economies of Scaling Software
The Economies of Scaling Software
Abdelmonaim Remani
 
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling SoftwareJAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
jazoon13
 
The economies of scaling software - Abdel Remani
The economies of scaling software - Abdel RemaniThe economies of scaling software - Abdel Remani
The economies of scaling software - Abdel Remani
jaxconf
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
DATAVERSITY
 
Oracle Systems _ Nathan Kroenert _ New Software New Hardware.pdf
Oracle Systems _ Nathan Kroenert _ New Software New Hardware.pdfOracle Systems _ Nathan Kroenert _ New Software New Hardware.pdf
Oracle Systems _ Nathan Kroenert _ New Software New Hardware.pdf
InSync2011
 

Similar to Caching 101: Caching on the JVM (and beyond) (20)

Caching 101: sur la JVM et au delà
Caching 101: sur la JVM et au delàCaching 101: sur la JVM et au delà
Caching 101: sur la JVM et au delà
 
Ehcache 3: JSR-107 on steroids at Devoxx Morocco
Ehcache 3: JSR-107 on steroids at Devoxx MoroccoEhcache 3: JSR-107 on steroids at Devoxx Morocco
Ehcache 3: JSR-107 on steroids at Devoxx Morocco
 
Caching 101: Caching on the JVM (and beyond)
Caching 101: Caching on the JVM (and beyond)Caching 101: Caching on the JVM (and beyond)
Caching 101: Caching on the JVM (and beyond)
 
The Economies of Scaling Software
The Economies of Scaling SoftwareThe Economies of Scaling Software
The Economies of Scaling Software
 
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling SoftwareJAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
 
Caching reboot: javax.cache & Ehcache 3
Caching reboot: javax.cache & Ehcache 3Caching reboot: javax.cache & Ehcache 3
Caching reboot: javax.cache & Ehcache 3
 
The economies of scaling software - Abdel Remani
The economies of scaling software - Abdel RemaniThe economies of scaling software - Abdel Remani
The economies of scaling software - Abdel Remani
 
Introduction to Micronaut - JBCNConf 2019
Introduction to Micronaut - JBCNConf 2019Introduction to Micronaut - JBCNConf 2019
Introduction to Micronaut - JBCNConf 2019
 
Pune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCDPune-Cocoa: Blocks and GCD
Pune-Cocoa: Blocks and GCD
 
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
A Case Study of NoSQL Adoption: What Drove Wordnik Non-Relational?
 
Eclipse Enterprise Content Repository (ECR)
Eclipse Enterprise Content Repository (ECR)Eclipse Enterprise Content Repository (ECR)
Eclipse Enterprise Content Repository (ECR)
 
Token vs Cookies (DevoxxMA 2015)
Token vs Cookies (DevoxxMA 2015)Token vs Cookies (DevoxxMA 2015)
Token vs Cookies (DevoxxMA 2015)
 
Have I Been Pwned and Cloudflare
Have I Been Pwned and CloudflareHave I Been Pwned and Cloudflare
Have I Been Pwned and Cloudflare
 
Latest (storage IO) patterns for cloud-native applications
Latest (storage IO) patterns for cloud-native applications Latest (storage IO) patterns for cloud-native applications
Latest (storage IO) patterns for cloud-native applications
 
Oracle Systems _ Nathan Kroenert _ New Software New Hardware.pdf
Oracle Systems _ Nathan Kroenert _ New Software New Hardware.pdfOracle Systems _ Nathan Kroenert _ New Software New Hardware.pdf
Oracle Systems _ Nathan Kroenert _ New Software New Hardware.pdf
 
Machine Learning With H2O vs SparkML
Machine Learning With H2O vs SparkMLMachine Learning With H2O vs SparkML
Machine Learning With H2O vs SparkML
 
Data consistency: Analyse, understand and decide
Data consistency: Analyse, understand and decideData consistency: Analyse, understand and decide
Data consistency: Analyse, understand and decide
 
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-Sensitive Queries for Presto at Facebook: A Collaboration ...
 
Security with VA Smalltalk
Security with VA SmalltalkSecurity with VA Smalltalk
Security with VA Smalltalk
 
Real time analytics using Hadoop and Elasticsearch
Real time analytics using Hadoop and ElasticsearchReal time analytics using Hadoop and Elasticsearch
Real time analytics using Hadoop and Elasticsearch
 

Recently uploaded

JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
Max Lee
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 

Recently uploaded (20)

COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
 
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityAPVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
KLARNA -  Language Models and Knowledge Graphs: A Systems ApproachKLARNA -  Language Models and Knowledge Graphs: A Systems Approach
KLARNA - Language Models and Knowledge Graphs: A Systems Approach
 
How to pick right visual testing tool.pdf
How to pick right visual testing tool.pdfHow to pick right visual testing tool.pdf
How to pick right visual testing tool.pdf
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
 
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
 

Caching 101: Caching on the JVM (and beyond)