let's talk about the cache! - mathilde lemée - codemotion rome 2015

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

Upload: codemotion

Post on 15-Jul-2015

435 views

Category:

Documents


0 download

TRANSCRIPT

Mathilde Lemee

Cache

@MathildeLemee - Aetys

ROME 27-28 march 2015

Mathilde Lemée

@MathildeLemee DuchessFR Founder

Tests

Java developper

Distributed Cache/IMDG

Why ?3

1s = 1.6 billion

100TB

3000 $

100k

2 millions

Key Value STORE

JSR 107

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

13

HIT#CodeMotion @MathildeLemee

MISS

#CodeMotion @MathildeLemee

TTI TTL

#CodeMotion @MathildeLemee

Value/Reference

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

PATTERN

19

CACHE ASIDE

Database

Application

Cache

Functionnal

#CodeMotion @MathildeLemee

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

System of

RECORD#CodeMotion @MathildeLemee

Cache as a s-o-r : Read through

Database

Application

Ehcache

Persistence layer

#CodeMotion @MathildeLemee

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

Cache as a s-o-r : Write through

Database

Application

Ehcache

Persistence layer

#CodeMotion @MathildeLemee

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

Cache as a s-o-r : Write Behind

Database

Application

Ehcache

Persistence layer

Write-behind thread

#CodeMotion @MathildeLemee

CONFLATION

#CodeMotion @MathildeLemee

RATE LIMITING

#CodeMotion @MathildeLemee

AVOID PEAK CONTENTION

#CodeMotion @MathildeLemee

Response

TIME#CodeMotion @MathildeLemee

Write Through – Response Time

#CodeMotion @MathildeLemee

Write Behind – Temps de réponses

#CodeMotion @MathildeLemee

DATABASE#CodeMotion @MathildeLemee

Write Through – Database load

#CodeMotion @MathildeLemee

Write Behind – Database load

#CodeMotion @MathildeLemee

REFRESH

AHEAD#CodeMotion @MathildeLemee

TTL0

#CodeMotion @MathildeLemee

TTR0

#CodeMotion @MathildeLemee

And now ?

41

Types of cache

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

42

FAILURE#CodeMotion @MathildeLemee

44

45

SCALE#CodeMotion @MathildeLemee

#CodeMotion @MathildeLemee

#CodeMotion @MathildeLemee

#CodeMotion @MathildeLemee

50

FAILURE +SCALE

#CodeMotion @MathildeLemee

52

53

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

Distributed Cache VS

World55

IMDG ?

#CodeMotion @MathildeLemee

Focus change

#CodeMotion @MathildeLemee

IMDC : High

availabilit#CodeMotion @MathildeLemee

IMDG :Data

Processi#CodeMotion @MathildeLemee

IMDG = IMDG + IMCG#CodeMotion @MathildeLemee

61

Main features#CodeMotion @MathildeLemee

“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

Continuous

querying#CodeMotion @MathildeLemee

In Memory

Database #CodeMotion @MathildeLemee

Speed

#CodeMotion @MathildeLemee

SQL Join

#CodeMotion @MathildeLemee

Speed VS

Speed + #CodeMotion @MathildeLemee

Replace VS Adapt

#CodeMotion @MathildeLemee

SQL ?

#CodeMotion @MathildeLemee

NoSQL ?

#CodeMotion @MathildeLemee

MongoDB

#CodeMotion @MathildeLemee

Cassandra

#CodeMotion @MathildeLemee

Replacement

#CodeMotion @MathildeLemee

Partner

#CodeMotion @MathildeLemee

Open-source

#CodeMotion @MathildeLemee

In memory cures

everything#CodeMotion @MathildeLemee

Credit :

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

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

#CodeMotion @MathildeLemee