Upload
spring-by-pivotal
View
1.069
Download
1
Embed Size (px)
Citation preview
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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