Talk given during Devoxx Belgium 2016
https://cfp.devoxx.be/2016/speaker/anthony_dahanne
Caching 101
Caching on the JVM
Clustered Caching with Terracotta Server
Deployment examples
2. „Anthony Dahanne, Software Engineer @ Terracotta,
a Software AG company
„Working on the Terracotta Management Console,
and its integration in Terracotta products
„And strong Docker supporter :-P , trying to
containerize as much as I can !
LET ME INTRODUCE MYSELF
„Come visit us at Booth #1 ! Oculus Rift to win !!!
5. CACHE DEFINITION
“Store of things
that will be required in the future,
and can be retrieved rapidly.”
from wiktionary.com
A Map (key / value mappings)
with capacity control (via eviction)
and freshness control (via expiry)
7. 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
Round trip within same datacenter 500,000 ns 500 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
8. WHERE IS CACHING USED ?
Browser Caching CDN Caching
CPU Caching
Application Caching
Disk Caching
9. 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. 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
12. WHAT TO MEASURE WHEN CACHING
• Cache Usage (empty ? full ?)
• HitRatio : hits / (misses + hits)
• HitRate : hits / second
14. 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
EHCACHE
First Release
2003
Terracotta 5
2016
TERRACOTTA
Ehcache3
2016
2009
Ehcache acquisition
Public Release
2014
15. EHCACHE REBOOT : EHCACHE3
• 3.0 (May 2016)
• Compatible with JSR 107 (javax.cache)
• User managed cache
• Copiers & Serializers
• Strong typing
• 3.1 (Jun 2016)
• Clustered tier added
• 3.2 (2 days ago)
• High Availability with Terracotta Server
16. CACHING PATTERNS
• No Caching
• Cache aside
• Cache through
• Demo !
Business logic
Cache
GET(K)
PUT(K,V)
NULL
LOAD(K)
V
SoR
K,V
K,V
Business logic Cache
GET(K) LOAD(K)
V
PUT(K,V)
K,V
SoR
K,VV
21. App
Server
App Server
App Server
DEPLOYMENT
App Server
App Server
Ehcache
App Server
JBOSS
SOA-P
App Server
Ehcache
Layer 7
“Presentation Zone” “Application Zone”
Individual
& Families
Issuers
3rd Parties
(B2B)
187K simultaneous users / 6K processes requests/s
10’s of Terracotta Servers / 100’s of caching clients
22. LINKS AND REFERENCES
• The essence of caching, by Greg Luck (available on youtube)
• Caching 101: Caching on the JVM (and beyond) by Louis Jacomet & Aurelien Broszniowski (available on
youtube)
• Ehcache3 documentation (available on ehcache.org)
• Ehcache3 and Terracotta Server demos (available on github)