Brown Bag Lunch sur Hazelcast

30
HAZELCAST OU LE CLUSTERING FACILE ! BBL – février 2014

description

Présentation rapide de Hazelcast, faite au cours d'un Brown Bag Lunch

Transcript of Brown Bag Lunch sur Hazelcast

Page 1: Brown Bag Lunch sur Hazelcast

HAZELCAST OU

LE CLUSTERING FACILE !

BBL – février 2014

Page 2: Brown Bag Lunch sur Hazelcast

A propos…

!  Sylvain Wallez !  Architecte et dev expert freelance

Web/Java/Scala !  2014 - Fondateur de Actoboard !  2011 - Backend architect de Sigfox !  2008 - CTO de Goojet/Scoop.it !  2006 - Backend architect Joost !  2003 - Premier VP Apache français !  2000 - Cofondateur & CTO Anyware Technologies

[email protected] http://bluxte.net Twitter: @bluxte

Page 3: Brown Bag Lunch sur Hazelcast

Une appli distribuée en 5 lignes !

Mise en bouche

Page 4: Brown Bag Lunch sur Hazelcast

Mise en bouche

!  La Map classique

public static void main(String[] args) { Map<String, String> map = new HashMap<>(); map.put("hello", "world"); String value = map.get("hello");}

Page 5: Brown Bag Lunch sur Hazelcast

Mise en bouche

!  La ConcurrentMap

public static void main(String[] args) { ConcurrentMap<String, String> map = new ConcurrentHashMap<>(); map.put("hello", "world"); String value = map.get("hello"); String previous = map.putIfAbsent("goodbye", "marylou");}

Page 6: Brown Bag Lunch sur Hazelcast

Mise en bouche

!  La ConcurrentMap distribuée

public static void main(String[] args) { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); ConcurrentMap<String, String> map = hz.getMap("mymap"); map.put("hello", "world"); String value = map.get("hello"); String previous = map.putIfAbsent("goodbye", "marylou");}

Page 7: Brown Bag Lunch sur Hazelcast

Mise en bouche

Démo

Page 8: Brown Bag Lunch sur Hazelcast

Mais que vient-on de voir ?

Hazelcast features

Page 9: Brown Bag Lunch sur Hazelcast

Buzzword bingo !

!  In-memory data grid !  Open source, Apache Licence !  P2P elastic cache !  Distributed event bus !  NoSQL datastore !  Cluster coordination !  Distributed computing

Page 10: Brown Bag Lunch sur Hazelcast

La concurrence

!  Oracle Coherence !  IBM Extreme Scale !  VMware Gemfire !  Gigaspaces !  JBoss Infinispan !  Gridgain !  Terracotta

Page 11: Brown Bag Lunch sur Hazelcast

In-memory data grid

!  La Map classique, plus des bonus

HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IMap<String, String> map = hz.getMap("mymap"); map.put("hello", "world"); String value = map.get("hello"); Future<String> future = map.getAsync("hello"); map.put("goodbye", "marylou", 10, TimeUnit.MINUTES); Set<Entry<String, String>> set = map.entrySet(new Predicate<String, String>() { public boolean apply(Entry<String, String> entry) { return entry.getKey().contains("z"); } });

Asynchrone

Expiration

Filtrage « in grid »

Page 12: Brown Bag Lunch sur Hazelcast

P2P elastic cache

!  Partitionnement et réplication automatiques

Page 13: Brown Bag Lunch sur Hazelcast

P2P elastic cache

!  Ajout dynamique de nouveaux noeuds

New!

Multicast

Page 14: Brown Bag Lunch sur Hazelcast

P2P elastic cache

!  Redistribution des données

Page 15: Brown Bag Lunch sur Hazelcast

P2P elastic cache

!  Redistribution des données

Page 16: Brown Bag Lunch sur Hazelcast

P2P elastic cache

!  Redistribution des données

Page 17: Brown Bag Lunch sur Hazelcast

P2P event bus

!  Les topics : broadcast à tous les listeners

ITopic<String> topic = hz.getTopic("alerts"); topic.addMessageListener(new MessageListener<String>() { public void onMessage(Message<String> message) { println("Received " + message.getMessageObject() + " from " + message.getPublishingMember()); } });

Nœud d’origine du message

Page 18: Brown Bag Lunch sur Hazelcast

P2P event bus

!  Les queues

(Aussi en asynchrone avec poll() et les listeners)

BlockingQueue<String> queue = hz.getQueue("jobs"); queue.offer("Make me a sandwich");

BlockingQueue<String> queue = hz.getQueue("jobs"); while(true) { String job = queue.take(); println("Now working on " + job); }

Page 19: Brown Bag Lunch sur Hazelcast

NoSQL datastore

!  Stockage persistant

Page 20: Brown Bag Lunch sur Hazelcast

NoSQL datastore

!  La Map « interrogeable »

IMap<Long, Employee> map = hz.getMap("employee"); map.addIndex("active", true); map.addIndex("age", true); Collection<Employee> employees = map.values(new SqlPredicate("active AND age < 30"));

Sous ensemble de SQL sur les propriétés JavaBean

Indexation des propriétés

Page 21: Brown Bag Lunch sur Hazelcast

Cluster coordination

!  Compteurs distribués

IAtomicLong reqCount = hz.getAtomicLong("users"); // Start request long count = reqCount.incrementAndGet(); try { // Do some stuff println("There are " + count + " request in progress"); } finally { // End request reqCount.decrementAndGet(); }

Page 22: Brown Bag Lunch sur Hazelcast

Cluster coordination

!  Locks distribués (à utiliser avec parcimonie)

Lock lock = hz.getLock("maintenance_mode"); lock.lock(); try { // There can be only one in the cluster } finally { lock.unlock(); }

ILock lock = hz.getLock("maintenance_mode"); lock.lock(10, TimeUnit.SECONDS); try { // There can be only one in the cluster } finally { lock.unlock(); }

Protection : durée limitée

Page 23: Brown Bag Lunch sur Hazelcast

Distributed computing

!  Un ExecutorService distribué

ExecutorService executor = hz.getExecutorService("compute"); Runnable job = null; Callable<String> jobWithResult = null; executor.execute(job); Future<String> future = executor.submit(jobWithResult);

Page 24: Brown Bag Lunch sur Hazelcast

Distributed computing

!  Un ExecutorService distribué ! Fonctions avancées de IExecutorService

IExecutorService executor = hz.getExecutorService("compute");Runnable job = null;Callable<String> jobWithResult = null;executor.executeOnKeyOwner(job, 42);Member member = hz.getPartitionService().getPartition(42).getOwner();println("Submitting to IP address " + member.getInetSocketAddress());executor.submitToMember(jobWithResult, member, new ExecutionCallback<String>() { public void onResponse(String response) { println("Result is " + response); } public void onFailure(Throwable t) { println("Job failed"); } }); }

Data locality

Choix explicite du noeud

Callback asynchrone

Page 25: Brown Bag Lunch sur Hazelcast

Administration

Page 26: Brown Bag Lunch sur Hazelcast

Administration

!  JMX !  API de statistiques sur Cluster et Member !  Webapp Management Center

Page 27: Brown Bag Lunch sur Hazelcast

Management Center

Page 28: Brown Bag Lunch sur Hazelcast

Management Center

Page 29: Brown Bag Lunch sur Hazelcast

Management Center

Page 30: Brown Bag Lunch sur Hazelcast

Merci !

Questions ?

Réponses !