Gimme Caching - The JCache Way

Preview:

Citation preview

www.hazelcast.com@noctarius2k

/** * Gimme Caching * The JCache Way */

www.hazelcast.com@noctarius2k

Interactive!

www.hazelcast.com@noctarius2k

www.hazelcast.com@noctarius2k

Disclaimer# A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00002aaaaaf6d9c3, pid=2185, tid=1086892352 # # JRE version: 6.0_21-b06 # Java VM: Java HotSpot(TM) 64-Bit Server VM (17.0-b16 mixed mode linux-amd64 ) # # An error report file with more information is saved as: # /path/to/hs_err_pid2185.log # # This presentation may include certain forward-looking statements and projections provided by the Company. Any such # statements and projections reflect various estimates and assumptions by the Company concerning anticipated # results. These statements involve risks, uncertainties and assumptions and are based on the current estimates and # assumptions of the management of the Company as of the date of this presentation and are subject to uncertainty and # changes. No representations or warranties are made by the Company as to the accuracy of any such statements or # projections. Whether or not any such forward-looking statements or projections are in fact achieved will depend upon # future events some of which are not within the control of the Company. Accordingly, actual results may vary from the # projected results and such variations may be material. Statements contained herein describing documents and # agreements are summaries only and such summaries are qualified in their entirety by reference to such documents # and agreements.

www.hazelcast.com@noctarius2k

Who’s that dude?

• Chris(toph) Engelbert • Twitter fanatic: @noctarius2k • Weird 9+ Java-Years • Performance, GC, Fairytales • Apache Committer • Gaming, Travel Management, …

www.hazelcast.com@noctarius2k

• Chris(toph) Engelbert • Twitter fanatic: @noctarius2k • Weird 9+ Java-Years • Performance, GC, Fairytales • Apache Committer • Gaming, Travel Management, …

The www.hazelcast.ninja

Who’s that dude?

www.hazelcast.com@noctarius2k

… What is Caching?OOO( )

www.hazelcast.com@noctarius2k

Collect, store …

www.hazelcast.com@noctarius2k

…access fast when necessary!…access fast when necessary!

www.hazelcast.com

Fast Delivery

www.hazelcast.com@noctarius2k

‘In-Memory Caching’

L1 Cache Reference L2 Cache Reference Main Memory Reference 1K send over 1 Gbps Network 4K read from SSD Seek on Spinning Disk Send Packet CA->AMS->CA

0.5 ns 7 ns

100 ns 10,000 ns

150,000 ns 10,000,000 ns

150,000,000 ns

0.01 ms 0.15 ms

10 ms 150 ms

www.hazelcast.com@noctarius2k

Evolution of:- Memory-Price- Memory-Size

www.hazelcast.com@noctarius2k

Caches

www.hazelcast.com@noctarius2k

http://gadizmo.com/roll-your-own-with-the-ham-dogger.php

Roll Your Own!Caches Are Simple

www.hazelcast.com@noctarius2k

Caches Are Simple!public class Cache<K, V> { private final Map<K, V> cache = new CHM<>();

public void put(K key, V value) { cache.put(key, value); }

public V get(K key) { return cache.get(key); } }

www.hazelcast.com@noctarius2k

Even With TTL!

www.hazelcast.com@noctarius2k

And Auto-Cleanup

www.hazelcast.com@noctarius2k

What Is Wrong?

www.hazelcast.com@noctarius2k

What Is Wrong?

O(n)5 mio

Entries

www.hazelcast.com@noctarius2k

It was a trap!

www.hazelcast.com@noctarius2k

Distributed Caching!

www.hazelcast.com@noctarius2k

www.hazelcast.com

Data Partitioning

www.hazelcast.com

Data Partitioning

www.hazelcast.com@noctarius2k

JCache?

www.hazelcast.com@noctarius2k

A Java Caching Standard!

www.hazelcast.com@noctarius2k

No need to ## care aboutProprietary Solutions

anymore!

www.hazelcast.com@noctarius2k

“Vendor Independent”

www.hazelcast.com@noctarius2k

http://technoodling.net/mili-power-crystal-battery-pack-review/

Terracotta /EHcache

OracleCoherence

Infinispan

JavaCollections

API

Hazelcast

JCache

Custom

www.hazelcast.com@noctarius2k

JCache Impementations

www.hazelcast.com@noctarius2k

JCache Impementations

Hazelcast

www.hazelcast.com@noctarius2k

JCache Impementations

Hazelcast Ehcache

www.hazelcast.com@noctarius2k

JCache Impementations

Hazelcast EhcacheInfinispan

www.hazelcast.com@noctarius2k

JCache Impementations

Hazelcast

Apache IgniteEhcache

Infinispan

www.hazelcast.com@noctarius2k

JCache Impementations

Hazelcast Coherence

Apache IgniteEhcache

Infinispan

www.hazelcast.com@noctarius2k

JCache Impementations

Hazelcast CoherenceInfinispanApache Ignite How Dare You Are To Call You JCache?

Ehcache

www.hazelcast.com@noctarius2k

Success!Feels like

www.hazelcast.com@noctarius2k

Demo Time

www.hazelcast.com@noctarius2k

// Ask the JCache API for implementationsCachingProvider cachingProvider = Caching.getCachingProvider();

Demo Time

www.hazelcast.com@noctarius2k

// Ask the JCache API for implementationsCachingProvider cachingProvider = Caching.getCachingProvider();

Demo Time

Caching.getCachingProvider(myClassLoader); Caching.getCachingProvider("c.h.c.CachingProvider");

www.hazelcast.com@noctarius2k

// Ask the JCache API for implementationsCachingProvider cachingProvider = Caching.getCachingProvider();

Demo Time

Caching.getCachingProvider(myClassLoader); Caching.getCachingProvider("c.h.c.CachingProvider");

www.hazelcast.com@noctarius2k

// Ask the JCache API for implementationsCachingProvider cachingProvider = Caching.getCachingProvider(); // Build cache scope, multiple can exist CacheManager cacheManager = cachingProvider.getCacheManager();

Demo Time

www.hazelcast.com@noctarius2k

// Ask the JCache API for implementationsCachingProvider cachingProvider = Caching.getCachingProvider(); // Build cache scope, multiple can exist CacheManager cacheManager = cachingProvider.getCacheManager();

Demo Time

cachingProvider.getCacheManager(myURI, myClassLoader)

www.hazelcast.com@noctarius2k

// Ask the JCache API for implementationsCachingProvider cachingProvider = Caching.getCachingProvider(); // Build cache scope, multiple can exist CacheManager cacheManager = cachingProvider.getCacheManager();// Configure the new cache Configuration<Integer, String> configuration = new MutableConfiguration<Integer, String>() .setTypes(Integer.class, String.class);

Demo Time

www.hazelcast.com@noctarius2k

// Ask the JCache API for implementationsCachingProvider cachingProvider = Caching.getCachingProvider(); // Build cache scope, multiple can exist CacheManager cacheManager = cachingProvider.getCacheManager();// Configure the new cache Configuration<Integer, String> configuration = new MutableConfiguration<Integer, String>() .setTypes(Integer.class, String.class); // Create the actual cache Cache<Integer, String> cache = cacheManager.createCache("name", configuration);

Demo Time

www.hazelcast.com@noctarius2k

// Ask the JCache API for implementationsCachingProvider cachingProvider = Caching.getCachingProvider(); // Build cache scope, multiple can exist CacheManager cacheManager = cachingProvider.getCacheManager();// Configure the new cache Configuration<Integer, String> configuration = new MutableConfiguration<Integer, String>() .setTypes(Integer.class, String.class); // Get the actual cache Cache<Integer, String> cache = cacheManager.getCache("name", Integer.class, String.class);

Demo Time

www.hazelcast.com@noctarius2k

// Configure the new cache Configuration<Integer, String> configuration = …;// Get the actual cache Cache<Integer, String> cache = cacheManager.getCache(…);

if (cache == null) { try { cache = cacheManager.createCache("name", configuration); } catch (CacheException e) { cache = cacheManager.getCache(…); } }

Demo Time

www.hazelcast.com@noctarius2k

<hazelcast xmlns="…"> <cache name="named"> <key-type="java.lang.Integer"/> <key-type="java.lang.String"/> </cache> </hazelcast>

Demo Time

www.hazelcast.com@noctarius2k

<hazelcast xmlns="…"> <cache name="named"> <key-type="java.lang.Integer"/> <key-type="java.lang.String"/> </cache> </hazelcast>

Demo Time

www.hazelcast.com@noctarius2k

<hazelcast xmlns="…"> <cache name="named"> <key-type="java.lang.Integer"/> <key-type="java.lang.String"/> </cache> </hazelcast>

Demo Time

www.hazelcast.com@noctarius2k

<hazelcast xmlns="…"> <cache name="named"> <key-type="java.lang.Integer"/> <key-type="java.lang.String"/> </cache> </hazelcast>

Demo Time

www.hazelcast.com@noctarius2k

// Ask the JCache API for implementationsCachingProvider cachingProvider = Caching.getCachingProvider(); // Build cache scope, multiple can exist CacheManager cacheManager = cachingProvider.getCacheManager();// Configure the new cache Configuration<Integer, String> configuration = new MutableConfiguration<Integer, String>() .setTypes(Integer.class, String.class); // Get the actual cache Cache<Integer, String> cache = cacheManager.getCache("name", Integer.class, String.class);

Demo Time

www.hazelcast.com@noctarius2k

I told you:Easy Peasy!

www.hazelcast.com@noctarius2k

Quick Shameless Plug :)Hazelcast!

www.hazelcast.com@noctarius2k

Hazelcast in 5 Facts• Java Collections API• Java Concurrency API

• Transparent Data Distribution• Drop-In Replacement

• Disruptively Simple(c) Rod Johnson (@springrod)

www.hazelcast.com@noctarius2k

Time to be Happy!

www.hazelcast.com@noctarius2k

Time to be Happy!

Apache License 2

www.hazelcast.com@noctarius2k

Time to be Happy!

www.hazelcast.org

www.hazelcast.com@noctarius2k

You can do it!

www.hazelcast.com@noctarius2k

Thank You!Any Questions?

@noctarius2k http://www.sourceprojects.org

http://github.com/noctarius

@hazelcast http://www.hazelcast.com http://www.hazelcast.org

http://github.com/hazelcast

www.hazelcast.com@noctarius2k

Thank You!Any Questions?

@noctarius2k http://www.sourceprojects.org

http://github.com/noctarius

@hazelcast http://www.hazelcast.com http://www.hazelcast.org

http://github.com/hazelcast

Free Hazelcast T-Shirthttp://bit.ly/tshirtcast

Recommended