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.
@ljacomet#DevoxxMA #ehcache
Ehcache 3
JSR-107 on steroids
Louis Jacomet - Lead Software Engineer
@ljacomet#DevoxxMA #ehcache
Who am I?
• Louis Jacomet
• Software engineer, closer to 40 than 20 and still coding!
• @ Terr...
@ljacomet#DevoxxMA #ehcache
And what about you?
• Who knows nothing about caching?
• Who already uses caching in productio...
@ljacomet#DevoxxMA #ehcache
Agenda
•Caching and JSR-107
•Ehcache past and present
•Ehcache 3 future
@ljacomet#DevoxxMA #ehcache
Caching and JSR-107
@ljacomet#DevoxxMA #ehcache
Caching
• Data structure holding a temporary copy of data
• Trade off between higher memory us...
@ljacomet#DevoxxMA #ehcache
Caches all over the place
CPU
Browser
Network
Disk
@ljacomet#DevoxxMA #ehcache
What should I cache?
• Keys
• Proper equals/
hashcode
• Immutable
• Small(ish)
• Value
• Prope...
@ljacomet#DevoxxMA #ehcache
JSR-107 javax.cache
• Java Community Process driven standard
• Specifies API and semantics for...
@ljacomet#DevoxxMA #ehcache
JSR-107 Features
• CacheManager / Cache
• Expiration
• Creation/Access/
Update
• Integration
•...
@ljacomet#DevoxxMA #ehcache
JSR-107 gotcha’s
• MutableConfiguration
• Always invoke
MutableConfiguration.setTypes(Class, C...
@ljacomet#DevoxxMA #ehcache
JSR-107 gotcha’s (2)
• Compare and Swap operations with a CacheLoader
• Loader is ignored
• pu...
@ljacomet#DevoxxMA #ehcache
Ehcache past and
present
@ljacomet#DevoxxMA #ehcache
A bit of history
• Announced in November 2003 on
• v1.0 released on September 2004
• Only a fe...
@ljacomet#DevoxxMA #ehcache
Storage model: tiers
• Multiple storage tiers
• Heap: like objects in a regular hash map
• Off...
@ljacomet#DevoxxMA #ehcache
Overflow model
Heap
Disk
@ljacomet#DevoxxMA #ehcache
Heap
Disk
Overflow model
@ljacomet#DevoxxMA #ehcache
Disk
Heap
Overflow model
@ljacomet#DevoxxMA #ehcache
Disk
Heap
Overflow model
@ljacomet#DevoxxMA #ehcache
Disk
Heap
Overflow model
@ljacomet#DevoxxMA #ehcache
Authoritative tier model
Heap
Disk
@ljacomet#DevoxxMA #ehcache
Disk
Heap
Authoritative tier model
@ljacomet#DevoxxMA #ehcache
Heap
Disk
Authoritative tier model
@ljacomet#DevoxxMA #ehcache
Heap
Disk
Authoritative tier model
@ljacomet#DevoxxMA #ehcache
Heap
Disk
Authoritative tier model
@ljacomet#DevoxxMA #ehcache
Why the new model?
• Predictable latency
• Every put pays the price of the lower /
slowest tie...
@ljacomet#DevoxxMA #ehcache
Not a cache feature?
• Search
• What does searching on a hot set means?
• Even without interac...
@ljacomet#DevoxxMA #ehcache
Ehcache 3
The future is here
@ljacomet#DevoxxMA #ehcache
Lifecycle - explicit
• CacheManager
• init / close methods
• create and close caches
• Persist...
@ljacomet#DevoxxMA #ehcache
Cache<K, V> for proper typing
• Ehcache 2.x not generic, was time to change
that
• Needs to be...
@ljacomet#DevoxxMA #ehcache
Serialization
• Required as soon as we move away from the
heap
• Fully customisable in Ehcache...
@ljacomet#DevoxxMA #ehcache
CacheLoaderWriter
• Enables the cache-through pattern
• Consistent across all cache operations...
@ljacomet#DevoxxMA #ehcache
Cache through - miss
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Cache through - miss
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Cache through - miss
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Cache through - miss
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Cache through - miss
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Cache through - hit
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Cache through - hit
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Cache through - hit
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Cache through - write
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Cache through - write
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Cache through - write
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Cache through - write
Application Cache
Database
@ljacomet#DevoxxMA #ehcache
Write behind
• Enables scaling your writes
• Putter does not pay for write latency
• Batching ...
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind - eviction
(K1,V1)
(K1,V1)
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind - eviction
(K1,V1)
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind - eviction
(K1,V1)
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind - eviction
(K1,V1)
@ljacomet#DevoxxMA #ehcache
Application Cache
Database
queue
Write behind - eviction
(K1,V1)
@ljacomet#DevoxxMA #ehcache
Write behind - failure
Application Cache
queue
Database
@ljacomet#DevoxxMA #ehcache
Write behind - failure
Application Cache
queue
Database
@ljacomet#DevoxxMA #ehcache
Write behind - failure
Application Cache
queue
Database
@ljacomet#DevoxxMA #ehcache
Write behind - failure
Application Cache
queue
Database
@ljacomet#DevoxxMA #ehcache
Write behind - failure
Application Cache
queue
Database
@ljacomet#DevoxxMA #ehcache
Write behind - failure
Application Cache
queue
Database
@ljacomet#DevoxxMA #ehcache
Write behind - failure
Application Cache
queue
Database
@ljacomet#DevoxxMA #ehcache
Write behind - failure
Application Cache
queue
Database
@ljacomet#DevoxxMA #ehcache
Write behind - failure
Database
@ljacomet#DevoxxMA #ehcache
Database
Write behind - failure
@ljacomet#DevoxxMA #ehcache
queue
Database
Write behind - failure
@ljacomet#DevoxxMA #ehcache
queue
Database
Write behind - failure
@ljacomet#DevoxxMA #ehcache
queue
Database
Write behind - failure
@ljacomet#DevoxxMA #ehcache
Expiry
• Offers context
@ljacomet#DevoxxMA #ehcache
Eviction Veto and Prioritizer
• Veto
• Enables to suggest a veto on certain mappings
• Priorit...
@ljacomet#DevoxxMA #ehcache
Transactions
• Full blown XA resource
• includes recovery support
• Needs work for transaction...
@ljacomet#DevoxxMA #ehcache
Clustering using Terracotta
@ljacomet#DevoxxMA #ehcache
Automatic Resource Control
• Enables sizing in natural units
• n bytes on heap
• Percentage of...
@ljacomet#DevoxxMA #ehcache
Resilience strategy
• A cache is to be resilient
• Yet… sh*t happens
• Storage failures
• SLA ...
@ljacomet#DevoxxMA #ehcache
Q&A
Thank you for your time
Upcoming SlideShare
Loading in …5
×

Ehcache 3: JSR-107 on steroids at Devoxx Morocco

1,420 views

Published on

Slides for the presentation given at Devoxx Morocco on November 18th 2015

Published in: Technology
  • Be the first to comment

Ehcache 3: JSR-107 on steroids at Devoxx Morocco

  1. 1. @ljacomet#DevoxxMA #ehcache Ehcache 3 JSR-107 on steroids Louis Jacomet - Lead Software Engineer
  2. 2. @ljacomet#DevoxxMA #ehcache Who am I? • Louis Jacomet • Software engineer, closer to 40 than 20 and still coding! • @ Terracotta (Software AG) since 2013 • Working on Ehcache mostly • Team manager and fiddling in infrastructure • No idea how to do a (nice) UI, especially a web one • Enjoys concurrency, API design and hard problems
  3. 3. @ljacomet#DevoxxMA #ehcache And what about you? • Who knows nothing about caching? • Who already uses caching in production? • Who had production problems related to caching? • Who knows about JCache?
  4. 4. @ljacomet#DevoxxMA #ehcache Agenda •Caching and JSR-107 •Ehcache past and present •Ehcache 3 future
  5. 5. @ljacomet#DevoxxMA #ehcache Caching and JSR-107
  6. 6. @ljacomet#DevoxxMA #ehcache Caching • Data structure holding a temporary copy of data • Trade off between higher memory usage and reduced latency • Targets • Data which is reused • Data which is expensive to compute / retrieve
  7. 7. @ljacomet#DevoxxMA #ehcache Caches all over the place CPU Browser Network Disk
  8. 8. @ljacomet#DevoxxMA #ehcache What should I cache? • Keys • Proper equals/ hashcode • Immutable • Small(ish) • Value • Proper equals/ hashcode • Ideally immutable • Think concurrent otherwise • Size matters
  9. 9. @ljacomet#DevoxxMA #ehcache JSR-107 javax.cache • 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
  10. 10. @ljacomet#DevoxxMA #ehcache JSR-107 Features • CacheManager / Cache • Expiration • Creation/Access/ Update • Integration • CacheLoader / Writer • CacheEntryListener • Created/Updated • Removed/Expired • Get old value • Entry processor • Annotations • MBeans, exposing • Configuration • Statistics • No capacity control !
  11. 11. @ljacomet#DevoxxMA #ehcache JSR-107 gotcha’s • MutableConfiguration • Always invoke MutableConfiguration.setTypes(Class, Class) • Otherwise Cache only knows about Object • Adding a CacheLoader factory is not enough - need to invoke setReadThrough(boolean)
  12. 12. @ljacomet#DevoxxMA #ehcache JSR-107 gotcha’s (2) • Compare and Swap operations with a CacheLoader • Loader is ignored • putIfAbsent checks Cache only, not underlying system of record • Results in a weird contract
  13. 13. @ljacomet#DevoxxMA #ehcache Ehcache past and present
  14. 14. @ljacomet#DevoxxMA #ehcache A bit of history • Announced in November 2003 on • v1.0 released on September 2004 • Only a few days before Java 5 and generics • Acquired in 2009 by • v2.0 released in March 2010 • Terracotta acquired in 2011 by
  15. 15. @ljacomet#DevoxxMA #ehcache Storage model: tiers • Multiple storage tiers • Heap: like objects in a regular hash map • Off-heap: binary form stored outside of Garbage Collector reach • Disk: binary form stored on disk • Clustered: binary form stored on other server(s)
  16. 16. @ljacomet#DevoxxMA #ehcache Overflow model Heap Disk
  17. 17. @ljacomet#DevoxxMA #ehcache Heap Disk Overflow model
  18. 18. @ljacomet#DevoxxMA #ehcache Disk Heap Overflow model
  19. 19. @ljacomet#DevoxxMA #ehcache Disk Heap Overflow model
  20. 20. @ljacomet#DevoxxMA #ehcache Disk Heap Overflow model
  21. 21. @ljacomet#DevoxxMA #ehcache Authoritative tier model Heap Disk
  22. 22. @ljacomet#DevoxxMA #ehcache Disk Heap Authoritative tier model
  23. 23. @ljacomet#DevoxxMA #ehcache Heap Disk Authoritative tier model
  24. 24. @ljacomet#DevoxxMA #ehcache Heap Disk Authoritative tier model
  25. 25. @ljacomet#DevoxxMA #ehcache Heap Disk Authoritative tier model
  26. 26. @ljacomet#DevoxxMA #ehcache Why the new model? • Predictable latency • Every put pays the price of the lower / slowest tier • No degradation when a higher tier gets full • Preserves fast(er) access for hot set • When a mapping is accessed it moves to the fastest tier available
  27. 27. @ljacomet#DevoxxMA #ehcache Not a cache feature? • Search • What does searching on a hot set means? • Even without interacting with the cache, two execution of the same query could return different results • Pinning • Prevent eviction from cache entries • May adversly effect the ability of the cache to respect size constraints
  28. 28. @ljacomet#DevoxxMA #ehcache Ehcache 3 The future is here
  29. 29. @ljacomet#DevoxxMA #ehcache Lifecycle - explicit • CacheManager • init / close methods • create and close caches • PersistentCacheManager • Maintenance mode • Destroy cache data
  30. 30. @ljacomet#DevoxxMA #ehcache Cache<K, V> for proper typing • Ehcache 2.x not generic, was time to change that • Needs to be known at runtime • No one wants a ClassCastException • Cache data may live beyond application lifecycle • Usage show that frequently key and values are of the same type in a given cache
  31. 31. @ljacomet#DevoxxMA #ehcache Serialization • Required as soon as we move away from the heap • Fully customisable in Ehcache 3
  32. 32. @ljacomet#DevoxxMA #ehcache CacheLoaderWriter • Enables the cache-through pattern • Consistent across all cache operations • Single interface • Loader only - make sure write related methods throw • Writer only - what? • Anyone having a good use case for this - talk to us
  33. 33. @ljacomet#DevoxxMA #ehcache Cache through - miss Application Cache Database
  34. 34. @ljacomet#DevoxxMA #ehcache Cache through - miss Application Cache Database
  35. 35. @ljacomet#DevoxxMA #ehcache Cache through - miss Application Cache Database
  36. 36. @ljacomet#DevoxxMA #ehcache Cache through - miss Application Cache Database
  37. 37. @ljacomet#DevoxxMA #ehcache Cache through - miss Application Cache Database
  38. 38. @ljacomet#DevoxxMA #ehcache Cache through - hit Application Cache Database
  39. 39. @ljacomet#DevoxxMA #ehcache Cache through - hit Application Cache Database
  40. 40. @ljacomet#DevoxxMA #ehcache Cache through - hit Application Cache Database
  41. 41. @ljacomet#DevoxxMA #ehcache Cache through - write Application Cache Database
  42. 42. @ljacomet#DevoxxMA #ehcache Cache through - write Application Cache Database
  43. 43. @ljacomet#DevoxxMA #ehcache Cache through - write Application Cache Database
  44. 44. @ljacomet#DevoxxMA #ehcache Cache through - write Application Cache Database
  45. 45. @ljacomet#DevoxxMA #ehcache Write behind • Enables scaling your writes • Putter does not pay for write latency • Batching and coalescing options • Simplified compared to 2.x - no more sizing gotchas
  46. 46. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind
  47. 47. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind
  48. 48. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind
  49. 49. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind
  50. 50. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind
  51. 51. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind
  52. 52. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind
  53. 53. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind
  54. 54. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind
  55. 55. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind - eviction (K1,V1) (K1,V1)
  56. 56. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind - eviction (K1,V1)
  57. 57. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind - eviction (K1,V1)
  58. 58. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind - eviction (K1,V1)
  59. 59. @ljacomet#DevoxxMA #ehcache Application Cache Database queue Write behind - eviction (K1,V1)
  60. 60. @ljacomet#DevoxxMA #ehcache Write behind - failure Application Cache queue Database
  61. 61. @ljacomet#DevoxxMA #ehcache Write behind - failure Application Cache queue Database
  62. 62. @ljacomet#DevoxxMA #ehcache Write behind - failure Application Cache queue Database
  63. 63. @ljacomet#DevoxxMA #ehcache Write behind - failure Application Cache queue Database
  64. 64. @ljacomet#DevoxxMA #ehcache Write behind - failure Application Cache queue Database
  65. 65. @ljacomet#DevoxxMA #ehcache Write behind - failure Application Cache queue Database
  66. 66. @ljacomet#DevoxxMA #ehcache Write behind - failure Application Cache queue Database
  67. 67. @ljacomet#DevoxxMA #ehcache Write behind - failure Application Cache queue Database
  68. 68. @ljacomet#DevoxxMA #ehcache Write behind - failure Database
  69. 69. @ljacomet#DevoxxMA #ehcache Database Write behind - failure
  70. 70. @ljacomet#DevoxxMA #ehcache queue Database Write behind - failure
  71. 71. @ljacomet#DevoxxMA #ehcache queue Database Write behind - failure
  72. 72. @ljacomet#DevoxxMA #ehcache queue Database Write behind - failure
  73. 73. @ljacomet#DevoxxMA #ehcache Expiry • Offers context
  74. 74. @ljacomet#DevoxxMA #ehcache Eviction Veto and Prioritizer • Veto • Enables to suggest a veto on certain mappings • Prioritizer • Allows to sort sample before picking eviction victim • Not applicable to all stores • Both are hints only - capacity always takes priority
  75. 75. @ljacomet#DevoxxMA #ehcache Transactions • Full blown XA resource • includes recovery support • Needs work for transaction managers integration • Code isolated in its own module • Currently part of the main Ehcache 3 jar
  76. 76. @ljacomet#DevoxxMA #ehcache Clustering using Terracotta
  77. 77. @ljacomet#DevoxxMA #ehcache Automatic Resource Control • Enables sizing in natural units • n bytes on heap • Percentage of the max heap available • Define resource pools at the cache manager • Cross eviction amongst caches • Enables auto balancing
  78. 78. @ljacomet#DevoxxMA #ehcache Resilience strategy • A cache is to be resilient • Yet… sh*t happens • Storage failures • SLA violations (timeouts?) • Very explicit contract at this time • To be refined when clustering is wrapping up
  79. 79. @ljacomet#DevoxxMA #ehcache Q&A Thank you for your time

×