Top Banner
Mathilde Lemee Cache @MathildeLemee - Aetys ROME 27-28 march 2015
78

Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Jul 15, 2015

Download

Documents

Codemotion
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Mathilde Lemee

Cache

@MathildeLemee - Aetys

ROME 27-28 march 2015

Page 2: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Mathilde Lemée

@MathildeLemee DuchessFR Founder

Tests

Java developper

Distributed Cache/IMDG

Page 3: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Why ?3

Page 4: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015
Page 5: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015
Page 6: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

1s = 1.6 billion

Page 7: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

100TB

Page 8: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

3000 $

Page 9: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

100k

Page 10: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

2 millions

Page 11: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015
Page 12: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Key Value STORE

Page 13: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

JSR 107

Cache<String, Integer> cache = Caching.getCache("simpleCache", String.class, Integer.class);

13

Page 14: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

HIT#CodeMotion @MathildeLemee

Page 15: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

MISS

#CodeMotion @MathildeLemee

Page 16: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

TTI TTL

#CodeMotion @MathildeLemee

Page 17: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Value/Reference

Page 18: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

JSR 107/** * Type of Expiry */public enum ExpiryType { /** * Time since last modified. Creation is also considered a modification event. */ MODIFIED, /** * Time since last <em>accessed</em>. Access means any access to an entry including * a modification event. Examples are: * <ul> * <li>put</li> * <li>get</li> * <li>containsKey</li> * <li>iteration</li> * </ul> * */ ACCESSED}

18

Page 19: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

PATTERN

19

Page 20: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

CACHE ASIDE

Database

Application

Cache

Functionnal

#CodeMotion @MathildeLemee

Page 21: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

JSR 107

String helloMessage = cache.get("helloKey"); if (helloMessage == null) { helloMessage = new StringBuilder(20) .append("Hello World ! ") .append(System.currentTimeMillis()).toString(); cache.put("helloKey", helloMessage);}

• // functionnal use of the helloMessage

21

Page 22: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

System of

RECORD#CodeMotion @MathildeLemee

Page 23: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Cache as a s-o-r : Read through

Database

Application

Ehcache

Persistence layer

#CodeMotion @MathildeLemee

Page 24: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

public interface CacheLoader<K, V> { /** * Loads an object. Application developers should implement this * method to customize the loading of a value for a cache entry. This method * is called by a cache when a requested entry is not in the cache. If * the object can't be loaded <code>null</code> should be returned. */ V load(K key) throws CacheLoaderException; /** * Loads multiple objects. Application developers should implement this * method to customize the loading of cache entries. This method is called * when the requested object is not in the cache. If an object can't be loaded, * it is not returned in the resulting map. */ Map<K, V> loadAll(Iterable<? extends K> keys) throws CacheLoaderException;}

24

Page 25: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Cache as a s-o-r : Write through

Database

Application

Ehcache

Persistence layer

#CodeMotion @MathildeLemee

Page 26: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

public interface CacheWriter<K, V> {

void write(Cache.Entry<? extends K, ? CacheWriterException; void writeAll(Collection<Cache.Entry<? extends K, ? extends V>> entries) throws CacheWriterException; void delete(Object key) throws CacheWriterException; void deleteAll(Collection<?> keys) throws CacheWriterException; }

26

Page 27: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Cache as a s-o-r : Write Behind

Database

Application

Ehcache

Persistence layer

Write-behind thread

#CodeMotion @MathildeLemee

Page 28: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

CONFLATION

#CodeMotion @MathildeLemee

Page 29: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

RATE LIMITING

#CodeMotion @MathildeLemee

Page 30: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

AVOID PEAK CONTENTION

#CodeMotion @MathildeLemee

Page 31: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015
Page 32: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Response

TIME#CodeMotion @MathildeLemee

Page 33: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Write Through – Response Time

#CodeMotion @MathildeLemee

Page 34: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Write Behind – Temps de réponses

#CodeMotion @MathildeLemee

Page 35: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

DATABASE#CodeMotion @MathildeLemee

Page 36: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Write Through – Database load

#CodeMotion @MathildeLemee

Page 37: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Write Behind – Database load

#CodeMotion @MathildeLemee

Page 38: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

REFRESH

AHEAD#CodeMotion @MathildeLemee

Page 39: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

TTL0

#CodeMotion @MathildeLemee

Page 40: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

TTR0

#CodeMotion @MathildeLemee

Page 41: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

And now ?

41

Page 42: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Types of cache

• Local • Remote • Mirrored • Distributed • Replicated • Near

42

Page 43: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

FAILURE#CodeMotion @MathildeLemee

Page 44: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

44

Page 45: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

45

Page 46: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

SCALE#CodeMotion @MathildeLemee

Page 47: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

#CodeMotion @MathildeLemee

Page 48: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

#CodeMotion @MathildeLemee

Page 49: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

#CodeMotion @MathildeLemee

Page 50: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

50

Page 51: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

FAILURE +SCALE

#CodeMotion @MathildeLemee

Page 52: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

52

Page 53: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

53

Page 54: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Configuration managerConfig = new Configuration() .terracotta(new TerracottaClientConfiguration().url("localhost:9510").rejoin(true)) .cache(new CacheConfiguration().name("nonstop-sample") .persistence(new PersistenceConfiguration().strategy(DISTRIBUTED)) .maxBytesLocalHeap(128, MemoryUnit.MEGABYTES) .maxBytesLocalOffHeap(1, MemoryUnit.GIGABYTES) .terracotta(new TerracottaConfiguration() ));

54

Page 55: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Distributed Cache VS

World55

Page 56: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

IMDG ?

#CodeMotion @MathildeLemee

Page 57: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Focus change

#CodeMotion @MathildeLemee

Page 58: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

IMDC : High

availabilit#CodeMotion @MathildeLemee

Page 59: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

IMDG :Data

Processi#CodeMotion @MathildeLemee

Page 60: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

IMDG = IMDG + IMCG#CodeMotion @MathildeLemee

Page 61: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

61

Page 62: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Main features#CodeMotion @MathildeLemee

Page 63: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

“Event processing is a method of tracking and analyzing (processing)

streams of information (data) about things that happen (events),[1] and deriving a

conclusion from them”#CodeMotion @MathildeLemee

Page 64: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Continuous

querying#CodeMotion @MathildeLemee

Page 65: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

In Memory

Database #CodeMotion @MathildeLemee

Page 66: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Speed

#CodeMotion @MathildeLemee

Page 67: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

SQL Join

#CodeMotion @MathildeLemee

Page 68: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Speed VS

Speed + #CodeMotion @MathildeLemee

Page 69: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Replace VS Adapt

#CodeMotion @MathildeLemee

Page 70: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

SQL ?

#CodeMotion @MathildeLemee

Page 71: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

NoSQL ?

#CodeMotion @MathildeLemee

Page 72: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

MongoDB

#CodeMotion @MathildeLemee

Page 73: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Cassandra

#CodeMotion @MathildeLemee

Page 74: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Replacement

#CodeMotion @MathildeLemee

Page 75: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Partner

#CodeMotion @MathildeLemee

Page 76: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Open-source

#CodeMotion @MathildeLemee

Page 77: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

In memory cures

everything#CodeMotion @MathildeLemee

Page 78: Let's talk about the cache! - Mathilde Lemée - Codemotion Rome 2015

Credit :

http://gridgain.blogspot.fr/2012/11/gridgain-and-hadoop-differences-and.html

http://www.infoq.com/articles/write-behind-caching

#CodeMotion @MathildeLemee