SlideShare une entreprise Scribd logo
1  sur  49
Télécharger pour lire hors ligne
@ljacomet#Caching101
Caching 101: on the JVM and beyond
Louis Jacomet
@ljacomet
Software AG / Terracotta
ehcache.org
#Caching101
@ljacomet
Agenda
• Caching theory
• Caching in Java
• Caching patterns
• Scaling
#Caching101
@ljacomet
Who am I?
• 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
#Caching101
@ljacomet
Who are you?
• Who knows nothing about caching?
• Who already uses caching in production?
• Who had caching related problems in production?
• Ehcache anyone?
#Caching101
@ljacomet
There are only two hard things in
Computer Science: 

cache invalidation and naming things.
-- Phil Karlton
#Caching101
@ljacomet
Caching theory
#Caching101
@ljacomet
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
#Caching101
@ljacomet
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
#Caching101
@ljacomet
The long tail
• Coined by Chris Anderson
• Application of a Power Law probability distribution
• Pareto Law or 80:20 rule
#Caching101
@ljacomet
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
#Caching101
@ljacomet
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
#Caching101
@ljacomet
Amdhal’s law
• Parallelisation
• P: parallel proportion
• N: processor count
#Caching101
@ljacomet
Amdhal’s law
• Sequential
• p: times a part was sped up
• f: fraction of time improved
#Caching101
@ljacomet
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
#Caching101
@ljacomet
Desired cache features
• Capacity control / eviction
• Data freshness / expiry
• Data consistency / invalidation
• Fault tolerant
#Caching101
@ljacomet
Caching in Java
#Caching101
@ljacomet
Google
Guava
And more …
BlazingCache
#Caching101
@ljacomet
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
#Caching101
@ljacomet
javax.cache features
• CacheManager managing … Cache!
• Expiry
• Integration (CacheLoader and CacheWriter)
• Cache listeners
• Entry processors
• Annotations
• Statistics and MBeans
#Caching101
@ljacomet
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
#Caching101
@ljacomet
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???
#Caching101
@ljacomet
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
#Caching101
@ljacomet
Caching patterns
#Caching101
@ljacomet
Cache aside (miss)
Application
Cache
Database
#Caching101
@ljacomet
Cache aside (hit)
Application
Cache
Database
#Caching101
@ljacomet
D
em
o
#Caching101
@ljacomet
Hibernate 2nd level cache
• Stores dehydrated entities
• 4 strategies
• ReadOnly
• NonStrictReadWrite
• ReadWrite
• Transactional
#Caching101
@ljacomet
Sum
m
ary
#Caching101
@ljacomet
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
#Caching101
@ljacomet
Cache through (miss)
Application Cache
Database
#Caching101
@ljacomet
Cache through (hit)
Application Cache
Database
#Caching101
@ljacomet
Cache through (write)
Application Cache
Database
#Caching101
@ljacomet
D
em
o
#Caching101
@ljacomet
Sum
m
ary
#Caching101
@ljacomet
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
#Caching101
@ljacomet
Application Cache
Database
queue
Write behind
#Caching101
@ljacomet
D
em
o
#Caching101
@ljacomet
Sum
m
ary
#Caching101
@ljacomet
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
#Caching101
@ljacomet
Scaling
#Caching101
@ljacomet
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
#Caching101
@ljacomet
Clustering
• Cache shared between multiple machines
• Different topologies
• peer to peer
• client - server
• with or without client caching
• Consistency becomes a much harder problem
#Caching101
@ljacomet
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)
#Caching101
@ljacomet
Terracotta clustering
#Caching101
@ljacomet
Terracotta consistency: strong
Cache
Terracotta
client
Terracotta
server
Terracotta
client
Terracotta
client
#Caching101
@ljacomet
Terracotta consistency: eventual
Cache
Terracotta
client
Terracotta
server
Terracotta
client
Terracotta
client
#Caching101
@ljacomet
Sum
m
ary
#Caching101
@ljacomet
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
#Caching101
@ljacomet
Q
&
A

Contenu connexe

Tendances

Testing at-cloud-speed sans-app-sec-austin-2013
Testing at-cloud-speed sans-app-sec-austin-2013Testing at-cloud-speed sans-app-sec-austin-2013
Testing at-cloud-speed sans-app-sec-austin-2013
Matt Tesauro
 
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
Legacy Typesafe (now Lightbend)
 
Building High-Throughput, Low-Latency Pipelines in Kafka
Building High-Throughput, Low-Latency Pipelines in KafkaBuilding High-Throughput, Low-Latency Pipelines in Kafka
Building High-Throughput, Low-Latency Pipelines in Kafka
confluent
 

Tendances (20)

Aljoscha Krettek - The Future of Apache Flink
Aljoscha Krettek - The Future of Apache FlinkAljoscha Krettek - The Future of Apache Flink
Aljoscha Krettek - The Future of Apache Flink
 
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and more
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and moreTypesafe Reactive Platform: Monitoring 1.0, Commercial features and more
Typesafe Reactive Platform: Monitoring 1.0, Commercial features and more
 
Counting Elements in Streams
Counting Elements in StreamsCounting Elements in Streams
Counting Elements in Streams
 
Flink 1.0-slides
Flink 1.0-slidesFlink 1.0-slides
Flink 1.0-slides
 
Stream Processing with Apache Flink
Stream Processing with Apache FlinkStream Processing with Apache Flink
Stream Processing with Apache Flink
 
Legacy Sins
Legacy SinsLegacy Sins
Legacy Sins
 
Testing at-cloud-speed sans-app-sec-austin-2013
Testing at-cloud-speed sans-app-sec-austin-2013Testing at-cloud-speed sans-app-sec-austin-2013
Testing at-cloud-speed sans-app-sec-austin-2013
 
The Good, The Bad, and The Avro (Graham Stirling, Saxo Bank and David Navalho...
The Good, The Bad, and The Avro (Graham Stirling, Saxo Bank and David Navalho...The Good, The Bad, and The Avro (Graham Stirling, Saxo Bank and David Navalho...
The Good, The Bad, and The Avro (Graham Stirling, Saxo Bank and David Navalho...
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Big Data Warsaw
Big Data WarsawBig Data Warsaw
Big Data Warsaw
 
Apache Flink Hands On
Apache Flink Hands OnApache Flink Hands On
Apache Flink Hands On
 
Reliability Guarantees for Apache Kafka
Reliability Guarantees for Apache KafkaReliability Guarantees for Apache Kafka
Reliability Guarantees for Apache Kafka
 
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
 
Westpac Bank Tech Talk 1: Dive into Apache Kafka
Westpac Bank Tech Talk 1: Dive into Apache KafkaWestpac Bank Tech Talk 1: Dive into Apache Kafka
Westpac Bank Tech Talk 1: Dive into Apache Kafka
 
Heroku
HerokuHeroku
Heroku
 
Building High-Throughput, Low-Latency Pipelines in Kafka
Building High-Throughput, Low-Latency Pipelines in KafkaBuilding High-Throughput, Low-Latency Pipelines in Kafka
Building High-Throughput, Low-Latency Pipelines in Kafka
 
Kostas Tzoumas_Stephan Ewen - Keynote -The maturing data streaming ecosystem ...
Kostas Tzoumas_Stephan Ewen - Keynote -The maturing data streaming ecosystem ...Kostas Tzoumas_Stephan Ewen - Keynote -The maturing data streaming ecosystem ...
Kostas Tzoumas_Stephan Ewen - Keynote -The maturing data streaming ecosystem ...
 
ELK Stack
ELK StackELK Stack
ELK Stack
 
High Availability and Scalability: Too Expensive! Architectures for Future E...
High Availability and Scalability: Too Expensive! Architectures for Future E...High Availability and Scalability: Too Expensive! Architectures for Future E...
High Availability and Scalability: Too Expensive! Architectures for Future E...
 
Declarative benchmarking of cassandra and it's data models
Declarative benchmarking of cassandra and it's data modelsDeclarative benchmarking of cassandra and it's data models
Declarative benchmarking of cassandra and it's data models
 

Similaire à Caching 101: sur la JVM et au delà

Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010
Jason Ragsdale
 
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
 
The Data Mullet: From all SQL to No SQL back to Some SQL
The Data Mullet: From all SQL to No SQL back to Some SQLThe Data Mullet: From all SQL to No SQL back to Some SQL
The Data Mullet: From all SQL to No SQL back to Some SQL
Datadog
 

Similaire à Caching 101: sur la JVM et au delà (20)

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)
 
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)
 
Ehcache 3 @ BruJUG
Ehcache 3 @ BruJUGEhcache 3 @ BruJUG
Ehcache 3 @ BruJUG
 
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
 
Where Django Caching Bust at the Seams
Where Django Caching Bust at the SeamsWhere Django Caching Bust at the Seams
Where Django Caching Bust at the Seams
 
Caching reboot: javax.cache & Ehcache 3
Caching reboot: javax.cache & Ehcache 3Caching reboot: javax.cache & Ehcache 3
Caching reboot: javax.cache & Ehcache 3
 
Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010Caching: A Guided Tour - 10/12/2010
Caching: A Guided Tour - 10/12/2010
 
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?
 
The Data Mullet: From all SQL to No SQL back to Some SQL
The Data Mullet: From all SQL to No SQL back to Some SQLThe Data Mullet: From all SQL to No SQL back to Some SQL
The Data Mullet: From all SQL to No SQL back to Some SQL
 
Caching in applications still matters
Caching in applications still mattersCaching in applications still matters
Caching in applications still matters
 
Leveraging Databricks for Spark Pipelines
Leveraging Databricks for Spark PipelinesLeveraging Databricks for Spark Pipelines
Leveraging Databricks for Spark Pipelines
 
Leveraging Databricks for Spark pipelines
Leveraging Databricks for Spark pipelinesLeveraging Databricks for Spark pipelines
Leveraging Databricks for Spark pipelines
 
Openstack meetup lyon_2017-09-28
Openstack meetup lyon_2017-09-28Openstack meetup lyon_2017-09-28
Openstack meetup lyon_2017-09-28
 
Using the big guns: Advanced OS performance tools for troubleshooting databas...
Using the big guns: Advanced OS performance tools for troubleshooting databas...Using the big guns: Advanced OS performance tools for troubleshooting databas...
Using the big guns: Advanced OS performance tools for troubleshooting databas...
 
Data consistency: Analyse, understand and decide
Data consistency: Analyse, understand and decideData consistency: Analyse, understand and decide
Data consistency: Analyse, understand and decide
 
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
 
JEEConf 2019 | Let’s build a Java backend designed for a high load
JEEConf 2019 | Let’s build a Java backend designed for a high loadJEEConf 2019 | Let’s build a Java backend designed for a high load
JEEConf 2019 | Let’s build a Java backend designed for a high load
 
From Concept to Clustered JAC (jira.atlassian.com) - Graham Carrick
From Concept to Clustered JAC (jira.atlassian.com) - Graham CarrickFrom Concept to Clustered JAC (jira.atlassian.com) - Graham Carrick
From Concept to Clustered JAC (jira.atlassian.com) - Graham Carrick
 
Fixing twitter
Fixing twitterFixing twitter
Fixing twitter
 
Fixing_Twitter
Fixing_TwitterFixing_Twitter
Fixing_Twitter
 

Dernier

Dernier (20)

SQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionSQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
 
Naer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research SynthesisNaer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research Synthesis
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
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
 
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
 
The Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion ProductionThe Impact of PLM Software on Fashion Production
The Impact of PLM Software on Fashion Production
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
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
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
Malaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptxMalaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptx
 
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
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
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
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 

Caching 101: sur la JVM et au delà