HAZELCAST DISTRIBUTED DATA STRUCTURES FOR JAVA WHO AM I Fuad - - PowerPoint PPT Presentation

hazelcast
SMART_READER_LITE
LIVE PREVIEW

HAZELCAST DISTRIBUTED DATA STRUCTURES FOR JAVA WHO AM I Fuad - - PowerPoint PPT Presentation

HAZELCAST DISTRIBUTED DATA STRUCTURES FOR JAVA WHO AM I Fuad Malikov @fuadm Hazelcast Co-founder Java Developer since 2005 Leading Hazelcast Technical Operations COMPANY: HAZELCAST Founded in 2008 Open Source Business Model Head Quartered


slide-1
SLIDE 1

HAZELCAST

DISTRIBUTED DATA STRUCTURES FOR JAVA

slide-2
SLIDE 2

WHO AM I

Fuad Malikov @fuadm Hazelcast Co-founder Java Developer since 2005 Leading Hazelcast Technical Operations

slide-3
SLIDE 3

COMPANY: HAZELCAST

Founded in 2008 Open Source Business Model Head Quartered in Palo Alto, CA Distributed Team with R&D mainly in Europe $14M+ Total Investment

slide-4
SLIDE 4

PRODUCT: HAZELCAST

In-Memory DataGrid Open Source - Apache License 2.0 In-Mempory Distributed Data Store Distributed Messaging Distributed Computation NoSQL

slide-5
SLIDE 5

WHO USES HAZELCAST?

and many more ...

slide-6
SLIDE 6

USECASES

slide-7
SLIDE 7
slide-8
SLIDE 8
slide-9
SLIDE 9
slide-10
SLIDE 10
slide-11
SLIDE 11
slide-12
SLIDE 12

ALTERNATIVES?

Oracle Coherence IBM eXtreme Scale VMware Gemfire Gridgain Redhat Infinispan Terracotta Gigaspaces

slide-13
SLIDE 13

WHY HAZELCAST?

Scale-out Computing Fast Application Performance Resilience Programming Model

slide-14
SLIDE 14

FEATURES

Java Collection API Map, Queue, Set, List, +MultiMap, +ReplicatedMap Topic (PubSub) Ring Buffer Java Concurrency API Lock, ExecutorService, AtomicLong, Semaphore, CountDownLatch, Entry Processor, Query, Map Reduce, Aggregations Transactions Custom Serialization Native Memory support (off-heap) Native client: C#, C++, Java, REST, memcached Hibernate 2nd Level Cache Web Session Replication

slide-15
SLIDE 15

CACHE AS A SERVICE

slide-16
SLIDE 16

EASY API

// Creating a new Hazelcast node HazelcastInstance hz = Hazelcast.newHazelcastInstance(); // Getting a Map, Queue, Topic, ... Map map = hz.getMap("my-map"); Queue queue = hz.getQueue("my-queue"); ITopic topic = hz.getTopic("my-topic"); //Creating a Hazelcast Client HazelcastInstance client = Hazelcast.newHazelcastClient(); // Shutting down the node hz.shutdown();

slide-17
SLIDE 17

HOW DOES IT WORK?

slide-18
SLIDE 18

DATA PARTITIONING (1/2)

Multiple partitions per node Consistent Hashing: Controlled partitioning: "key@partitionkey", c.h.c.PartitionAware Possibility to find key owner for every key Support for Near-Caching and executions on key owner Automatic Fault-Tolerance Synchronous and Asynchronous backups Define sync / async backup counts

partition_id = hash(serialize(key)) % partitionCount ;

slide-19
SLIDE 19

With 4 cluster nodes every server holds 1/4 real data and 1/4 of backups

DATA PARTITIONING (2/2)

slide-20
SLIDE 20

A HAZELCAST NETWORK

slide-21
SLIDE 21

HAZELCAST IN NUMBERS

Default partition count 271 Biggest cluster 600+ nodes 1 TB in-memory data Handles 1M+/sec topic messages Native Memory (Off-Heap) support for low GC overhead

slide-22
SLIDE 22

COMMUNITY VS. ENTERPRISE

Feature Community Enterprise Java Collection API X X Java Concurrency API X X JCache API X X Map Reduce / Aggregations X X HD Memory Store (off-heap) X Advanced Security X Native Clients (C++ / C#) X Management Center X

slide-23
SLIDE 23

HEAP VS HD MEMORY STORE

slide-24
SLIDE 24

CODE SAMPLES

slide-25
SLIDE 25

EASY TO UNITTEST

public class SomeTestCase { private HazelcastInstance[] instances; @Before public void before() throws Exception { // Multiple instances on the same JVM instances = new HazelcastInstance[2]; instances[0] = Hazelcast.newHazelcastInstance(); instances[1] = Hazelcast.newHazelcastInstance(); } @After public void after() throws Exception { Hazelcast.shutdownAll(); } }

slide-26
SLIDE 26

SERIALIZATION

// java.io.Serializable public class User implements Serializable {} // or java.io.Externalizable public class User implements Externalizable {} // or (com.hazelcast.nio.serialization).DataSerializable public class User implements DataSerializable {} // or (com.hazelcast.nio.serialization).DataSerializable public class User implements IdentifiedDataSerializable {} // or new in Hazelcast 3 (multi version support) Portable public class User implements Portable {} //Support for Pluggable Custom Serializer

slide-27
SLIDE 27

MAP

interface com.hazelcast.core.IMap<K, V> extends java.util.Map, java.util.ConcurrentMap HazelcastInstance hz = getHazelcastInstance(); //java.util.concurrent.ConcurrentMap implementation IMap<String, User> hzMap = hz.getMap("users"); hzMap.put("Peter", new User("Peter", "Veentjer")); hzMap.putIfAbsent("Peter", new User("Peter", "Veentjer")); //Distributed Lock hzMap.lock("Peter"); User peter = map.get("Peter");

slide-28
SLIDE 28

LIST

interface com.hazelcast.core.IList<E> extends java.util.List HazelcastInstance hz = getHazelcastInstance(); //java.util.List implementation L ist<User> l ist = hz.getList("users"); l ist.add(new User("Peter", "Veentjer")); User peter = list.get(0);

slide-29
SLIDE 29

QUEUE

interface com.hazelcast.core.IQueue<E> extends java.util.concurrent.BlockingQueue HazelcastInstance hz = getHazelcastInstance(); //java.util.concurrent.BlockingQueue implementation IQueue<Task> queue = hz.getQueue("tasks"); queue.offer(newTask()); queue.offer(newTask(), 500, TimeUnit.MILLISECONDS); Task task = queue.poll(); Task task = queue.poll(100, TimeUnit.MILLISECONDS); Task task = queue.take();

slide-30
SLIDE 30

LOCK (1/3)

interface com.hazelcast.core.ILock extends java.util.concurrent.locks.Lock

slide-31
SLIDE 31

LOCK (2/3)

HazelcastInstance hz = getHazelcastInstance(); // Distributed Reentrant L

  • ck l
  • ck = hz.getLock("myLock");

l

  • ck.lock();

try { // Do something } finally { l

  • ck.unlock();

}

slide-32
SLIDE 32

LOCK (3/3)

HazelcastInstance hz = getHazelcastInstance(); // Map (Row-)locks IMap<String, User> map = hz.getMap("users"); map.lock("Peter"); try { // Do something with Peter } finally { map.unlock("Peter"); }

slide-33
SLIDE 33

TOPIC / PUBSUB

public class Example implements MessageListener<String> { public void sendMessage { HazelcastInstance hz = getHazelcastInstance(); ITopic<String> topic = hz.getTopic("topic"); topic.addMessageListener(this); topic.publish("Hello World"); } @Override public void onMessage(Message<String> message) { System.out.println("Got message: " + message.getMessageObject()); } }

slide-34
SLIDE 34

EXECUTORSERVICE

public interface com.hazelcast.core.IExecutorService extends java.util.concurrent.ExecutorService HazelcastInstance hz = getHazelcastInstance(); //java.util.concurrent.ExecutorService implementation IExecutorService es = hz.getExecutorService("name"); es.executeOnAllMembers(buildRunnable()); es.executeOnKeyOwner(buildRunnable(), "Peter"); es.execute(buildRunnable()); Map<..> futures = es.submitToAllMembers(buildCallable()); Future<..> future = es.submitToKeyOwner(buildCallable(), "Peter"); es.submitToAllMembers(buildCallable(), buildCallback()); es.submitToKeyOwner(buildCallable(), "Peter", buildCallback());

slide-35
SLIDE 35

MORE ADVANCED FEATURES

slide-36
SLIDE 36

ADVANCED FEATURES

Secondary Indexes and SQL-Like Query, Write-Behind / Write-Through persistence Read-Through (if key not loaded use MapLoader) Local & XA Transactions EntryListeners / EntryProcessors Map Reduce / Aggregators Hibernate 2nd Level Cache HTTP Session Clustering Automatic eviction Controlled partitioning and many more ...

slide-37
SLIDE 37

CODE SAMPLES

slide-38
SLIDE 38

INDEXING

IMap<String, User> map = Hazelcast.getMap("users"); map.addIndex("age", true); // ordered map.addIndex("active", false); // not ordered <map name="employees"> ... <indexes> <index ordered="true">age</index> <index ordered="false">name</index> </indexes> </map>

slide-39
SLIDE 39

DISTRIBUTED SQL-LIKE QUERIES

HazelcastInstance hz = getHazelcastInstance(); IMap<String, User> map = hz.getMap("users"); Predicate predicate = new SqlPredicate("active AND age <= 30"); Set<User> users = map.values(predicate); Set<Entry<String, User>> entries = map.entrySet(predicate);

slide-40
SLIDE 40

PERSISTENCY: MAPLOADER / MAPSTORE

public class MapStorage implements MapStore<String, User>, MapLoader<String, User> { // Some methods missing ... @Override public User load(String key) { return loadValueDB(key); } @Override public Set<String> loadAllKeys() { return loadKeysDB(); } @Override public void delete(String key) { deleteDB(key); } @Override public void store(String key, User value) { storeToDatabase(key, value); } } <map name="users"> <map-store enabled="true"> <class-name>com.hazelcast.example.MapStorage</class-name> <write-delay-seconds>0</write-delay-seconds> </map-store> </map>

slide-41
SLIDE 41

TRANSACTIONS

HazelcastInstance hz = getHazelcastInstance(); TransactionContext context = hz.newTransactionContext(); context.beginTransaction(); TransactionalMap map = context.getMap("default"); TransactionalQueue queue = context.getQueue("default"); try { Tweet tweet = (Tweet) queue.poll(); processTweet(tweet); map.put(buildKey(tweet), tweet); context.commitTransaction(); } catch (Exception e) { context.rollbackTransaction(); }

slide-42
SLIDE 42

Force location of corresponding data in the same partition by providing a special partition key

CONTROLLED PARTITIONING

HazelcastInstance hz = getHazelcastInstance(); Map users = hz.getMap("users"); users.put("Peter@Peter", new User("Peter", "Veentjer")); Map friends = hz.getMap("friends"); friends.put("Chris@Peter", new User("Christoph", "Engelbert")); friends.put("Nils@Peter", new User("Fuad", "Malikov")); //All three will be stored on the same partition

slide-43
SLIDE 43

REPLICATED MAP

HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(); Map<String, Customer> customers = hazelcastInstance .getReplicatedMap("customers"); customers.put( "1", new Customer( "Joe", "Smith" ) ); customers.put( "2", new Customer( "Ali", "Selam" ) ); customers.put( "3", new Customer( "Avi", "Noyan" ) ); Collection<Customer> colCustomers = customers.values(); for ( Customer customer : colCustomers ) { // process customer }

slide-44
SLIDE 44

JCACHE

slide-45
SLIDE 45

JCACHE (1/2)

<dependency> <groupid>javax.cache</groupid> <artifactid>cache-api</artifactid> <version>1.0.0</version> </dependency> // Retrieve the CachingProvider which is automatically baced by // the chosen Hazelcast server or client provider CachingProvider cachingProvider = Caching.getCachingProvider(); // Create a CacheManager CacheManager cacheManager = cachingProvider.getCacheManager(); // Cache<String, String> cache = cacheManager // .getCache( name, String.class, String.class ); // Create a simple but typesafe configuration for the cache CompleteConfiguration<String, String> config = new MutableConfiguration<String, String>() .setTypes( String.class, String.class );

slide-46
SLIDE 46

JCACHE (2/2)

// Create and get the cache Cache<String, String> cache = cacheManager .createCache( "example", config ); // Alternatively to request an already existing cache // Cache<String, String> cache = cacheManager // .getCache( name, String.class, String.class ); // Put a value into the cache cache.put( "world", "Hello World" ); // Retrieve the value again from the cache String value = cache.get( "world" ); // Print the value 'Hello World' System.out.println( value );

slide-47
SLIDE 47

MAP REDUCE

HazelcastInstance hz = getHazelcastInstance(); Map users = hz.getMap("users"); JobTracker tracker = hz.getJobTracker("default"); KeyValueSource source = KeyValueSource.fromMap(users); Job job = tracker.newJob(source); ICompleteFuture future = job.mapper(new MyMapper()) .reducer(new MyReducer()) .submit(); Map result = future.get();

slide-48
SLIDE 48

AGGREGATIONS

HazelcastInstance hz = getHazelcastInstance(); Map users = hz.getMap("users"); int sum = users.aggregate( Supplier.all((user) -> user.getSalary()), Aggregations.longSum() );

slide-49
SLIDE 49

NEW IN HAZELCAST 3.5

slide-50
SLIDE 50

NEW IN HAZELCAST

Ring Buffers Client Protocol Cluster Quorum

slide-51
SLIDE 51

RING BUFFERS

slide-52
SLIDE 52

@fuadm, @hazelcast hazelcast@googlegroups.com http://www.hazelcast.com http://github.com/hazelcast/hazelcast

THANK YOU!

ANY QUESTIONS?

We are hiring > http://hazelcast.com/company/careers/

Images: www.clipartist.info, Gnome Nebula Theme, KDE theme