SlideShare una empresa de Scribd logo
1 de 41
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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 a 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 a 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
 

Más de 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
 

Más de 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
 

Último

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Último (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.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...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

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