Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Caching in applications still matters

44 views

Published on

Is caching data in your application still relevant today, with all those HTTP caches, very fast key value stores, and microservices? During this presentation, you will learn the basics of caching (TTL, TTI, invalidation, tiering, and so on), key figures in the caching world, how the Java community came up with a specification (JSR 107), and how you can leverage it in your application with the implementation of your choice (EhCache 3). During the multiple demos, you’ll even see how you can sync up your (clustered) caches when you start scaling your application.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Caching in applications still matters

  1. 1. © 2018 Software AG. All rights reserved. [DEV5935] CACHING IN APPLICATIONS STILL MATTERS ! Anthony Dahanne @anthonydahanne blog.dahanne.net Henri Tremblay @henri_tremblay blog.tremblay.pro
  2. 2. LET US INTRODUCE OURSELVES „Henri Tremblay, Senior Software Engineer @ Terracotta, a Software AG company „Working on Ehcache mostly „Lead developer of EasyMock and Objenesis „Java Champion, Oracle Groundbreaker Ambassador and Montréal JUG leader „Anthony Dahanne, Senior Software Engineer @ Terracotta, a Software AG company „Working on the Terracotta Management Console „Working on Terracotta cloud deployments (Docker, Kubernetes, AWS, etc.) „Montréal JUG leader
  3. 3. AGENDA Caching 101 Caching on the JVM Clustered Caching with Terracotta Server
  4. 4. CACHING 101
  5. 5. CACHE DEFINITION “Store of things that will be required in the future, and can be retrieved rapidly.” from wiktionary.com
  6. 6. CACHE DEFINITION A Map (key/value mappings) with • capacity control (via eviction) • freshness control (via expiry)
  7. 7. WHERE IS CACHING USED ? LET’S START WITH THE CPU ! Core L1 D-cache L1 I-cache L2 Cache L3 Cache Core L1 D-cache L1 I-cache L2 Cache Core L1 D-cache L1 I-cache L2 Cache Core L1 D-cache L1 I-cache L2 Cache Not that long ago (Intel I7 series) : L1 Instruction Cache and Data Cache : 32KB L2 Cache : 256KB L3 Cache : 8MB
  8. 8. LATENCIES TO REMEMBER L1 cache reference 0.5 ns L2 cache reference 7 ns 14x L1 cache Main memory reference 100 ns 20x L2 cache Read 1 MB sequentially from memory 250,000 ns 250 us Read 1 MB sequentially from SSD* 1,000,000 ns 1,000 us 1 ms ~1GB/sec SSD Read 1 MB sequentially from disk 20,000,000 ns 20,000 us 20 ms 80x memory Send packet CA->Netherlands->CA 150 ms 150 ms from github.com/jboner
  9. 9. WHERE IS CACHING USED ? Browser Caching CDN Caching CPU Caching Application Caching Disk Caching
  10. 10. CACHING THEORY : AMDAHL’S LAW “the theoretical speedup is always limited by the part of the task that cannot benefit from the improvement.”, from Wikipedia s : speedup in latency p : percentage of the execution time
  11. 11. CACHING THEORY : THE LONG TAIL
  12. 12. CACHING GLOSSARY • Hit : when the cache returns a value • Miss : when the cache does not have a value • Cold / Hot : when the cache is empty / full
  13. 13. WHAT TO MEASURE WHEN CACHING • Cache Usage (empty ? full ?) • HitRatio : hits / (misses + hits) • HitRate : hits / second • Eviction rate • Size (in entries or bytes)
  14. 14. CACHING ON THE JVM
  15. 15. EHCACHE HISTORY OF CACHING ON THE JVM Review Ballot 2001 Public Review 2013 First Release 2003 2.0 “Express” 2010 2.3 Offheap 2011 JSR-107 First Release 2003 Terracotta 5 2016 TERRACOTTA 2009 Ehcache acquisition Public Release 2014 1.1 2017 Ehcache 3 2016
  16. 16. EHCACHE REBOOT : EHCACHE3 • 3.0 (May 2016) • Compatible with JSR-107 • User managed cache • Copiers & Serializers • Strong typing • 3.1 (Jun 2016) • Clustered tier added • 3.2 (November 2016) • High Availability with Terracotta Server • 3.5 (March 2018) • Embracing Java 8 / dropping Java 6 support • Documented resilience strategies • 3.6 (September 2018) • On-heap performance improvement
  17. 17. JSR-107 AND EHCACHE 3 INTEGRATIONS • JSR-107 • Spring (since 4.1, Spring Boot since 1.2) • Guice • jcache-cdi • Hibernate (since 5.2.0) • JHipster (since 3.12) • Bootique (since 0.21) • Ehcache 3 • Apache Shiro • Apache Camel (since 2.18)
  18. 18. CACHING PATTERNS • No Caching
  19. 19. CACHING PATTERNS • No Caching • Cache aside Business logic Cache GET(K) PUT(K,V) NULL LOAD(K) SoR K,V K,V V
  20. 20. THUNDERING HERD Client 1 Client 2 Client n ... Cache GET(K) PUT(K,V) NULL LOAD(K) SoR K,V K,V V
  21. 21. PREVENTING THE THUNDERING HERD Client 1 Client 2 Client n ... Cache GET(K) PUT(K,V) NULL LOAD(K) SoR K,V K,V V Waiting...
  22. 22. CACHING PATTERNS • No Caching • Cache aside • Cache through V Business logic Cache GET(K) LOAD(K) PUT(K,V) K,V SoR K,VV
  23. 23. CLUSTERED CACHING WITH TERRACOTTA SERVER
  24. 24. TERRACOTTA SERVER RESOURCES from ehcache.org documentation
  25. 25. n … SEVERAL CLIENTS, ACTIVE PASSIVE TERRACOTTA CLUSTER MySQL Webapp with Ehcache3 Clustered Terracotta Server Terracotta Server
  26. 26. LINKS AND REFERENCES • Old version of this conference by Anthony (Devoxx): • Slideshare: https://www.slideshare.net/anthonydahanne/terracotta-ehcache-simpler-faster-distributed • Youtube: https://www.youtube.com/watch?v=-j6cNZc5wYM • Caching 101: Caching on the JVM (and beyond) by Louis Jacomet & Aurelien Broszniowski (Devoxx UK) • Youtube: https://www.youtube.com/watch?v=FQfd8x29Ud8 • Ehcache3 documentation: http://www.ehcache.org/ • Ehcache3 and Terracotta Server demos: https://github.com/ehcache/ehcache3-samples • The essence of caching, by Greg Luck • Youtube: https://www.youtube.com/watch?v=TszcAWgCXD0
  27. 27. WHO HAS LEARNED SOMETHING TODAY? ?
  28. 28. © 2018 Software AG. All rights reserved. For internal use only"28 http://ehcache.org @ehcache http://terracotta.org @terracottatech http://montreal-jug.org @montrealjug http://easymock.org @easymock Questions? Anthony Dahanne @anthonydahanne blog.dahanne.net Henri Tremblay @henri_tremblay blog.tremblay.pro

×