SlideShare ist ein Scribd-Unternehmen logo
1 von 62
HAZELCAST

                         Art of Data Distribution
                          open source, in-memory data grid




                          Talip Ozturk
                           @oztalip




Tuesday, October 2, 12
Who uses Hazelcast?




                         and many more....
                         Every sec one Hazelcast instance starts around the
                         globe




Tuesday, October 2, 12
9th Fastest Growing Skill




Tuesday, October 2, 12
Keywords


                         In-memory data grid
                         Distributed(Elastic) Cache
                         NoSQL
                         Clustering, Scalability, Partitioning
                         Cloud Computing



Tuesday, October 2, 12
Map



                 import java.util.Map;
                 import java.util.HashMap;

                 Map map = new HashMap();
                 map.put(“1”, “value”);
                 map.get(“1”);




Tuesday, October 2, 12
Concurrent Map



                 import java.util.Map;
                 import java.util.concurrent.*;

                 Map map = new ConcurrentHashMap();
                 map.put(“1”, “value”);
                 map.get(“1”);




Tuesday, October 2, 12
Distributed Map



                 import java.util.Map;
                 import com.hazelcast.core.Hazelcast;

                 Map map = Hazelcast.getMap(“mymap”);
                 map.put(“1”, “value”);
                 map.get(“1”);




Tuesday, October 2, 12
Why Hazelcast?




                                  To build highly
                                  available and
                                  scalable applications




Tuesday, October 2, 12
Alternatives




Tuesday, October 2, 12
Difference



                         License/Cost
                         Feature-set
                         Ease of use
                         Main focus (distributed map, tuple space,
                         cache, processing vs. data)
                         Light/Heavy weight

Tuesday, October 2, 12
HAZELCAST




Tuesday, October 2, 12
Should be free!




                         Apache License




Tuesday, October 2, 12
Lightweight without any dependency




                         1.7 MB jar




Tuesday, October 2, 12
Introducing Hazelcast



                         Map, queue, set, list, lock, semaphore, topic and
                         executor service
                         Native Java, C#, REST and Memcache Interfaces
                         Cluster info and membership events
                         Dynamic clustering, backup, fail-over
                         Transactional and secure


Tuesday, October 2, 12
Use-cases

                         Scale your application
                         Share data across cluster
                         Partition your data
                         Send/receive messages
                         Balance the load
                         Process in parallel on many JVM


Tuesday, October 2, 12
Demo



Tuesday, October 2, 12
Where is the Data?



Tuesday, October 2, 12
Data Partitioning in a Cluster

                  Fixed number of partitions (default 271)
                  Each key falls into a partition
                  partitionId = hash(keyData)%PARTITION_COUNT

                  Partition ownerships are reassigned upon membership change

                           A                B                C




Tuesday, October 2, 12
New Node Added



                         A   B    C   D




Tuesday, October 2, 12
Migration



                         A   B   C   D




Tuesday, October 2, 12
Migration



                         A   B   C   D




Tuesday, October 2, 12
Migration



                         A   B   C   D




Tuesday, October 2, 12
Migration



                         A   B   C   D




Tuesday, October 2, 12
Migration



                         A   B   C   D




Tuesday, October 2, 12
Migration



                         A   B   C   D




Tuesday, October 2, 12
Crash
                 Migration Complete



                         A   B           C   D




Tuesday, October 2, 12
Node Crashes



                         A   B           C   D
                                 Crash




Tuesday, October 2, 12
Restoring Backups



                         A   B           C   D
                                 Crash




Tuesday, October 2, 12
Restoring Backups



                         A   B           C   D
                                 Crash




Tuesday, October 2, 12
Restoring Backups



                         A   B           C   D
                                 Crash




Tuesday, October 2, 12
Restoring Backups



                         A   B           C   D
                                 Crash




Tuesday, October 2, 12
Restoring Data from Backup



                         A   B           C    D
                                 Crash




Tuesday, October 2, 12
Data is Recovered from backup



                         A   B           C       D
                                 Crash




Tuesday, October 2, 12
Backup for Recovered Data



                         A   B           C   D
                                 Crash




Tuesday, October 2, 12
Backup for Recovered Data



                         A   B           C   D
                                 Crash




Tuesday, October 2, 12
Backup for Recovered Data



                         A   B           C   D
                                 Crash




Tuesday, October 2, 12
All Safe



                            A   C   D




Tuesday, October 2, 12
Node Types



Tuesday, October 2, 12
Topology




                         Native Client:
                           HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);


                         Lite Member:
                           -Dhazelcast.lite.member=true




Tuesday, October 2, 12
Hazelcast
                         Enterprise


Tuesday, October 2, 12
Community vs Enterprise



                         Enterprise =
                         Community +
                         Elastic Memory + Security + Man. Center




Tuesday, October 2, 12
Elastic Memory is OFF-HEAP storage


                     -XX:MaxDirectMemorySize=60G ...
                     hazelcast.elastic.memory.enabled to true.
                     hazelcast.elastic.memory.total.size
                     hazelcast.elastic.memory.chunk.size
                         Default chunk size is 1. Chunk size has to be power of 2 such as 1, 2, 4 and 8.


                     <hazelcast>
                         ...
                         <map name="default">
                             ...
                             <storage-type>OFFHEAP</storage-type>
                         </map>
                     </hazelcast>




Tuesday, October 2, 12
JAAS based Security

                         Credentials
                         Cluster Login Module
                         Cluster Member Security
                         Native Client Security
                              Authentication
                              Authorization
                              Permission




Tuesday, October 2, 12
Code Samples



Tuesday, October 2, 12
Hazelcast


                         Hazelcast is thread safe
                             Map<String, Employee> = Hazelcast.getMap(“employees”);
                             List<Users> = Hazelcast.getList(“users”);



                         Many instances on the same JVM
                             Config config = new Config();
                             HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config)
                             HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config)


                         All objects must be serializable
                             class Employee implements java.io.Serializable
                              //better
                             class Employee implements com.hazelcast.nio.DataSerializable

Tuesday, October 2, 12
Cluster Interface



                 import com.hazelcast.core.*;
                 import java.util.Set;

                 Cluster cluster = Hazelcast.getCluster();
                 cluster.addMembershipListener(listener);

                 Member localMember = cluster.getLocalMember();
                 System.out.println (localMember.getInetAddress());

                 Set<Member> setMembers = cluster.getMembers();




Tuesday, October 2, 12
Distributed Map



                 import com.hazelcast.core.*;
                 import java.util.ConcurrentMap;

                 Map<String, Customer> map = Hazelcast.getMap("customers");
                 map.put ("1", customer);
                 Customer c = map.get("1");

                 //ConcurrentMap methods
                 map.putIfAbsent ("2", new Customer(“Chuck Norris”));
                 map.replace ("3", new Customer(“Bruce Lee”));




Tuesday, October 2, 12
Distributed Queue

                 import com.hazelcast.core.Hazelcast;
                 import java.util.concurrent.BlockingQueue;
                 import java.util.concurrent.TimeUnit;

                 BlockingQueue<Task> queue = Hazelcast.getQueue(“tasks");

                 queue.offer(task);
                 Task t = queue.poll();

                 //Timed blocking Operations
                 queue.offer(task, 500, TimeUnit.MILLISECONDS)
                 Task t = queue.poll(5, TimeUnit.SECONDS);

                 //Indefinitely blocking Operations
                 queue.put(task)
                 Task t = queue.take();




Tuesday, October 2, 12
Distributed Lock

                 import com.hazelcast.core.Hazelcast;
                 import java.util.concurrent.locks.Lock;

                 Lock mylock = Hazelcast.getLock(mylockobject);
                 mylock.lock();
                 try {
                 // do something
                 } finally {
                       mylock.unlock();
                 }

                 //Lock on Map
                 IMap<String, Customer> map = Hazelcast.getMap("customers");
                 map.lock("1");
                 try {
                 // do something
                 } finally {
                       map.unlock("1");
                 }




Tuesday, October 2, 12
Distributed Topic


                import com.hazelcast.core.*;

                public class Sample implements MessageListener {
                   public static void main(String[] args) {
                      Sample sample = new Sample();
                      ITopic<String> topic = Hazelcast.getTopic ("default");
                      topic.addMessageListener(sample);
                      topic.publish ("my-message-object");
                   }
                   public void onMessage(Object msg) {
                      System.out.println("Got msg :" + msg);
                   }
                }




Tuesday, October 2, 12
Distributed Events

                import com.hazelcast.core.*;

                public class Sample implements EntryListener {
                    public static void main(String[] args) {
                        Sample sample = new Sample();
                        IMap map = Hazelcast.getMap ("default");
                        map.addEntryListener (sample, true);
                        map.addEntryListener (sample, "key");
                    }
                    public void entryAdded(EntryEvent event) {
                        System.out.println("Added " + event.getKey() + ":" +
                                                                         event.getValue());
                    }
                    public void entryRemoved(EntryEvent event) {
                        System.out.println("Removed " + event.getKey() + ":" +
                                                                         event.getValue());
                    }
                    public void entryUpdated(EntryEvent event) {
                        System.out.println("Updated " + event.getKey() + ":" +
                                                                         event.getValue());
                    }
                }




Tuesday, October 2, 12
Executor Service



Tuesday, October 2, 12
Hello Task

                         A simple task
                             public class HelloTask implements Callable<String>, Serializable{
                                @Override
                                public String call(){
                                   Cluster cluster = Hazelcast.getCluster();
                                   return “Hello from ” + cluster.getLocalMember();
                             }

                         Execute on any member
                             ExecutorService ex = Hazelcast.getExecutorService();
                             Future<String> future = executor.submit(new HelloTask());
                             // ...
                             String result = future.get();

                         Attach a callback
                             DistributedTask task = ...
                             task.setExecutionCallback(new ExecutionCallback() {
                                 public void done(Future f) {
                                   // Get notified when the task is done!
                                 }
                             });

Tuesday, October 2, 12
Hazelcast can execute a task ...

                1.       On a specific node
                2.       On any available node
                3.       On a collection of defined nodes
                4.       On a node owning a key

                ExecutorService executor = Hazelcast.getExecutorService();
                FutureTask<String> task1, task2;


                // CASE 1: Run task on a specific member.
                Member member = ...
                task1 = new DistributedTask<String>(new HelloTask(), member);
                executor.execute(task1);

                // CASE 2: Run task on a member owning the key.
                Member member = ...
                task1 = new DistributedTask<String>(new HelloTask(), “key”);
                executor.execute(task1);

                // CASE 3: Run task on group of members.
                Set<Member> members = ...
                task = new MultiTask<String>(new HelloTask(), members);
                executor.execute(task2);


Tuesday, October 2, 12
Executor Service Scenario




                public int removeOrder(long customerId, long orderId){
                    IMap<Long, Customer> map = Hazelcast.getMap("customers");
                    map.lock(customerId);
                    Customer customer = map.get(customerId);
                    customer.removeOrder (orderId);
                    map.put(customerId, customer);
                    map.unlock(customerId);
                    return customer.getOrderCount();
                }




Tuesday, October 2, 12
Add Bonus Task

    public class OrderDeletionTask implements Callable<Integer>, PartitionAware, Serializable {

         private long customerId;
         private long orderId;

         public OrderDeletionTask(long customerId, long orderId) {
             super();
             this.customerId = customerId;
             this.orderId = orderId;
         }

         public Integer call () {
             IMap<Long, Customer> map = Hazelcast.getMap("customers");
             map.lock(customerId);
             customer customer = map. get(customerId);
             customer.removeOrder (orderId);
             map.put(customerId, customer);
             map.unlock(customerId);
             return customer.getOrderCount();
         }

         public Object getPartitionKey() {
             return customerId;
         }
    }




Tuesday, October 2, 12
Send computation over data




      public static int removeOrder(long customerId, long orderId){
          ExecutorService es = Hazelcast.getExecutorService();
          OrderDeletionTask task = new OrderDeletionTask(customerId, orderId);
          Future future = es.submit(task);
          int remainingOrders = future.get();
          return remainingOrders;
      }




Tuesday, October 2, 12
Persistence



Tuesday, October 2, 12
Persistence
                   import com.hazelcast.core.MapStore,
                   import com.hazelcast.core.MapLoader,

                   public class MyMapStore implements MapStore, MapLoader {

                         public Set loadAllKeys () {
                            return readKeys();
                          }

                         public Object load (Object key) {
                           return readFromDatabase(key);
                         }

                         public void store (Object key, Object value) {
                           saveIntoDatabase(key, value);
                         }

                         public void remove(Object key) {
                           removeFromDatabase(key);
                         }

                   }




Tuesday, October 2, 12
Persistence




                         Write-Behind : asynchronously storing entries
                         Write-Through : synchronous
                         Read-Through : if get(key) is null, load it




Tuesday, October 2, 12
Recap

                     •   Distributed implementation of   •   Embedded, but accessible
                         •  Map                              through
                         •  Queue                            •  Native Java & C# Client
                         •  Set                              •  REST
                         •  List                             •  Memcache
                         •  MultiMap                     •   Dynamic
                         •  Lock                             •  Cluster
                         •  Executor Service                 •  Add/ remove nodes
                         •  Topic                            •  Backup
                         •  Semaphore                        •  Fail-over
                         •  AtomicLong
                         •  CountDownLatch




Tuesday, October 2, 12
Q&A

                          JOIN US!

                          github.com/hazelcast/

                          hazelcast@googlegroups.com

                          @hazelcast

                          Hazelcast Hackers Linkedin group




Tuesday, October 2, 12

Weitere ähnliche Inhalte

Mehr von JAX London

Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
 
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias Wessendorf
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias WessendorfHTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias Wessendorf
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias WessendorfJAX London
 
Play framework 2 : Peter Hilton
Play framework 2 : Peter HiltonPlay framework 2 : Peter Hilton
Play framework 2 : Peter HiltonJAX London
 
Complexity theory and software development : Tim Berglund
Complexity theory and software development : Tim BerglundComplexity theory and software development : Tim Berglund
Complexity theory and software development : Tim BerglundJAX London
 
Why FLOSS is a Java developer's best friend: Dave Gruber
Why FLOSS is a Java developer's best friend: Dave GruberWhy FLOSS is a Java developer's best friend: Dave Gruber
Why FLOSS is a Java developer's best friend: Dave GruberJAX London
 
Akka in Action: Heiko Seeburger
Akka in Action: Heiko SeeburgerAkka in Action: Heiko Seeburger
Akka in Action: Heiko SeeburgerJAX London
 
NoSQL Smackdown 2012 : Tim Berglund
NoSQL Smackdown 2012 : Tim BerglundNoSQL Smackdown 2012 : Tim Berglund
NoSQL Smackdown 2012 : Tim BerglundJAX London
 
Closures, the next "Big Thing" in Java: Russel Winder
Closures, the next "Big Thing" in Java: Russel WinderClosures, the next "Big Thing" in Java: Russel Winder
Closures, the next "Big Thing" in Java: Russel WinderJAX London
 
Java and the machine - Martijn Verburg and Kirk Pepperdine
Java and the machine - Martijn Verburg and Kirk PepperdineJava and the machine - Martijn Verburg and Kirk Pepperdine
Java and the machine - Martijn Verburg and Kirk PepperdineJAX London
 
Mongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsMongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsJAX London
 
New opportunities for connected data - Ian Robinson
New opportunities for connected data - Ian RobinsonNew opportunities for connected data - Ian Robinson
New opportunities for connected data - Ian RobinsonJAX London
 
HTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaHTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaJAX London
 
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian Plosker
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian PloskerThe Big Data Con: Why Big Data is a Problem, not a Solution - Ian Plosker
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian PloskerJAX London
 
Bluffers guide to elitist jargon - Martijn Verburg, Richard Warburton, James ...
Bluffers guide to elitist jargon - Martijn Verburg, Richard Warburton, James ...Bluffers guide to elitist jargon - Martijn Verburg, Richard Warburton, James ...
Bluffers guide to elitist jargon - Martijn Verburg, Richard Warburton, James ...JAX London
 
No Crash Allowed - Patterns for fault tolerance : Uwe Friedrichsen
No Crash Allowed - Patterns for fault tolerance : Uwe FriedrichsenNo Crash Allowed - Patterns for fault tolerance : Uwe Friedrichsen
No Crash Allowed - Patterns for fault tolerance : Uwe FriedrichsenJAX London
 
Size does matter - Patterns for high scalability: Uwe Friedrichsen
Size does matter - Patterns for high scalability: Uwe FriedrichsenSize does matter - Patterns for high scalability: Uwe Friedrichsen
Size does matter - Patterns for high scalability: Uwe FriedrichsenJAX London
 
HBase Advanced - Lars George
HBase Advanced - Lars GeorgeHBase Advanced - Lars George
HBase Advanced - Lars GeorgeJAX London
 
Scala in Action - Heiko Seeburger
Scala in Action - Heiko SeeburgerScala in Action - Heiko Seeburger
Scala in Action - Heiko SeeburgerJAX London
 
Achieving genuine elastic multitenancy with the Waratek Cloud VM for Java : J...
Achieving genuine elastic multitenancy with the Waratek Cloud VM for Java : J...Achieving genuine elastic multitenancy with the Waratek Cloud VM for Java : J...
Achieving genuine elastic multitenancy with the Waratek Cloud VM for Java : J...JAX London
 
Choosing the right Agile innovation practices: Scrum vs Kanban vs Lean Startu...
Choosing the right Agile innovation practices: Scrum vs Kanban vs Lean Startu...Choosing the right Agile innovation practices: Scrum vs Kanban vs Lean Startu...
Choosing the right Agile innovation practices: Scrum vs Kanban vs Lean Startu...JAX London
 

Mehr von JAX London (20)

Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias Wessendorf
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias WessendorfHTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias Wessendorf
HTML alchemy: the secrets of mixing JavaScript and Java EE - Matthias Wessendorf
 
Play framework 2 : Peter Hilton
Play framework 2 : Peter HiltonPlay framework 2 : Peter Hilton
Play framework 2 : Peter Hilton
 
Complexity theory and software development : Tim Berglund
Complexity theory and software development : Tim BerglundComplexity theory and software development : Tim Berglund
Complexity theory and software development : Tim Berglund
 
Why FLOSS is a Java developer's best friend: Dave Gruber
Why FLOSS is a Java developer's best friend: Dave GruberWhy FLOSS is a Java developer's best friend: Dave Gruber
Why FLOSS is a Java developer's best friend: Dave Gruber
 
Akka in Action: Heiko Seeburger
Akka in Action: Heiko SeeburgerAkka in Action: Heiko Seeburger
Akka in Action: Heiko Seeburger
 
NoSQL Smackdown 2012 : Tim Berglund
NoSQL Smackdown 2012 : Tim BerglundNoSQL Smackdown 2012 : Tim Berglund
NoSQL Smackdown 2012 : Tim Berglund
 
Closures, the next "Big Thing" in Java: Russel Winder
Closures, the next "Big Thing" in Java: Russel WinderClosures, the next "Big Thing" in Java: Russel Winder
Closures, the next "Big Thing" in Java: Russel Winder
 
Java and the machine - Martijn Verburg and Kirk Pepperdine
Java and the machine - Martijn Verburg and Kirk PepperdineJava and the machine - Martijn Verburg and Kirk Pepperdine
Java and the machine - Martijn Verburg and Kirk Pepperdine
 
Mongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsMongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdams
 
New opportunities for connected data - Ian Robinson
New opportunities for connected data - Ian RobinsonNew opportunities for connected data - Ian Robinson
New opportunities for connected data - Ian Robinson
 
HTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaHTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun Gupta
 
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian Plosker
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian PloskerThe Big Data Con: Why Big Data is a Problem, not a Solution - Ian Plosker
The Big Data Con: Why Big Data is a Problem, not a Solution - Ian Plosker
 
Bluffers guide to elitist jargon - Martijn Verburg, Richard Warburton, James ...
Bluffers guide to elitist jargon - Martijn Verburg, Richard Warburton, James ...Bluffers guide to elitist jargon - Martijn Verburg, Richard Warburton, James ...
Bluffers guide to elitist jargon - Martijn Verburg, Richard Warburton, James ...
 
No Crash Allowed - Patterns for fault tolerance : Uwe Friedrichsen
No Crash Allowed - Patterns for fault tolerance : Uwe FriedrichsenNo Crash Allowed - Patterns for fault tolerance : Uwe Friedrichsen
No Crash Allowed - Patterns for fault tolerance : Uwe Friedrichsen
 
Size does matter - Patterns for high scalability: Uwe Friedrichsen
Size does matter - Patterns for high scalability: Uwe FriedrichsenSize does matter - Patterns for high scalability: Uwe Friedrichsen
Size does matter - Patterns for high scalability: Uwe Friedrichsen
 
HBase Advanced - Lars George
HBase Advanced - Lars GeorgeHBase Advanced - Lars George
HBase Advanced - Lars George
 
Scala in Action - Heiko Seeburger
Scala in Action - Heiko SeeburgerScala in Action - Heiko Seeburger
Scala in Action - Heiko Seeburger
 
Achieving genuine elastic multitenancy with the Waratek Cloud VM for Java : J...
Achieving genuine elastic multitenancy with the Waratek Cloud VM for Java : J...Achieving genuine elastic multitenancy with the Waratek Cloud VM for Java : J...
Achieving genuine elastic multitenancy with the Waratek Cloud VM for Java : J...
 
Choosing the right Agile innovation practices: Scrum vs Kanban vs Lean Startu...
Choosing the right Agile innovation practices: Scrum vs Kanban vs Lean Startu...Choosing the right Agile innovation practices: Scrum vs Kanban vs Lean Startu...
Choosing the right Agile innovation practices: Scrum vs Kanban vs Lean Startu...
 

Kürzlich hochgeladen

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Clustering your application with Hazelcast - Talip Ozturk

  • 1. HAZELCAST Art of Data Distribution open source, in-memory data grid Talip Ozturk @oztalip Tuesday, October 2, 12
  • 2. Who uses Hazelcast? and many more.... Every sec one Hazelcast instance starts around the globe Tuesday, October 2, 12
  • 3. 9th Fastest Growing Skill Tuesday, October 2, 12
  • 4. Keywords In-memory data grid Distributed(Elastic) Cache NoSQL Clustering, Scalability, Partitioning Cloud Computing Tuesday, October 2, 12
  • 5. Map import java.util.Map; import java.util.HashMap; Map map = new HashMap(); map.put(“1”, “value”); map.get(“1”); Tuesday, October 2, 12
  • 6. Concurrent Map import java.util.Map; import java.util.concurrent.*; Map map = new ConcurrentHashMap(); map.put(“1”, “value”); map.get(“1”); Tuesday, October 2, 12
  • 7. Distributed Map import java.util.Map; import com.hazelcast.core.Hazelcast; Map map = Hazelcast.getMap(“mymap”); map.put(“1”, “value”); map.get(“1”); Tuesday, October 2, 12
  • 8. Why Hazelcast? To build highly available and scalable applications Tuesday, October 2, 12
  • 10. Difference License/Cost Feature-set Ease of use Main focus (distributed map, tuple space, cache, processing vs. data) Light/Heavy weight Tuesday, October 2, 12
  • 12. Should be free! Apache License Tuesday, October 2, 12
  • 13. Lightweight without any dependency 1.7 MB jar Tuesday, October 2, 12
  • 14. Introducing Hazelcast Map, queue, set, list, lock, semaphore, topic and executor service Native Java, C#, REST and Memcache Interfaces Cluster info and membership events Dynamic clustering, backup, fail-over Transactional and secure Tuesday, October 2, 12
  • 15. Use-cases Scale your application Share data across cluster Partition your data Send/receive messages Balance the load Process in parallel on many JVM Tuesday, October 2, 12
  • 17. Where is the Data? Tuesday, October 2, 12
  • 18. Data Partitioning in a Cluster Fixed number of partitions (default 271) Each key falls into a partition partitionId = hash(keyData)%PARTITION_COUNT Partition ownerships are reassigned upon membership change A B C Tuesday, October 2, 12
  • 19. New Node Added A B C D Tuesday, October 2, 12
  • 20. Migration A B C D Tuesday, October 2, 12
  • 21. Migration A B C D Tuesday, October 2, 12
  • 22. Migration A B C D Tuesday, October 2, 12
  • 23. Migration A B C D Tuesday, October 2, 12
  • 24. Migration A B C D Tuesday, October 2, 12
  • 25. Migration A B C D Tuesday, October 2, 12
  • 26. Crash Migration Complete A B C D Tuesday, October 2, 12
  • 27. Node Crashes A B C D Crash Tuesday, October 2, 12
  • 28. Restoring Backups A B C D Crash Tuesday, October 2, 12
  • 29. Restoring Backups A B C D Crash Tuesday, October 2, 12
  • 30. Restoring Backups A B C D Crash Tuesday, October 2, 12
  • 31. Restoring Backups A B C D Crash Tuesday, October 2, 12
  • 32. Restoring Data from Backup A B C D Crash Tuesday, October 2, 12
  • 33. Data is Recovered from backup A B C D Crash Tuesday, October 2, 12
  • 34. Backup for Recovered Data A B C D Crash Tuesday, October 2, 12
  • 35. Backup for Recovered Data A B C D Crash Tuesday, October 2, 12
  • 36. Backup for Recovered Data A B C D Crash Tuesday, October 2, 12
  • 37. All Safe A C D Tuesday, October 2, 12
  • 39. Topology Native Client: HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig); Lite Member: -Dhazelcast.lite.member=true Tuesday, October 2, 12
  • 40. Hazelcast Enterprise Tuesday, October 2, 12
  • 41. Community vs Enterprise Enterprise = Community + Elastic Memory + Security + Man. Center Tuesday, October 2, 12
  • 42. Elastic Memory is OFF-HEAP storage -XX:MaxDirectMemorySize=60G ... hazelcast.elastic.memory.enabled to true. hazelcast.elastic.memory.total.size hazelcast.elastic.memory.chunk.size Default chunk size is 1. Chunk size has to be power of 2 such as 1, 2, 4 and 8. <hazelcast> ... <map name="default"> ... <storage-type>OFFHEAP</storage-type> </map> </hazelcast> Tuesday, October 2, 12
  • 43. JAAS based Security Credentials Cluster Login Module Cluster Member Security Native Client Security Authentication Authorization Permission Tuesday, October 2, 12
  • 45. Hazelcast Hazelcast is thread safe Map<String, Employee> = Hazelcast.getMap(“employees”); List<Users> = Hazelcast.getList(“users”); Many instances on the same JVM Config config = new Config(); HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config) HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config) All objects must be serializable class Employee implements java.io.Serializable //better class Employee implements com.hazelcast.nio.DataSerializable Tuesday, October 2, 12
  • 46. Cluster Interface import com.hazelcast.core.*; import java.util.Set; Cluster cluster = Hazelcast.getCluster(); cluster.addMembershipListener(listener); Member localMember = cluster.getLocalMember(); System.out.println (localMember.getInetAddress()); Set<Member> setMembers = cluster.getMembers(); Tuesday, October 2, 12
  • 47. Distributed Map import com.hazelcast.core.*; import java.util.ConcurrentMap; Map<String, Customer> map = Hazelcast.getMap("customers"); map.put ("1", customer); Customer c = map.get("1"); //ConcurrentMap methods map.putIfAbsent ("2", new Customer(“Chuck Norris”)); map.replace ("3", new Customer(“Bruce Lee”)); Tuesday, October 2, 12
  • 48. Distributed Queue import com.hazelcast.core.Hazelcast; import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; BlockingQueue<Task> queue = Hazelcast.getQueue(“tasks"); queue.offer(task); Task t = queue.poll(); //Timed blocking Operations queue.offer(task, 500, TimeUnit.MILLISECONDS) Task t = queue.poll(5, TimeUnit.SECONDS); //Indefinitely blocking Operations queue.put(task) Task t = queue.take(); Tuesday, October 2, 12
  • 49. Distributed Lock import com.hazelcast.core.Hazelcast; import java.util.concurrent.locks.Lock; Lock mylock = Hazelcast.getLock(mylockobject); mylock.lock(); try { // do something } finally { mylock.unlock(); } //Lock on Map IMap<String, Customer> map = Hazelcast.getMap("customers"); map.lock("1"); try { // do something } finally { map.unlock("1"); } Tuesday, October 2, 12
  • 50. Distributed Topic import com.hazelcast.core.*; public class Sample implements MessageListener { public static void main(String[] args) { Sample sample = new Sample(); ITopic<String> topic = Hazelcast.getTopic ("default"); topic.addMessageListener(sample); topic.publish ("my-message-object"); } public void onMessage(Object msg) { System.out.println("Got msg :" + msg); } } Tuesday, October 2, 12
  • 51. Distributed Events import com.hazelcast.core.*; public class Sample implements EntryListener { public static void main(String[] args) { Sample sample = new Sample(); IMap map = Hazelcast.getMap ("default"); map.addEntryListener (sample, true); map.addEntryListener (sample, "key"); } public void entryAdded(EntryEvent event) { System.out.println("Added " + event.getKey() + ":" + event.getValue()); } public void entryRemoved(EntryEvent event) { System.out.println("Removed " + event.getKey() + ":" + event.getValue()); } public void entryUpdated(EntryEvent event) { System.out.println("Updated " + event.getKey() + ":" + event.getValue()); } } Tuesday, October 2, 12
  • 53. Hello Task A simple task public class HelloTask implements Callable<String>, Serializable{ @Override public String call(){ Cluster cluster = Hazelcast.getCluster(); return “Hello from ” + cluster.getLocalMember(); } Execute on any member ExecutorService ex = Hazelcast.getExecutorService(); Future<String> future = executor.submit(new HelloTask()); // ... String result = future.get(); Attach a callback DistributedTask task = ... task.setExecutionCallback(new ExecutionCallback() { public void done(Future f) { // Get notified when the task is done! } }); Tuesday, October 2, 12
  • 54. Hazelcast can execute a task ... 1. On a specific node 2. On any available node 3. On a collection of defined nodes 4. On a node owning a key ExecutorService executor = Hazelcast.getExecutorService(); FutureTask<String> task1, task2; // CASE 1: Run task on a specific member. Member member = ... task1 = new DistributedTask<String>(new HelloTask(), member); executor.execute(task1); // CASE 2: Run task on a member owning the key. Member member = ... task1 = new DistributedTask<String>(new HelloTask(), “key”); executor.execute(task1); // CASE 3: Run task on group of members. Set<Member> members = ... task = new MultiTask<String>(new HelloTask(), members); executor.execute(task2); Tuesday, October 2, 12
  • 55. Executor Service Scenario public int removeOrder(long customerId, long orderId){ IMap<Long, Customer> map = Hazelcast.getMap("customers"); map.lock(customerId); Customer customer = map.get(customerId); customer.removeOrder (orderId); map.put(customerId, customer); map.unlock(customerId); return customer.getOrderCount(); } Tuesday, October 2, 12
  • 56. Add Bonus Task public class OrderDeletionTask implements Callable<Integer>, PartitionAware, Serializable { private long customerId; private long orderId; public OrderDeletionTask(long customerId, long orderId) { super(); this.customerId = customerId; this.orderId = orderId; } public Integer call () { IMap<Long, Customer> map = Hazelcast.getMap("customers"); map.lock(customerId); customer customer = map. get(customerId); customer.removeOrder (orderId); map.put(customerId, customer); map.unlock(customerId); return customer.getOrderCount(); } public Object getPartitionKey() { return customerId; } } Tuesday, October 2, 12
  • 57. Send computation over data public static int removeOrder(long customerId, long orderId){ ExecutorService es = Hazelcast.getExecutorService(); OrderDeletionTask task = new OrderDeletionTask(customerId, orderId); Future future = es.submit(task); int remainingOrders = future.get(); return remainingOrders; } Tuesday, October 2, 12
  • 59. Persistence import com.hazelcast.core.MapStore, import com.hazelcast.core.MapLoader, public class MyMapStore implements MapStore, MapLoader { public Set loadAllKeys () { return readKeys(); } public Object load (Object key) { return readFromDatabase(key); } public void store (Object key, Object value) { saveIntoDatabase(key, value); } public void remove(Object key) { removeFromDatabase(key); } } Tuesday, October 2, 12
  • 60. Persistence Write-Behind : asynchronously storing entries Write-Through : synchronous Read-Through : if get(key) is null, load it Tuesday, October 2, 12
  • 61. Recap • Distributed implementation of • Embedded, but accessible • Map through • Queue • Native Java & C# Client • Set • REST • List • Memcache • MultiMap • Dynamic • Lock • Cluster • Executor Service • Add/ remove nodes • Topic • Backup • Semaphore • Fail-over • AtomicLong • CountDownLatch Tuesday, October 2, 12
  • 62. Q&A JOIN US! github.com/hazelcast/ hazelcast@googlegroups.com @hazelcast Hazelcast Hackers Linkedin group Tuesday, October 2, 12