devoxx uk 2014 high performance in-memory java with open source
DESCRIPTION
www.hazelcast.comTRANSCRIPT
![Page 1: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/1.jpg)
@dbrimley #DevoxxHazelcast
High Performance In-Memory Java with Open Source
David Brimley @dbrimley http://blog.hazelcast.com/ http://www.hazelcast.org/
![Page 2: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/2.jpg)
@dbrimley #DevoxxHazelcast
Who is this guy?
• Senior Solutions Architect for Hazelcast.
• 17 Years Java Development.
• Started out as a Cobol Programmer in 1988.
• Learnt to code Basic on a Vic-20 and BBC Model B.
• Oracle Coherence and Pivotal Gemfire.
![Page 3: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/3.jpg)
@dbrimley #DevoxxHazelcast
In Memory Java
• High Performance In Memory Java? It’s an IMDG!
• Getting to grips with Hazelcast, a tour of features.
• Some IMDG Tips!
![Page 4: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/4.jpg)
@dbrimley #DevoxxHazelcast
In Memory Java
• It’s 2 things really, the 2 C.
• Cache
• Compute
• The Magic is the D you stick in front…Distributed!
• DCache + DCompute = IMDG!
![Page 5: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/5.jpg)
@dbrimley #DevoxxHazelcast
Evolution of IMDG
CACHE IN ONE PROCESS - A MAP, AGGHH OOM!
![Page 6: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/6.jpg)
@dbrimley #DevoxxHazelcast
Evolution of IMDG
CACHE IN ONE PROCESS - WITH EVICTION
![Page 7: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/7.jpg)
@dbrimley #DevoxxHazelcast
Evolution of IMDG
DISTRIBUTED CACHE
![Page 8: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/8.jpg)
@dbrimley #DevoxxHazelcast
Evolution of IMDG
DISTRIBUTED CACHE
![Page 9: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/9.jpg)
@dbrimley #DevoxxHazelcast
Evolution of IMDG
BIG DATA IMDG
![Page 10: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/10.jpg)
@dbrimley #DevoxxHazelcast
Qualities of an IMDG
• It should be easy to scale, vertically and horizontally.
• It should be fault tolerant.
• It should be performant.
• It should have a easy to understand API.
![Page 11: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/11.jpg)
@dbrimley #DevoxxHazelcast
Enter Hazelcast! • Java Collections & Queues - Distributed!
• Java Concurrency - Distributed!
• Persist to and Read from from Anything! (RDBMS,File,Hadoop,Cassandra,MongoDB)
• Predicate and SQL like queries!
• Topics(Pub/Sub)
• Rich Event Callbacks
![Page 12: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/12.jpg)
@dbrimley #DevoxxHazelcast
<dependency> <groupId>com.hazelcast</groupId> <artifactId>hazelcast</artifactId> <version>3.2.2</version> </dependency>
1. Starting a Hazelcast Cluster Node
![Page 13: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/13.jpg)
@dbrimley #DevoxxHazelcast
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
2. Starting a Hazelcast Cluster Node
![Page 14: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/14.jpg)
@YourTwitterHandle @dbrimley #DevoxxHazelcast
![Page 15: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/15.jpg)
@dbrimley #DevoxxHazelcast
Distributed Compute • Executors
• EntryProcessor
• MapReduce
![Page 16: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/16.jpg)
@dbrimley #DevoxxHazelcast
Executor can run anywhere • IExecutorService
• Runnable or Callable
• Targeted execution in the grid (keys,members)
![Page 17: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/17.jpg)
@dbrimley #DevoxxHazelcast
HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IExecutorService executor = hz.getExecutorService(“myEService"); executor.execute(new EchoTask("foo"));
2. Java Executor, but Distributed!
![Page 18: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/18.jpg)
@dbrimley #DevoxxHazelcast
EntryProcessor • Execute your code on an entry in an atomic way.
• You do not need any explicit lock on entry.
• Runs via IMap.
![Page 19: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/19.jpg)
@dbrimley #DevoxxHazelcast
/** * Applies the user defined EntryProcessor to the entry mapped by the key. * Returns the the object which is result of the process() method of EntryProcessor. */ Object executeOnKey(K key, EntryProcessor entryProcessor);
EntryProcessor via IMap
![Page 20: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/20.jpg)
@dbrimley #DevoxxHazelcast
MapReduce • New in 3.2
• Hadoop like API.
• Aggregators in 3.3
• Scheduled Tasks in 3.4
![Page 21: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/21.jpg)
@dbrimley #DevoxxHazelcast
IMap<String,String> map = hazelcastInstance.getMap("articles"); KeyValueSource<String,String> source = KeyValueSource.fromMap(map); Job<String, String> job = jobTracker.newJob( source ); ICompletableFuture<Map<String, Long>> future = job .mapper( new TokenizerMapper() ) .combiner( new WordCountCombinerFactory() ) .reducer( new WordCountReducerFactory() ) .submit();
MapReduce
![Page 22: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/22.jpg)
@dbrimley #DevoxxHazelcast
Persist and Read from anywhere. • Implement a MapStore interface.
• Configure your Map.
• Cache misses will read through to the store.
• Cache updates can persist to store (sync/async).
![Page 23: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/23.jpg)
@dbrimley #DevoxxHazelcast
<map name="aDistributedMap"> <map-store enabled="true"> <class-name>com.company.YourMapStore</class-name> <write-delay-seconds>30</write-delay-seconds> </map-store> <indexes> <index ordered="true">aValueProperty</index> </indexes> </map>
2. Configure (in XML,Spring or API)
![Page 24: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/24.jpg)
@dbrimley #DevoxxHazelcast
public class UserMapStore implements MapStore<Integer, User> { public void store(Integer userKey, User user) { userDao.insertUser(user); } public User load(Integer userKey) { return userDao.getUser(userKey); } …… (more methods like delete, loadAll)
2. Implement MapStore
![Page 25: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/25.jpg)
@dbrimley #DevoxxHazelcast
We like standards. • Greg Luck, Hazelcast CTO is JSR107 co-spec lead.
• Hazelcast will be JSR107 compliant this summer.
• https://github.com/hazelcast/hazelcast/tree/jcache-preview
![Page 26: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/26.jpg)
@YourTwitterHandle @dbrimley #DevoxxHazelcast
![Page 27: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/27.jpg)
@dbrimley #DevoxxHazelcast
Some IMDG Advice • Don’t force in your RDBMS schema.
• Do you really need that transaction?
• Execute near the data.
• Use the right Serialisation interface.
• Tune your JVM.
![Page 28: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/28.jpg)
@YourTwitterHandle #DVXFR14{session hashtag} @dbrimley #DevoxxHazelcast
![Page 29: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/29.jpg)
@dbrimley #DevoxxHazelcast
Powerful tool for many Use Cases • Unscalable NoSQL or RDBMS fix.
• Compute Intensive Tasks
• Web Session Replication
• HA Services
• WAN Replication
![Page 30: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/30.jpg)
@dbrimley #DevoxxHazelcast
Get Coding! • hazelcast.org - for open source and downloads
• hazelcast.com - for pro support,papers & webinars
• github.com/hazelcast for sources
• github.com/hazelcast/hazelcast-code-samples
• follow me on twitter @dbrimley
![Page 31: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/31.jpg)
@YourTwitterHandle #DVXFR14{session hashtag} @dbrimley #DevoxxHazelcast
![Page 32: Devoxx UK 2014 High Performance In-Memory Java with Open Source](https://reader033.vdocuments.us/reader033/viewer/2022060108/554f7583b4c9052a518b46c0/html5/thumbnails/32.jpg)
@dbrimley #DevoxxHazelcast
Thanks / Creative Commons
• Presentation Template — Guillaume LaForge • The Queen — A prestigious heritage with some
inspiration from The Sex Pistols and funny Devoxxians • Girl with a Balloon — Banksy
• Tube — Michael Keen