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.

Bringing javax.cache'ing to your app

1,306 views

Published on

Recorded at SpringOne2GX 2015.
Speakers:
Chris Dennis, Alex Snaps
Data / Integration Track
10 years in the making and finally JSR-107 has been finalized. We now have a standardized Caching API for the Java Platform. And that's all ready for you to use in your Spring apps. But what does it really enable for you? What's with these optional features? No transaction support? How do you efficiently make use of this new API to solve real world problems in your application today? We'll look into how get you best started introducing caching into your Spring application to solve real world problems. And, as we explore the javax.cache API in much more details, we'll see how to push the specifications to its limits and... beyond. Whether implicitly through frameworks (like Spring and Hibernate), or explicitly (cache-aside, cache-through, ...). And how to abstract yourself from a given provider when you require more than what the specifications cover (e.g. transactional caches). We'll also cover some implementer specifics you might want to account for when choosing an implementation, especially if you plan to push the spec to the extreme, like when going distributed and caching terabytes of data.

Published in: Technology
  • Be the first to comment

Bringing javax.cache'ing to your app

  1. 1. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ SPRINGONE2GX WASHINGTON, DC Bringing javax.cache’ing 
 to your Application Chris Dennis, Alex Snaps @tall_chris @alexsnaps
  2. 2. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Who are these guys? • Chris Dennis • Software Engineer • Terracotta • JSR-107 EG member 2 • Alex Snaps • Software Engineer • Terracotta • JCP EC Alternate
  3. 3. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Terracotta? Software AG? … Ehcache?! … What the • Terracotta • Network Attached Memory • Distributed Shared Object • Ehcache • World’s most used Java caching API • Joins Terracotta Aug. 2009 • Quartz • Java’s de facto scheduler • Join Terracotta Nov. 2009 • Software AG • Acquires Terracotta May 2011 3
  4. 4. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Caching ? 4
  5. 5. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Caches are everywhere … • CPU caches: L1, L2, … • Network caches • Browser caches • Disk caches • … 5
  6. 6. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Why ? • The closer the better… • … the faster • Memory is actually cheap… • … and getting cheaper • Use that memory! 6
  7. 7. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 7
  8. 8. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ On human scale 8 L1 cache reference 0.5 s One heart beat L2 cache reference 7 s Long yawn Main memory reference 100 s Brushing your teeth Send 2K bytes over 1 Gbps network 5.5 hr From lunch to end of work day Read 1 MB sequentially from memory 2.9 days A long weekend Round trip within same datacenter 5.8 days A medium vacation Read 1 MB sequentially from SSD 11.6 days Delivery in almost 2 weeks! Disk seek 16.5 weeks A semester in university Read 1 MB sequentially from disk 7.8 months Almost a baby Send packet CA->Netherlands->CA 4.8 years Avg time to bachelor's degree
  9. 9. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ So, a cache is … • Data structure holding temporary copy of data • Trades memory usage for reduced latency • Targets: • Data which is reused • Data which is expensive to retrieve / compute 9
  10. 10. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JSR-107 aka JCache 10
  11. 11. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JSR-107 in a nutshell • JSR-107 is a Java platform specification • Java Community Process driven standard • Specifies API and semantics for temporary, 
 in-memory caching of Java objects, including object creation, shared access, spooling, invalidation, and consistency across JVM's • Final(ly!) release on 18 Mar, 2014 ! • Comes with • Standardized API; • A TCK; • … a reference implementation. 11
  12. 12. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What’s in there, you ask? • CacheManagers managing … Caches ! • Expiry • Integration • Cache Entry Listeners • Entry Processors • Caching Annotations • Some Management • … but no capacity control! 12
  13. 13. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Current implementations • Oracle’s Coherence — $$$ • Terracotta’s Ehcache — OSS & $ • Hazelcast — OSS & $ • JBoss’ Infinispan • Apache Ignite • … but also • Apache JCS • GemFire 13
  14. 14. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JSR-107 is “Store by Value” • Options: • Store by Value • Store by Reference • What do you really want? • Store! (by IDGAF) 14
  15. 15. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ DEMO Caching in PetClinic 15
  16. 16. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Hibernate explanation 16
  17. 17. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Jpa Entities • Not any other POJO • Comes with a lifecycle • Transient • Persistent • Detached • Removed • Attached == non thread-safe! • Associated with a PersistenceContext
 (i.e. a JDBC Connection!) • Session flushes at tx.commit() at the latest • But could be earlier… 17
  18. 18. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Hibernate 2nd level cache • Stores “dehydrated” entities • i.e. the “column values”, not actual domain objects • Is maintained through the Hibernate/JPA session • Where the session acts as the first level cache • Hibernate supports 4 cache access strategies • Read-Only • Read-Write • Non-Strict Read-Write • Transactional 18
  19. 19. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Hibernate’s Query Cache • Caches… any query result • Is responsible for invalidations • Maintains a per entity “timestamp cache” • Holds the last time “a table” was modified • Invalidates cached query results based of TS • Timestamp cache can become the bottleneck 19
  20. 20. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Ehcache 3 aka jsr-107 on steroids 20
  21. 21. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Write-behind • Let’s you scale out writes • Controls • Batch sizes • Temporal aspects of batches being written out • Concurrency of Queues/Write threads • Coalescing • May not be persistent • Provides “at least once guarantee” • Simpler in Ehcache 3! 21
  22. 22. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Off-heap storage • JVM process allocated memory • No GC’ed (i.e. not increasing your GC pauses) • Does not require sun.misc.Unsafe • Newly open-sourced! • No limitations on sizing (tested up to 6TB on a single machine) • Available as its own library • Light-weight Java Serialization (default) • Custom Serialization support (Ehcache3) • Clock eviction 22
  23. 23. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Tiering 23
  24. 24. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Ehcache in Spring Demo 24
  25. 25. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Beyond M3 aka the future to be defined 25
  26. 26. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Milestone 4 • Transaction support, but which? • As a full XA Resource • XA Synchronization • “Local” Transaction • Automatic Resource Control • What was in 2.x • What it could do… 26
  27. 27. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Beyond M4 • Clustering using the new Terracotta 5 platform • All (re) open-sourced • General purpose clustering platform • Highly available • Configurable consistency model • Resilience • Pluggable strategy • Out of the box ones • no-op • exceptions • Plays nicely with cache-through patterns 27
  28. 28. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a
 Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 28 Questions ? @ehcache ehcache.org Learn More. Stay Connected. @ehcache ehcache.org

×