eventual consistency
DESCRIPTION
Slides explaining the consistency modes for Terracotta clustered ehcache.TRANSCRIPT
Terracotta Ehcache ConsistencyStrong and EventualAbhishek SanoujamMarch 29, 2011
Terracotta Ehcache Consistency
Ehcache-2.4 + Terracotta 3.5
Search– http://ehcache.org/documentation/search.html
New Consistency modes– http://ehcache.org/documentation/terracotta/
consistency_options.html
Nonstop feature– http://ehcache.org/documentation/terracotta/non_stop_cache.html
Rejoin Explicit locking api merged to Ehcache interface Various other perf improvements and bug fixes
– http://ehcache.org
2
Terracotta Ehcache Consistency
Terracotta Ehcache Consistency
3
Terracotta Ehcache Consistency
Terracotta Ehcache Consistency
New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml
3
Terracotta Ehcache Consistency
Terracotta Ehcache Consistency
New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />
</cache>
3
Terracotta Ehcache Consistency
Terracotta Ehcache Consistency
New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />
</cache>
Consistency can be “strong” or “eventual”
3
Terracotta Ehcache Consistency
Terracotta Ehcache Consistency
New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />
</cache>
Consistency can be “strong” or “eventual” Old “coherent” attribute deprecated
3
Terracotta Ehcache Consistency
Terracotta Ehcache Consistency
New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />
</cache>
Consistency can be “strong” or “eventual” Old “coherent” attribute deprecated With “strong” consistency, changes made by any node in
the cluster are visible instantly
3
Terracotta Ehcache Consistency
Terracotta Ehcache Consistency
New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />
</cache>
Consistency can be “strong” or “eventual” Old “coherent” attribute deprecated With “strong” consistency, changes made by any node in
the cluster are visible instantly With “eventual” consistency, changes made by any node
are visible to other nodes eventually
3
Terracotta Ehcache Consistency
Terracotta Ehcache Consistency
New attribute “consistency” in “terracotta” sub-element of “cache” in ehcache.xml<cache name=”sampleCache”> <terracotta consistency=”strong|eventual” />
</cache>
Consistency can be “strong” or “eventual” Old “coherent” attribute deprecated With “strong” consistency, changes made by any node in
the cluster are visible instantly With “eventual” consistency, changes made by any node
are visible to other nodes eventually http://ehcache.org/documentation/terracotta/consistency_options.html
3
Terracotta Ehcache Consistency
Strong Consistency
4
Terracotta Ehcache Consistency
Strong Consistency
Changes are visible cluster-wide instantly
4
Terracotta Ehcache Consistency
Strong Consistency
Changes are visible cluster-wide instantly Reads/Writes uses clustered locks
– Clustered locks same as normal read-write locks, but valid through the cluster
– Multiple reads possible– Writes are mutually exclusive to other writes and reads
4
Terracotta Ehcache Consistency
Strong Consistency
Changes are visible cluster-wide instantly Reads/Writes uses clustered locks
– Clustered locks same as normal read-write locks, but valid through the cluster
– Multiple reads possible– Writes are mutually exclusive to other writes and reads
Honors happens-before cluster wide (using clustered locks)
4
Terracotta Ehcache Consistency
Strong Consistency
Changes are visible cluster-wide instantly Reads/Writes uses clustered locks
– Clustered locks same as normal read-write locks, but valid through the cluster
– Multiple reads possible– Writes are mutually exclusive to other writes and reads
Honors happens-before cluster wide (using clustered locks) Supports other concurrent apis
– putIfAbsent(Element element)– removeElement(Element element)– replace(Element element)– replace(Element old, Element element)
4
Terracotta Ehcache Consistency
Strong Consistency
Changes are visible cluster-wide instantly Reads/Writes uses clustered locks
– Clustered locks same as normal read-write locks, but valid through the cluster
– Multiple reads possible– Writes are mutually exclusive to other writes and reads
Honors happens-before cluster wide (using clustered locks) Supports other concurrent apis
– putIfAbsent(Element element)– removeElement(Element element)– replace(Element element)– replace(Element old, Element element)
Works with explicit locking apis
4
Terracotta Ehcache Consistency
Eventual Consistency
5
Terracotta Ehcache Consistency
Eventual Consistency
Changes are visible to other nodes eventually (in order of ms)
5
Terracotta Ehcache Consistency
Eventual Consistency
Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated
5
Terracotta Ehcache Consistency
Eventual Consistency
Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from
clients local cache
5
Terracotta Ehcache Consistency
Eventual Consistency
Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from
clients local cache Can read stale data for some time (in order of msecs)
5
Terracotta Ehcache Consistency
Eventual Consistency
Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from
clients local cache Can read stale data for some time (in order of msecs) Suitable for apps that can tolerate reading stale data
5
Terracotta Ehcache Consistency
Eventual Consistency
Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from
clients local cache Can read stale data for some time (in order of msecs) Suitable for apps that can tolerate reading stale data No need of locks for reads/writes
– Better performance compared to strong consistency
5
Terracotta Ehcache Consistency
Eventual Consistency
Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from
clients local cache Can read stale data for some time (in order of msecs) Suitable for apps that can tolerate reading stale data No need of locks for reads/writes
– Better performance compared to strong consistency Supports other concurrent apis
– putIfAbsent(Element element)– removeElement(Element element)– replace(Element element)– replace(Element old, Element element)
5
Terracotta Ehcache Consistency
Eventual Consistency
Changes are visible to other nodes eventually (in order of ms) L2 notifies clients about which keys were updated On receiving update from L2, those mappings are removed from
clients local cache Can read stale data for some time (in order of msecs) Suitable for apps that can tolerate reading stale data No need of locks for reads/writes
– Better performance compared to strong consistency Supports other concurrent apis
– putIfAbsent(Element element)– removeElement(Element element)– replace(Element element)– replace(Element old, Element element)
Works with explicit locking apis– provides more control over locking
5
Terracotta Ehcache Consistency
Old “coherent” attribute deprecated
6
Terracotta Ehcache Consistency
Old “coherent” attribute deprecated
Old “coherent” attribute deprecated
6
Terracotta Ehcache Consistency
Old “coherent” attribute deprecated
Old “coherent” attribute deprecated coherent=”true” translates to consistency=”strong”
6
Terracotta Ehcache Consistency
Old “coherent” attribute deprecated
Old “coherent” attribute deprecated coherent=”true” translates to consistency=”strong” coherent=”false” translates to consistency=”eventual”
6
Terracotta Ehcache Consistency
Old “coherent” attribute deprecated
Old “coherent” attribute deprecated coherent=”true” translates to consistency=”strong” coherent=”false” translates to consistency=”eventual” Old coherent=”false” meant bulk-load mode (incoherent
mode)– Cannot be set in config (use “eventual” consistency instead)– possible through api only now
• setNodeBulkLoadEnabled(true)• setNodeBulkLoadEnabled(false)
6
Terracotta Ehcache Consistency
Bulk-load mode
7
Terracotta Ehcache Consistency
Bulk-load mode
coherent=”false” - bulk load mode or incoherent mode
7
Terracotta Ehcache Consistency
Bulk-load mode
coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes
7
Terracotta Ehcache Consistency
Bulk-load mode
coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1)
7
Terracotta Ehcache Consistency
Bulk-load mode
coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1) Warmup of large caches happens pretty fast
7
Terracotta Ehcache Consistency
Bulk-load mode
coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1) Warmup of large caches happens pretty fast Once values are fetched, changes/updates by other nodes visible after
specific time (5 mins by default)
7
Terracotta Ehcache Consistency
Bulk-load mode
coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1) Warmup of large caches happens pretty fast Once values are fetched, changes/updates by other nodes visible after
specific time (5 mins by default) Possible through api only
7
Terracotta Ehcache Consistency
Bulk-load mode
coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1) Warmup of large caches happens pretty fast Once values are fetched, changes/updates by other nodes visible after
specific time (5 mins by default) Possible through api only Old api’s are deprecated
– setNodeCoherent(boolean coherent)– isNodeCoherent()– isClusterCoherent()– waitUntilClusterCoherent()
7
Terracotta Ehcache Consistency
Bulk-load mode
coherent=”false” - bulk load mode or incoherent mode No locks are required for reads/writes Writes are batched heavily in the client (L1) Warmup of large caches happens pretty fast Once values are fetched, changes/updates by other nodes visible after
specific time (5 mins by default) Possible through api only Old api’s are deprecated
– setNodeCoherent(boolean coherent)– isNodeCoherent()– isClusterCoherent()– waitUntilClusterCoherent()
New api’s added in Ehcache interface:– setNodeBulkLoadEnabled(boolean enabledBulkLoad)– isNodeBulkLoadEnabled()– isClusterBulkLoadEnabled()– waitUntilClusterBulkLoadComplete()
7
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
(k1, )v1
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
(k1, )v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)
(k1, )v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
acquireLock(READ) acquireLock
(READ)
v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
acquireLock(READ) acquireLock
(READ)
v1
recall
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
acquireLock(READ) acquireLock
(READ)
v1
recall
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
v1
recall
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
v1
recall
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)
v1
recall
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
v1
recall
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1
v1
recall
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1
put(k1, v2)
v1
recall
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1
put(k1, v2)
v1
recall
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1
put(k1, v2)
recall recall
v1
recall
(k1, v1)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
recall recall
v1
recall
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
recall recall
v1
recall
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v1
recall
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
recall
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
v2 v2
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
v2 v2
(k1, v2) (k1, v2)
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
v2 v2
(k1, v2) (k1, v2)
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
v2 v2
(k1, v2) (k1, v2)
recall
(k1, v2)
Terracotta Ehcache Consistency
How it works - Strong Consistency
8
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
acquireLock(WRITE)
Node B (L1)
put(k1, v1)
grant lock
put(k1, v1)
get(k1)get(k1)
(k1, )
grant readlock
acquireLock(READ) acquireLock
(READ)
grant readlock
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
recall recall
v2
v2 v2
(k1, v2) (k1, v2)
recall
(k1, v2)
v2 v2
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
(k1, )v1
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
(k1, )v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)
(k1, )v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)get(k1)
v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)get(k1)v1 v1
v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1
v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1
put(k1, v2)
v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1put(k1, v2)
put(k1, v2)
v1
(k1, v1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1put(k1, v2)
put(k1, v2)
v2
(k1, v1)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1put(k1, v2)
put(k1, v2)
v2
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1put(k1, v2)
put(k1, v2)
v2
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1put(k1, v2)
put(k1, v2)
v2
v1
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1put(k1, v2)
put(k1, v2)
v2
v1
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1put(k1, v2)
put(k1, v2)
v2
v1 v1
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)
(k1, v1) (k1, v1)
get(k1)v1 v1put(k1, v2)
put(k1, v2)
v2
k1 k1
v1 v1
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
v2
k1 k1
v1 v1
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
v2
k1 k1
v1 v1
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
v2
k1 k1
v1 v1
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
v2
k1 k1
v1 v1
v2 v2
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
v2
k1 k1
(k1, v2) (k1, v2)
v1 v1
v2 v2
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
v2
k1 k1
(k1, v2) (k1, v2)
v1 v1v2 v2
v2 v2
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
v2
k1 k1
(k1, v2) (k1, v2)
v1 v1v2 v2
v2 v2
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
v2
k1 k1
(k1, v2) (k1, v2)
v1 v1v2 v2
v2 v2
(k1, v1)(k1, v2)
Terracotta Ehcache Consistency
How it works - Eventual Consistency
9
Terracotta Server Array (L2)
Node A (L1)
Node C (L1)
Node B (L1)
put(k1, v1)
put(k1, v1)
get(k1)get(k1)
(k1, )
get(k1)get(k1)v1 v1
put(k1, v2)
put(k1, v2)
v2
k1 k1
(k1, v2) (k1, v2)
v1 v1v2 v2
v2 v2
(k1, v2)
Terracotta Ehcache Consistency
How it works - Bulk load mode
10
Terracotta Ehcache Consistency
How it works - Bulk load mode
Similar to eventual consistency– No locks required
10
Terracotta Ehcache Consistency
How it works - Bulk load mode
Similar to eventual consistency– No locks required
Puts are batched heavily in the L1
10
Terracotta Ehcache Consistency
How it works - Bulk load mode
Similar to eventual consistency– No locks required
Puts are batched heavily in the L1 The L2 don’t send out invalidation notifications
10
Terracotta Ehcache Consistency
How it works - Bulk load mode
Similar to eventual consistency– No locks required
Puts are batched heavily in the L1 The L2 don’t send out invalidation notifications Invalidations in the local cache happen based on time (5
mins by default)
10
Terracotta Ehcache Consistency
How it works - Bulk load mode
Similar to eventual consistency– No locks required
Puts are batched heavily in the L1 The L2 don’t send out invalidation notifications Invalidations in the local cache happen based on time (5
mins by default) Apps read stale data for the specified time interval
– configurable via tc property “ehcache.storageStrategy.dcv2.localcache.incoherentReadTimeout”
10
Terracotta Ehcache Consistency
Comparison
Strong consistency– Reads/Writes happen under locks– Invalidations of local cache happens when a node acquires
WRITE locks
Eventual Consistency– Reads/Writes do not require locks– L2 notifies about changes to interested nodes– L1 invalidates local cache upon receiving notification from L2– Notifications are batched and sent to only interested nodes
Bulk-load mode– No locks required– Invalidations happen based on time (5 mins by default)– Puts are batched heavily in the L1
11
Terracotta Ehcache Consistency
Summary
Strong consistency– Pros
• Provides coherent data across the cluster• Changes visible to all nodes instantly• Honors happens-before cluster wide
– Cons• If coherent cache not desired, suffers from performance• Needs locks for both reads and writes• May result in lock hopping when data not partitioned leading to perf
degradation
12
Terracotta Ehcache Consistency
Summary
13
Terracotta Ehcache Consistency
Summary
Eventual Consistency– Pros
• No need of locks for reads/writes• Better performance• Changes are visible across cluster in order of ms
– Cons• Application can read stale data for some time
13
Terracotta Ehcache Consistency
Summary
Eventual Consistency– Pros
• No need of locks for reads/writes• Better performance• Changes are visible across cluster in order of ms
– Cons• Application can read stale data for some time
Bulk Load mode– Pros
• No need of locks for reads/writes• Better performance for puts, useful for cache warmup
– Cons• Application can read stale data for longer amount of time• Values once fetched, will see changes after specific amount of time
13
Thank you!
Abhishek [email protected]
http://terracotta.orghttp://ehcache.orghttp://ehcache.org/documentation/terracotta/consistency_options.html