Bringing javax.cache'ing to your app
-
Upload
spring-by-pivotal -
Category
Technology
-
view
1.069 -
download
1
Transcript of Bringing javax.cache'ing to your app
![Page 1: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/1.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
SPRINGONE2GXWASHINGTON, DC
Bringing javax.cache’ing to your Application
Chris Dennis, Alex Snaps @tall_chris @alexsnaps
![Page 2: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/2.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 3: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/3.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 4: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/4.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Caching ?
4
![Page 5: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/5.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Caches are everywhere …
• CPU caches: L1, L2, …
• Network caches
• Browser caches
• Disk caches
• …
5
![Page 6: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/6.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Why ?
• The closer the better…
• … the faster
• Memory is actually cheap…
• … and getting cheaper
• Use that memory!
6
![Page 7: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/7.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 7
![Page 8: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/8.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 9: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/9.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 10: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/10.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
JSR-107 aka JCache
10
![Page 11: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/11.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 12: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/12.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 13: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/13.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 14: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/14.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 15: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/15.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
DEMO Caching in PetClinic
15
![Page 16: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/16.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Hibernate explanation
16
![Page 17: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/17.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 18: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/18.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 19: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/19.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 20: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/20.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Ehcache 3 aka jsr-107 on steroids
20
![Page 21: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/21.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 22: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/22.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 23: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/23.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Tiering
23
![Page 24: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/24.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Ehcache in Spring Demo
24
![Page 25: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/25.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/
Beyond M3 aka the future to be defined
25
![Page 26: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/26.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 27: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/27.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/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
![Page 28: Bringing javax.cache'ing to your app](https://reader034.fdocuments.us/reader034/viewer/2022050614/58a02db01a28ab4e768b6b73/html5/thumbnails/28.jpg)
Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 28
Questions ?
@ehcache ehcache.org
Learn More. Stay Connected.
@ehcache ehcache.org