SlideShare a Scribd company logo
1 of 41
Download to read offline
Cold Hard Cache
    Alex Miller (@puredanger)
Agenda

• Why cache?


• Ehcache


• Hibernate 2nd level cache


• Terracotta


• The future....
Why cache?

• Temporal locality


• Non-uniform distribution
Temporal locality




Items:
Temporal locality


Cache:

Items:
Temporal locality

Hits:               0%
Cache:

Items:
Temporal locality

Hits:               0%
Cache:

Items:

Items:
Temporal locality

Hits:               0%
Cache:

Items:

Items:

Cache:
Temporal locality

Hits:               0%
Cache:

Items:

Items:

Cache:
Hits:               65%
Non-uniform distribution
              Web page hits, ordered by rank
      3200                                       100%




      2400                                       75%




      1600                                       50%




       800                                       25%




        0                                         0%
                   Page views, ordered by rank


                    Pageviews per rank
                    % of total hits per rank
Non-uniform distribution
              Web page hits, ordered by rank
      3200                                       100%




      2400                                       75%




      1600                                       50%




       800                                       25%




        0                                         0%
                   Page views, ordered by rank


                    Pageviews per rank
                    % of total hits per rank
Cache is always good right?

• Watch out for:


   • Amdahl’s law


   • Memory


   • Concurrency


   • Copy cost
Reduce latency

            Page build   Data retrieval

  2000


  1500


  1000


   500


     0
            No cache          With cache
Database offload




Operations
Per Second




                  Amount of Data
DBs are sized to peak load




Operations
Per Second




                         Amount of Data
Strive to downsize DBs



                   Frequently accessed app data:
                   Shared Memory (Transactional)

Operations
Per Second

                              Business Record Data : Database




                           Amount of Data
Ehcache
Ehcache history

• First created in 2003 by Greg Luck


• Most widely used Java cache - 100k’s of deployments


• Apache 2.0 license


• JSR 107 Java cache implementation
Ehcache Architecture
Ehcache Features

• In-memory and spill-to-disk storage


• Cache bootstrap loaders


• Cache replication via listener API - RMI, JGroups, JMS


• Cache server with REST and SOAP APIs


• Servlet caching filter API


• Hibernate second-level cache support
Ehcache 1.6 performance
Ehcache Performance vs memcached
Hibernate Second-Level Cache
Hibernate Caching


                      Application Thread            Application Thread



                           Session                      Session          1st Level Cache


                        Cache           Cache               Cache
                      Concurrency     Concurrency         Concurrency
          Hibernate




                       Strategy        Strategy            Strategy

                                     CacheProvider                       2nd Level Cache


                        Cache              Cache             Cache
                        Region             Region            Region



                                       Database
Entity and collection caches

• Entity and collection cache regions


• Mark a Hibernate entity or a collection in an entity as @Cacheable


• Specify a cache concurrency strategy


   • ReadOnly, ReadWrite, NonstrictReadWrite, Transactional


• Turn on second level caching in the Hibernate config
Query Cache

• Query cache regions


   • Mark HQL, Criteria, Query as cacheable


   • Store result set id values


• Timestamp cache region - last update time for each entity type


• Useful for caching natural key lookups (non-primary key)


• ...but lots of hidden issues
Terracotta as cache
DistributedCache

• High-throughput clustered coherent cache


• Simple interface - basically ConcurrentMap


• Eviction options


   • TTI, TTL


   • Max in-memory size, max total size limits
DistributedCache Example

 CacheConfig config = CacheConfigFactory.newConfig();
 config.setMaxTTISeconds(30 * 60)
       .setMaxTTLSeconds(2 * 60 * 60);

 DistributedCache<String, Person> cache = config.newCache();


 Person person = new Person(.......);
 cache.put(“Alex”, person);

 Person cached = cache.get(“Alex”);
DistributedCache features

• Built on high throughput ConcurrentDistributedMap


• Expiration based on either TTI or TTL


• Both in-memory and total target max limits


• Automatic memory management of caches


• Coherent clustered cache
Terracotta Hibernate Second Level Cache

 • Easy integration and configuration


 • Supports entity, collection, and query cache regions


 • Supports read-only, read-write, and nonstrict-read-write cache
   concurrency strategies


 • Hibernate-specific tooling


 • High performance with cache coherency
Enabling Second Level Cache

• Mark your entities with a cache concurrency strategy


  • In hibernate.cfg.xml:   <cache usage="read-write"/>



  • With annotations:       @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)



• hibernate.cfg.xml

  • <property name="cache.use_second_level_cache">true</property>



  • <property name="cache.provider_class">
    org.terracotta.hibernate.TerracottaHibernateCacheProvider</property>
Enabling Second Level Cache
• Define the tc-hibernate-cache.xml in your classpath

<?xml version=”1.0” encoding=”UTF-8”?>
<terracotta-hibernate-cache-configuration>
  <default-configuration>
    <time-to-idle-seconds>7200</time-to-idle-seconds>
    <time-to-live-seconds>7200</time-to-live-seconds>
  </default-configuration>

  <cache>
    <region-name>org.terracotta.authinator.domain.Account</region-name>
    <!-- as many region-names here as you want -->
	     <configuration>
      <time-to-idle-seconds>600</time-to-idle-seconds>
      <time-to-live-seconds>600</time-to-live-seconds>
    </configuration>
  </cache>
</terracotta-hibernate-cache-configuration>




• Add the Terracotta Hibernate cache provider jar to your classpath


     • -cp terracotta-hibernate-cache-1.0.0.jar


• Add the Terracotta Hibernate cache agent jar to your command line


     • -javaagent:terracotta-hibernate-agent-1.0.0.jar
New Hibernate cache visibility
Performance - Read-Only Comparison


                                           Throughput                                                    Latency
                          200K                                                          100
Transactions per second




                                                                                        80
                          150K




                                                                     Avg Latency (ms)
                                                                                        60
                          100K
                                                                                        40

                          50K
                                                                                        20

                           0K                                                            0
                                 Database IMDG   EhcacheTerracotta                            Database IMDG   EhcacheTerracotta
The future of caching...
Wonder twin powers, activate!



      Terracotta                                          Ehcache




• “Standard” cache apis (Ehcache / JSR 107)
• Low latency local cache
• High throughput clustered cache
  • Coherent caching with options to degrade for greater performance
  • Support for both “copy” and “shared object” caching
Single node and replicated Ehcache

• Same license, code base, and API


• Better visibility


• Better performance testing -> improved concurrency and performance


• Smooth migration path to...
Clustered Ehcache

• Short release for initial integration (probably Ehcache 1.7)


   • Clustered store - partial API support


   • Smooth upgrade from single node or replicated Ehcache


   • New management and visibility features
Hibernate 2nd level cache

• More efficient in-memory and total count eviction (3.1.1)


• Better visibility of memory conditions


• Improved query caching


• Improved performance of core Terracotta (lock manager and memory
  manager)
Thanks!

• Terracotta Open Source JVM clustering:

   • http://www.terracotta.org

• Apress: “The Definitive Guide to Terracotta”

   • by Ari Zilka, Alex Miller, Geert Bevin, Jonas
     Boner, Orion Letizi, Taylor Gautier

   • 2nd edition in progress....

• Alex Miller

   • @puredanger

   • http://tech.puredanger.com

More Related Content

What's hot

DZone Java 8 Block Buster: Query Databases Using Streams
DZone Java 8 Block Buster: Query Databases Using StreamsDZone Java 8 Block Buster: Query Databases Using Streams
DZone Java 8 Block Buster: Query Databases Using StreamsSpeedment, Inc.
 
Introduction to .Net Driver
Introduction to .Net DriverIntroduction to .Net Driver
Introduction to .Net DriverDataStax Academy
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeperknowbigdata
 
Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019
 Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019 Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019
Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019Vlad Mihalcea
 
Advanced Apache Cassandra Operations with JMX
Advanced Apache Cassandra Operations with JMXAdvanced Apache Cassandra Operations with JMX
Advanced Apache Cassandra Operations with JMXzznate
 
인피니스팬데이터그리드따라잡기 (@JCO 2014)
인피니스팬데이터그리드따라잡기 (@JCO 2014)인피니스팬데이터그리드따라잡기 (@JCO 2014)
인피니스팬데이터그리드따라잡기 (@JCO 2014)Jaehong Cheon
 
Advanced Oracle Troubleshooting
Advanced Oracle TroubleshootingAdvanced Oracle Troubleshooting
Advanced Oracle TroubleshootingHector Martinez
 
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...DataStax
 
Virtualizing Java in Java (jug.ru)
Virtualizing Java in Java (jug.ru)Virtualizing Java in Java (jug.ru)
Virtualizing Java in Java (jug.ru)aragozin
 
Spark / Mesos Cluster Optimization
Spark / Mesos Cluster OptimizationSpark / Mesos Cluster Optimization
Spark / Mesos Cluster Optimizationebiznext
 
A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...
A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...
A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...DataStax
 
Cassandra Community Webinar: Apache Cassandra Internals
Cassandra Community Webinar: Apache Cassandra InternalsCassandra Community Webinar: Apache Cassandra Internals
Cassandra Community Webinar: Apache Cassandra InternalsDataStax
 
DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...
DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...
DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...DataStax
 
M6d cassandrapresentation
M6d cassandrapresentationM6d cassandrapresentation
M6d cassandrapresentationEdward Capriolo
 
Everyday I’m scaling... Cassandra
Everyday I’m scaling... CassandraEveryday I’m scaling... Cassandra
Everyday I’m scaling... CassandraInstaclustr
 
Optimizing Your Cluster with Coordinator Nodes (Eric Lubow, SimpleReach) | Ca...
Optimizing Your Cluster with Coordinator Nodes (Eric Lubow, SimpleReach) | Ca...Optimizing Your Cluster with Coordinator Nodes (Eric Lubow, SimpleReach) | Ca...
Optimizing Your Cluster with Coordinator Nodes (Eric Lubow, SimpleReach) | Ca...DataStax
 
The Best and Worst of Cassandra-stress Tool (Christopher Batey, The Last Pick...
The Best and Worst of Cassandra-stress Tool (Christopher Batey, The Last Pick...The Best and Worst of Cassandra-stress Tool (Christopher Batey, The Last Pick...
The Best and Worst of Cassandra-stress Tool (Christopher Batey, The Last Pick...DataStax
 
Bulk Loading Data into Cassandra
Bulk Loading Data into CassandraBulk Loading Data into Cassandra
Bulk Loading Data into CassandraDataStax
 

What's hot (20)

DZone Java 8 Block Buster: Query Databases Using Streams
DZone Java 8 Block Buster: Query Databases Using StreamsDZone Java 8 Block Buster: Query Databases Using Streams
DZone Java 8 Block Buster: Query Databases Using Streams
 
JahiaOne - Performance Tuning
JahiaOne - Performance TuningJahiaOne - Performance Tuning
JahiaOne - Performance Tuning
 
Hazelcast
HazelcastHazelcast
Hazelcast
 
Introduction to .Net Driver
Introduction to .Net DriverIntroduction to .Net Driver
Introduction to .Net Driver
 
Introduction to Apache ZooKeeper
Introduction to Apache ZooKeeperIntroduction to Apache ZooKeeper
Introduction to Apache ZooKeeper
 
Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019
 Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019 Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019
Awesome SQL Tips and Tricks - Voxxed Days Cluj - 2019
 
Advanced Apache Cassandra Operations with JMX
Advanced Apache Cassandra Operations with JMXAdvanced Apache Cassandra Operations with JMX
Advanced Apache Cassandra Operations with JMX
 
인피니스팬데이터그리드따라잡기 (@JCO 2014)
인피니스팬데이터그리드따라잡기 (@JCO 2014)인피니스팬데이터그리드따라잡기 (@JCO 2014)
인피니스팬데이터그리드따라잡기 (@JCO 2014)
 
Advanced Oracle Troubleshooting
Advanced Oracle TroubleshootingAdvanced Oracle Troubleshooting
Advanced Oracle Troubleshooting
 
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
Micro-batching: High-performance Writes (Adam Zegelin, Instaclustr) | Cassand...
 
Virtualizing Java in Java (jug.ru)
Virtualizing Java in Java (jug.ru)Virtualizing Java in Java (jug.ru)
Virtualizing Java in Java (jug.ru)
 
Spark / Mesos Cluster Optimization
Spark / Mesos Cluster OptimizationSpark / Mesos Cluster Optimization
Spark / Mesos Cluster Optimization
 
A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...
A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...
A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...
 
Cassandra Community Webinar: Apache Cassandra Internals
Cassandra Community Webinar: Apache Cassandra InternalsCassandra Community Webinar: Apache Cassandra Internals
Cassandra Community Webinar: Apache Cassandra Internals
 
DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...
DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...
DataStax | Best Practices for Securing DataStax Enterprise (Matt Kennedy) | C...
 
M6d cassandrapresentation
M6d cassandrapresentationM6d cassandrapresentation
M6d cassandrapresentation
 
Everyday I’m scaling... Cassandra
Everyday I’m scaling... CassandraEveryday I’m scaling... Cassandra
Everyday I’m scaling... Cassandra
 
Optimizing Your Cluster with Coordinator Nodes (Eric Lubow, SimpleReach) | Ca...
Optimizing Your Cluster with Coordinator Nodes (Eric Lubow, SimpleReach) | Ca...Optimizing Your Cluster with Coordinator Nodes (Eric Lubow, SimpleReach) | Ca...
Optimizing Your Cluster with Coordinator Nodes (Eric Lubow, SimpleReach) | Ca...
 
The Best and Worst of Cassandra-stress Tool (Christopher Batey, The Last Pick...
The Best and Worst of Cassandra-stress Tool (Christopher Batey, The Last Pick...The Best and Worst of Cassandra-stress Tool (Christopher Batey, The Last Pick...
The Best and Worst of Cassandra-stress Tool (Christopher Batey, The Last Pick...
 
Bulk Loading Data into Cassandra
Bulk Loading Data into CassandraBulk Loading Data into Cassandra
Bulk Loading Data into Cassandra
 

Viewers also liked

Innovative Software
Innovative SoftwareInnovative Software
Innovative SoftwareAlex Miller
 
Releasing Relational Data to the Semantic Web
Releasing Relational Data to the Semantic WebReleasing Relational Data to the Semantic Web
Releasing Relational Data to the Semantic WebAlex Miller
 
Stream Execution with Clojure and Fork/join
Stream Execution with Clojure and Fork/joinStream Execution with Clojure and Fork/join
Stream Execution with Clojure and Fork/joinAlex Miller
 
Project Fortress
Project FortressProject Fortress
Project FortressAlex Miller
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 
Cracking clojure
Cracking clojureCracking clojure
Cracking clojureAlex Miller
 
Clojure: The Art of Abstraction
Clojure: The Art of AbstractionClojure: The Art of Abstraction
Clojure: The Art of AbstractionAlex Miller
 
Visualising Data on Interactive Maps
Visualising Data on Interactive MapsVisualising Data on Interactive Maps
Visualising Data on Interactive MapsAnna Pawlicka
 
The new ehcache 2.0 and hibernate spi
The new ehcache 2.0 and hibernate spiThe new ehcache 2.0 and hibernate spi
The new ehcache 2.0 and hibernate spiCyril Lakech
 
Tree Editing with Zippers
Tree Editing with ZippersTree Editing with Zippers
Tree Editing with ZippersAlex Miller
 
Concurrent Stream Processing
Concurrent Stream ProcessingConcurrent Stream Processing
Concurrent Stream ProcessingAlex Miller
 
Strange Loop Conference 2009
Strange Loop Conference 2009Strange Loop Conference 2009
Strange Loop Conference 2009Alex Miller
 
Clojure/West Overview (12/1/11)
Clojure/West Overview (12/1/11)Clojure/West Overview (12/1/11)
Clojure/West Overview (12/1/11)Alex Miller
 
Scaling Your Cache And Caching At Scale
Scaling Your Cache And Caching At ScaleScaling Your Cache And Caching At Scale
Scaling Your Cache And Caching At ScaleAlex Miller
 
Collections In Java
Collections In JavaCollections In Java
Collections In JavaBinoj T E
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in javaCPD INDIA
 
Marshmallow Test
Marshmallow TestMarshmallow Test
Marshmallow TestAlex Miller
 

Viewers also liked (20)

Blogging ZOMG
Blogging ZOMGBlogging ZOMG
Blogging ZOMG
 
Innovative Software
Innovative SoftwareInnovative Software
Innovative Software
 
Releasing Relational Data to the Semantic Web
Releasing Relational Data to the Semantic WebReleasing Relational Data to the Semantic Web
Releasing Relational Data to the Semantic Web
 
Stream Execution with Clojure and Fork/join
Stream Execution with Clojure and Fork/joinStream Execution with Clojure and Fork/join
Stream Execution with Clojure and Fork/join
 
Project Fortress
Project FortressProject Fortress
Project Fortress
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 
Cracking clojure
Cracking clojureCracking clojure
Cracking clojure
 
Clojure: The Art of Abstraction
Clojure: The Art of AbstractionClojure: The Art of Abstraction
Clojure: The Art of Abstraction
 
Visualising Data on Interactive Maps
Visualising Data on Interactive MapsVisualising Data on Interactive Maps
Visualising Data on Interactive Maps
 
The new ehcache 2.0 and hibernate spi
The new ehcache 2.0 and hibernate spiThe new ehcache 2.0 and hibernate spi
The new ehcache 2.0 and hibernate spi
 
Tree Editing with Zippers
Tree Editing with ZippersTree Editing with Zippers
Tree Editing with Zippers
 
Concurrent Stream Processing
Concurrent Stream ProcessingConcurrent Stream Processing
Concurrent Stream Processing
 
Strange Loop Conference 2009
Strange Loop Conference 2009Strange Loop Conference 2009
Strange Loop Conference 2009
 
Clojure/West Overview (12/1/11)
Clojure/West Overview (12/1/11)Clojure/West Overview (12/1/11)
Clojure/West Overview (12/1/11)
 
Java collection
Java collectionJava collection
Java collection
 
Scaling Your Cache And Caching At Scale
Scaling Your Cache And Caching At ScaleScaling Your Cache And Caching At Scale
Scaling Your Cache And Caching At Scale
 
07 java collection
07 java collection07 java collection
07 java collection
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Marshmallow Test
Marshmallow TestMarshmallow Test
Marshmallow Test
 

Similar to Cold Hard Cache

Betting On Data Grids
Betting On Data GridsBetting On Data Grids
Betting On Data Gridsgojkoadzic
 
Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyLeif Hedstrom
 
PHP Performance with APC + Memcached
PHP Performance with APC + MemcachedPHP Performance with APC + Memcached
PHP Performance with APC + MemcachedFord AntiTrust
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & ScalabilityJoseph Scott
 
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...Flink Forward
 
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...srisatish ambati
 
Lightweight Grids With Terracotta
Lightweight Grids With TerracottaLightweight Grids With Terracotta
Lightweight Grids With TerracottaPT.JUG
 
Oracle no sql overview brief
Oracle no sql overview briefOracle no sql overview brief
Oracle no sql overview briefInfiniteGraph
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - DeploymentFabio Akita
 
Varnish, The Good, The Awesome, and the Downright Crazy
Varnish, The Good, The Awesome, and the Downright CrazyVarnish, The Good, The Awesome, and the Downright Crazy
Varnish, The Good, The Awesome, and the Downright CrazyMike Willbanks
 
Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.Mike Willbanks
 
Varnish Cache - International PHP Conference Fall 2012
Varnish Cache - International PHP Conference Fall 2012Varnish Cache - International PHP Conference Fall 2012
Varnish Cache - International PHP Conference Fall 2012Mike Willbanks
 
Cache is King: Get the Most Bang for Your Buck From Ruby
Cache is King: Get the Most Bang for Your Buck From RubyCache is King: Get the Most Bang for Your Buck From Ruby
Cache is King: Get the Most Bang for Your Buck From RubyMolly Struve
 
High Performance Cloud Computing
High Performance Cloud ComputingHigh Performance Cloud Computing
High Performance Cloud ComputingAmazon Web Services
 
High Performance Cloud Computing
High Performance Cloud ComputingHigh Performance Cloud Computing
High Performance Cloud ComputingAmazon Web Services
 
Chemical Database Management J Chem Base And J Chem Cartridge: US UGM 2008
Chemical Database Management J Chem Base And J Chem Cartridge: US UGM 2008Chemical Database Management J Chem Base And J Chem Cartridge: US UGM 2008
Chemical Database Management J Chem Base And J Chem Cartridge: US UGM 2008ChemAxon
 

Similar to Cold Hard Cache (20)

Betting On Data Grids
Betting On Data GridsBetting On Data Grids
Betting On Data Grids
 
Usenix lisa 2011
Usenix lisa 2011Usenix lisa 2011
Usenix lisa 2011
 
Apache con 2011 gd
Apache con 2011 gdApache con 2011 gd
Apache con 2011 gd
 
Netcf Gc
Netcf GcNetcf Gc
Netcf Gc
 
Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a Proxy
 
PHP Performance with APC + Memcached
PHP Performance with APC + MemcachedPHP Performance with APC + Memcached
PHP Performance with APC + Memcached
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & Scalability
 
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
 
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
Cache is King ( Or How To Stop Worrying And Start Caching in Java) at Chicago...
 
Lightweight Grids With Terracotta
Lightweight Grids With TerracottaLightweight Grids With Terracotta
Lightweight Grids With Terracotta
 
Oracle no sql overview brief
Oracle no sql overview briefOracle no sql overview brief
Oracle no sql overview brief
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - Deployment
 
Varnish, The Good, The Awesome, and the Downright Crazy
Varnish, The Good, The Awesome, and the Downright CrazyVarnish, The Good, The Awesome, and the Downright Crazy
Varnish, The Good, The Awesome, and the Downright Crazy
 
Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.
 
Varnish Cache
Varnish CacheVarnish Cache
Varnish Cache
 
Varnish Cache - International PHP Conference Fall 2012
Varnish Cache - International PHP Conference Fall 2012Varnish Cache - International PHP Conference Fall 2012
Varnish Cache - International PHP Conference Fall 2012
 
Cache is King: Get the Most Bang for Your Buck From Ruby
Cache is King: Get the Most Bang for Your Buck From RubyCache is King: Get the Most Bang for Your Buck From Ruby
Cache is King: Get the Most Bang for Your Buck From Ruby
 
High Performance Cloud Computing
High Performance Cloud ComputingHigh Performance Cloud Computing
High Performance Cloud Computing
 
High Performance Cloud Computing
High Performance Cloud ComputingHigh Performance Cloud Computing
High Performance Cloud Computing
 
Chemical Database Management J Chem Base And J Chem Cartridge: US UGM 2008
Chemical Database Management J Chem Base And J Chem Cartridge: US UGM 2008Chemical Database Management J Chem Base And J Chem Cartridge: US UGM 2008
Chemical Database Management J Chem Base And J Chem Cartridge: US UGM 2008
 

More from Alex Miller

Java Collections API
Java Collections APIJava Collections API
Java Collections APIAlex Miller
 
Java Concurrency Idioms
Java Concurrency IdiomsJava Concurrency Idioms
Java Concurrency IdiomsAlex Miller
 
Design Patterns Reconsidered
Design Patterns ReconsideredDesign Patterns Reconsidered
Design Patterns ReconsideredAlex Miller
 
Exploring Terracotta
Exploring TerracottaExploring Terracotta
Exploring TerracottaAlex Miller
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor ConcurrencyAlex Miller
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency GotchasAlex Miller
 

More from Alex Miller (7)

Java Collections API
Java Collections APIJava Collections API
Java Collections API
 
Java Concurrency Idioms
Java Concurrency IdiomsJava Concurrency Idioms
Java Concurrency Idioms
 
Design Patterns Reconsidered
Design Patterns ReconsideredDesign Patterns Reconsidered
Design Patterns Reconsidered
 
Java 7 Preview
Java 7 PreviewJava 7 Preview
Java 7 Preview
 
Exploring Terracotta
Exploring TerracottaExploring Terracotta
Exploring Terracotta
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
 
Java Concurrency Gotchas
Java Concurrency GotchasJava Concurrency Gotchas
Java Concurrency Gotchas
 

Recently uploaded

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Cold Hard Cache

  • 1. Cold Hard Cache Alex Miller (@puredanger)
  • 2. Agenda • Why cache? • Ehcache • Hibernate 2nd level cache • Terracotta • The future....
  • 3. Why cache? • Temporal locality • Non-uniform distribution
  • 6. Temporal locality Hits: 0% Cache: Items:
  • 7. Temporal locality Hits: 0% Cache: Items: Items:
  • 8. Temporal locality Hits: 0% Cache: Items: Items: Cache:
  • 9. Temporal locality Hits: 0% Cache: Items: Items: Cache: Hits: 65%
  • 10. Non-uniform distribution Web page hits, ordered by rank 3200 100% 2400 75% 1600 50% 800 25% 0 0% Page views, ordered by rank Pageviews per rank % of total hits per rank
  • 11. Non-uniform distribution Web page hits, ordered by rank 3200 100% 2400 75% 1600 50% 800 25% 0 0% Page views, ordered by rank Pageviews per rank % of total hits per rank
  • 12. Cache is always good right? • Watch out for: • Amdahl’s law • Memory • Concurrency • Copy cost
  • 13. Reduce latency Page build Data retrieval 2000 1500 1000 500 0 No cache With cache
  • 15. DBs are sized to peak load Operations Per Second Amount of Data
  • 16. Strive to downsize DBs Frequently accessed app data: Shared Memory (Transactional) Operations Per Second Business Record Data : Database Amount of Data
  • 18. Ehcache history • First created in 2003 by Greg Luck • Most widely used Java cache - 100k’s of deployments • Apache 2.0 license • JSR 107 Java cache implementation
  • 20. Ehcache Features • In-memory and spill-to-disk storage • Cache bootstrap loaders • Cache replication via listener API - RMI, JGroups, JMS • Cache server with REST and SOAP APIs • Servlet caching filter API • Hibernate second-level cache support
  • 24. Hibernate Caching Application Thread Application Thread Session Session 1st Level Cache Cache Cache Cache Concurrency Concurrency Concurrency Hibernate Strategy Strategy Strategy CacheProvider 2nd Level Cache Cache Cache Cache Region Region Region Database
  • 25. Entity and collection caches • Entity and collection cache regions • Mark a Hibernate entity or a collection in an entity as @Cacheable • Specify a cache concurrency strategy • ReadOnly, ReadWrite, NonstrictReadWrite, Transactional • Turn on second level caching in the Hibernate config
  • 26. Query Cache • Query cache regions • Mark HQL, Criteria, Query as cacheable • Store result set id values • Timestamp cache region - last update time for each entity type • Useful for caching natural key lookups (non-primary key) • ...but lots of hidden issues
  • 28. DistributedCache • High-throughput clustered coherent cache • Simple interface - basically ConcurrentMap • Eviction options • TTI, TTL • Max in-memory size, max total size limits
  • 29. DistributedCache Example CacheConfig config = CacheConfigFactory.newConfig(); config.setMaxTTISeconds(30 * 60) .setMaxTTLSeconds(2 * 60 * 60); DistributedCache<String, Person> cache = config.newCache(); Person person = new Person(.......); cache.put(“Alex”, person); Person cached = cache.get(“Alex”);
  • 30. DistributedCache features • Built on high throughput ConcurrentDistributedMap • Expiration based on either TTI or TTL • Both in-memory and total target max limits • Automatic memory management of caches • Coherent clustered cache
  • 31. Terracotta Hibernate Second Level Cache • Easy integration and configuration • Supports entity, collection, and query cache regions • Supports read-only, read-write, and nonstrict-read-write cache concurrency strategies • Hibernate-specific tooling • High performance with cache coherency
  • 32. Enabling Second Level Cache • Mark your entities with a cache concurrency strategy • In hibernate.cfg.xml: <cache usage="read-write"/> • With annotations: @Cache(usage=CacheConcurrencyStrategy.READ_WRITE) • hibernate.cfg.xml • <property name="cache.use_second_level_cache">true</property> • <property name="cache.provider_class"> org.terracotta.hibernate.TerracottaHibernateCacheProvider</property>
  • 33. Enabling Second Level Cache • Define the tc-hibernate-cache.xml in your classpath <?xml version=”1.0” encoding=”UTF-8”?> <terracotta-hibernate-cache-configuration> <default-configuration> <time-to-idle-seconds>7200</time-to-idle-seconds> <time-to-live-seconds>7200</time-to-live-seconds> </default-configuration> <cache> <region-name>org.terracotta.authinator.domain.Account</region-name> <!-- as many region-names here as you want --> <configuration> <time-to-idle-seconds>600</time-to-idle-seconds> <time-to-live-seconds>600</time-to-live-seconds> </configuration> </cache> </terracotta-hibernate-cache-configuration> • Add the Terracotta Hibernate cache provider jar to your classpath • -cp terracotta-hibernate-cache-1.0.0.jar • Add the Terracotta Hibernate cache agent jar to your command line • -javaagent:terracotta-hibernate-agent-1.0.0.jar
  • 34. New Hibernate cache visibility
  • 35. Performance - Read-Only Comparison Throughput Latency 200K 100 Transactions per second 80 150K Avg Latency (ms) 60 100K 40 50K 20 0K 0 Database IMDG EhcacheTerracotta Database IMDG EhcacheTerracotta
  • 36. The future of caching...
  • 37. Wonder twin powers, activate! Terracotta Ehcache • “Standard” cache apis (Ehcache / JSR 107) • Low latency local cache • High throughput clustered cache • Coherent caching with options to degrade for greater performance • Support for both “copy” and “shared object” caching
  • 38. Single node and replicated Ehcache • Same license, code base, and API • Better visibility • Better performance testing -> improved concurrency and performance • Smooth migration path to...
  • 39. Clustered Ehcache • Short release for initial integration (probably Ehcache 1.7) • Clustered store - partial API support • Smooth upgrade from single node or replicated Ehcache • New management and visibility features
  • 40. Hibernate 2nd level cache • More efficient in-memory and total count eviction (3.1.1) • Better visibility of memory conditions • Improved query caching • Improved performance of core Terracotta (lock manager and memory manager)
  • 41. Thanks! • Terracotta Open Source JVM clustering: • http://www.terracotta.org • Apress: “The Definitive Guide to Terracotta” • by Ari Zilka, Alex Miller, Geert Bevin, Jonas Boner, Orion Letizi, Taylor Gautier • 2nd edition in progress.... • Alex Miller • @puredanger • http://tech.puredanger.com