easy distributed systems using hazelcast -...
TRANSCRIPT
![Page 1: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/1.jpg)
Easy Distributed Systems Using Hazelcast
Peter Veentjer
![Page 2: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/2.jpg)
• Working for Hazelcast
• Team Lead Quality & Performance
• Author of ‘Mastering Hazelcast 3'
• 14 years Java experience
• Big love
• Concurrency control
• Distributed computing
Whoami
![Page 3: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/3.jpg)
![Page 4: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/4.jpg)
What is Hazelcast?
![Page 5: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/5.jpg)
What is Hazelcast?
• Leading Open Source Java In Memory Data/Compute Grid
• Out main goal is to simplify development of:
• Scalable systems
• Highly available systems
![Page 6: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/6.jpg)
Why Hazelcast?
• 3 MByte JAR
• no other dependencies!
• no need to install software!
• Its a library, not an application framework
• Apache 2 License
• Free to use
• no limitations
![Page 7: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/7.jpg)
Distributed Data-structures
• IAtomicLong/Ref
• IdGenerator
• Lock/Condition
• CountDownLatch
• Semaphore
• Queue
• Map
• MultiMap
• Set
• List
• Topic
• Executor
• ReplicatedMap
• MapReduce
• TransactionalMap/Q/S…
• Write your own!
![Page 8: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/8.jpg)
So what can I do with it?
![Page 9: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/9.jpg)
Scaling
![Page 10: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/10.jpg)
Scale up
![Page 11: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/11.jpg)
Scale Out
![Page 12: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/12.jpg)
High Availability
![Page 13: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/13.jpg)
100000
200000
300000
400000
500000
600000
700000
800000
900000
1000000
2 4 8 16 32
read write
![Page 14: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/14.jpg)
Raspberry Pi Cluster
![Page 15: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/15.jpg)
When?
• Caching
• Messaging Solution
• Data Aggregation
• Clustered Scheduling
• Job Processing
• Cluster management
• HTTP session clustering
![Page 16: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/16.jpg)
Which companies
• E-Commerce • Apple, eBay
• Financials
• JP Morgan, Morgan Stanley, HSBC, Deutsche Bank
• Telco’s
• AT&T, Ericsson
• Gaming
• Ubisoft/Blue Byte
![Page 17: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/17.jpg)
Which Open Source Projects
• WSO2 Carbon
• Mule ESB
• Vert.x
• Apache Camel
• Apache Shiro
• OrientDB
• Alfresco
• Karaf
![Page 18: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/18.jpg)
How Often
• In April 2014
• 3M startups
• 48K unique
![Page 19: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/19.jpg)
Where is the code!
![Page 20: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/20.jpg)
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
Creating Hazelcast Cluster
![Page 21: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/21.jpg)
<hazelcast> <network>…</network> <map name=“m”>…</map> <queue name=“q”>…</queue> <… </hazelcast>
XML Configuration
![Page 22: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/22.jpg)
Config config = new Config(); … make config modifications HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
Programmatic Configuration
![Page 23: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/23.jpg)
Demo
![Page 24: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/24.jpg)
Map<String,String> products = new HashMap(); map.put("1","IPhone");
Map
![Page 25: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/25.jpg)
Map<String,String> products = new ConcurrentHashMap(); map.put("1","IPhone");
Map
![Page 26: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/26.jpg)
HazelcastInstance hz = Hazelcast.newHazelcastInstance(); Map<String,String> products = hz.getMap("products"); cities.put("1","IPhone");
Map
![Page 27: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/27.jpg)
Demo
![Page 28: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/28.jpg)
!<map name="products"> <time-to-live-seconds>4</time-to-live-seconds> <indexes> <index>name</index> </indexes> <..> </map>
Map Configuration
![Page 29: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/29.jpg)
Map Scalability and High Availability
271 Partitions
partitionid = hash(key) % partitioncount
…
![Page 30: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/30.jpg)
Map Scalability and High Availability
Member 1
![Page 31: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/31.jpg)
Map Scalability and High Availability
Member 1
Member 2
![Page 32: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/32.jpg)
Map Scalability and High Availability
Member 1
Member 2
Member 3
![Page 33: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/33.jpg)
Map Scalability and High Availability
Member 1
Member 2
Member 3
![Page 34: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/34.jpg)
Map Scalability and High Availability
Member 1
Member 2
Member 3
![Page 35: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/35.jpg)
Map Scalability and High Availability
Member 1
Member 2
![Page 36: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/36.jpg)
Demo
![Page 37: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/37.jpg)
Multimap
• Collection as value • Serialization Overhead
• Lost update
![Page 38: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/38.jpg)
Demo
![Page 39: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/39.jpg)
BlockingQueue queue = new LinkedBlockingQueue(); queue.offer("1"); Object item = queue.take();
Queue
![Page 40: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/40.jpg)
!HazelcastInstance hz = Hazelcast.newHazelcastInstance(); BlockingQueue queue = hz.getQueue("queue"); queue.offer("1"); Object item = queue.take();
Queue
![Page 41: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/41.jpg)
Demo
![Page 42: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/42.jpg)
ITopic topic = hz.getTopic("topic"); //publishing topic.publish(msg); !//subscribing topic.addMessageListener(new TopicSubscriber()); !public class TopicSubscriber implements MessageListener<String> { public void onMessage(Message<String> m) { System.out.println(m.getMessageObject()); } }
Topic
![Page 43: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/43.jpg)
Client
• Languages
• Java
• C++
• C#
• Memcached
• Smart vs Dumb
![Page 44: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/44.jpg)
HazelcastInstance client = HazelcastClient.newHazelcastClient();
Client
![Page 45: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/45.jpg)
Network Communication
• Cluster Discovery
• Multicast
• TCP/IP Cluster
• AWS Cluster
• Normal Network Communication
• TCP/IP
![Page 46: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/46.jpg)
Advanced Hazelcast
![Page 47: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/47.jpg)
!ILock lock = hz.getLock(“someLock”); !IAtomicLong counter =hz.getAtomicLong(“someCounter”); !IMap map = hz.getMap(“someMap”); map.put(“somePerson”,new Person()); map.get(“somePerson”);
Data Locality: Problem
![Page 48: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/48.jpg)
Member 1
Member 2
Member 3
SomeLock
SomeCounter
SomePerson
![Page 49: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/49.jpg)
name@partitionkey
name
![Page 50: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/50.jpg)
ILock lock = hz.getLock(“someLock@foo”); IAtomicLong counter = hz.getAtomicLong(“someCounter@foo”); !IMap map = hz.getMap(“someMap”); map.put(“somePerson@foo”, new Person()); Person p = map.get(“somePerson@foo”);
Data Locality: Fixed
![Page 51: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/51.jpg)
Member 1
Member 2
Member 3
SomeLock
SomeCounter
SomePerson
Foo Partition
![Page 52: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/52.jpg)
IAtomicLong c1 = … IAtomicLong c2 = hz.getAtomicLong(“c2@“+c1.getPartitionKey());
Adding object in same partition
![Page 53: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/53.jpg)
Executor
• Execute task anywhere
• Execute task on key owner
• Execute task
• one/all/subset members
• Synchronisation
• Future
• ExecutionCallback
• CompletableFuture Hazelcast 3.3
![Page 54: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/54.jpg)
Demo
![Page 55: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/55.jpg)
Locking
• Locks
• TransactionalMap.getForUpdate
• Map.Lock
![Page 56: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/56.jpg)
Demo
![Page 57: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/57.jpg)
public void increment(int accountId,int amount){ Account account = accounts.get(accountId); account.balance+=amount; accounts.put(accountId, account); }
Race problem
![Page 58: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/58.jpg)
public void increment(int accountId,int amount){ accounts.lock(accountId); try{ Account account = accounts.get(accountId); account.balance+=amount; accounts.put(accountId, account); }finally{ accounts.unlock(accountId); } }
Pessimistic Increment
![Page 59: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/59.jpg)
public void increment(int accountId,int amount){ accounts.lock(accountId); try{ Account account = accounts.get(accountId); account.balance+=amount; accounts.put(accountId, account); }finally{ accounts.unlock(accountId); } }
Pessimistic Increment
![Page 60: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/60.jpg)
public void increment(int accountId,int amount){ for(;;){ Account old = accounts.get(accountId); Account update = new Account(old); update.balance+=amount; if(accounts.replace(accountId, old,update)){ return; } } }
Optimistic Increment
![Page 61: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/61.jpg)
public void increment(int accountId,int amount){ for(;;){ Account old = accounts.get(accountId); Account update = new Account(old); update.balance+=amount; if(accounts.replace(accountId, old,update)){ return; } } }
Optimistic Increment
![Page 62: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/62.jpg)
DATA
Bad: Send Data to Function
DATA
Good: Send Function to Data
Read Data
Write Data
Write Function
![Page 63: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/63.jpg)
class BalanceTask implements Runnable,Serializable{ private int accountId, amount; public void run() { for(;;){ Account old = accounts.get(accountId); Account update = new Account(old); update.balance+=amount; if(accounts.replace(accountId, old,update)){ return; } } } }
![Page 64: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/64.jpg)
public void increment(int id, int amount){ BalanceTask task = new BalanceTask(id,amount); executorService.executeOnKeyOwner(task,id); }
Increment with runnable
![Page 65: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/65.jpg)
class BalanceProcessor extends AbstractEntryProcessor{ int amount; BalanceProcessor(int amount) { this.amount = amount; } ! @Override Object process(Map.Entry<Integer, Account> e) { e.getValue().balance+=amount; return null; } }
Increment with EntryProcessor
![Page 66: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/66.jpg)
public void increment(int accountId, int amount){ BalanceProcessor p = new BalanceProcessor(amount); accounts.executeOnKey(accountId, p); }
Using entry processor
![Page 67: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/67.jpg)
Map: In Memory Format
• 2 Options
• BINARY
• OBJECT
• Predicates
• EntryProcessor
![Page 68: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/68.jpg)
SPI
• You can write your own distributed data-structures
• Example
• Distributed Actors implementation
![Page 69: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/69.jpg)
Serialization API
• Serializable/Externalizable
• Portable
• ByteArraySerializable
• StreamSerializer
• Kryo
• Jackson Smile
• Protobuf
![Page 70: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/70.jpg)
Kryo SerializationSi
ze in
Byt
es
0
5,000
10,000
15,000
20,000
Serialization Kryo Kryp + Compr
![Page 71: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/71.jpg)
!SerializerConfig ps = new SerializerConfig() .setTypeClass(Product.class) .setImplementation(new ProductSerializer()); !Config config = new Config(); config.getSerializationConfig() .addSerializerConfig(ps); !HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
Pluggable Serialization
![Page 72: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/72.jpg)
IMap<Integer,Account> accounts = hz.getMap(“accounts”); !Map<Integer,Integer> result = accounts .map(new AccountSumMapper()) .reduce(new AccountSumReducer()) .submit()
Hazelcast 3.2 Map Reduce
![Page 73: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/73.jpg)
Enterprise vs Community edition
• Support contracts
• Elastic Memory
• Security
• Management Center
![Page 74: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/74.jpg)
The Future
• Stabilizer
• Topologies
• Dynamic Creation
• Map of Maps
• Tiered storage
![Page 75: Easy Distributed Systems Using Hazelcast - JEEConfjeeconf.com/wp-content/uploads/slides/hazelcast-2014.pdf · • Working for Hazelcast! ... • Vert.x! • Apache Camel! •](https://reader033.vdocument.in/reader033/viewer/2022050902/5ab312fb7f8b9aea528deb89/html5/thumbnails/75.jpg)
Questions?