From Terracotta To Hazelcast 
Introduction on Hazelcast for Terracotta Users 
© 2014 Hazelcast Inc. 
AUTUMN 2014
About me 
© 2014 Hazelcast Inc. 
Rahul Gupta 
@wildnez 
! 
Senior Solutions Architect for Hazelcast 
Worked with Terracotta and Coherence 
Worked for Major Investment Banks 
Java Programmer since 1996 
Started programming in VHDL and later on 8048, 80286 CPU 
2
How this is going down 
© 2014 Hazelcast Inc. 
3 
• Limitations of Terracotta 
• What is Hazelcast 
• Migration 
• Important Features
Limitations of Terracotta 
! 
• Only an in-memory data store 
! 
• Complex APIs to use distributed collections 
! 
• No capabilities of processing data in memory 
! 
• Data needs to be fetched by the application resulting in network hops 
! 
• Inflexible - Only Client-Server architecture 
! 
• Dedicated environment for backup, Extra Server Licenses (Passive/Mirror) 
! 
• Requires dedicated environment 
! 
• Requires downtime to scale 
© 2014 Hazelcast Inc. 
4
Hazelcast overcomes the limitations 
• True IMDG space 
© 2014 Hazelcast Inc. 
– In-Memory Distributed Data Caching 
» Native Memory 
– In-Memory Parallel Data Processing 
» Distributed ExecutorService 
» EntryProcessors 
– In-Memory Map-Reduce 
! 
• Distributed Pub-Sub Messaging Model 
! 
• Simple Access to Distributed Collections 
5
Hazelcast overcomes the limitations 
• Highly Flexible Deployments 
© 2014 Hazelcast Inc. 
– Client-Server 
» Servers run in a separate tier in dedicated 
environment 
» Does not require dedicated infrastructure for 
running backup 
– Embedded 
» Hazelcast node runs within the application 
JVM 
» Application nodes made distributed by 
Hazelcast running within their JVM 
» Does not require dedicated environment 
6
Hazelcast overcomes the limitations 
• Backups also serve as Main nodes 
! 
• No extra licenses for backup 
! 
• Scales on the fly 
! 
• No downtime required to add/remove nodes 
© 2014 Hazelcast Inc. 
7
Configuring & forming a cluster 
© 2014 Hazelcast Inc. 
8
Forming a Cluster 
• Hazelcast Clusters run on JVM 
• Hazelcast discovers other instances via Multicast 
(Default) 
• Use TCP/IP lists when Multicast not possible 
• Segregate Clusters on same network via configuration 
• Hazelcast can form clusters on Amazon EC2. 
© 2014 Hazelcast Inc. 
9
Hazelcast Configuration - Server 
• Only one jar - look for hazelcast-all-x.x.x.jar 
! 
• Hazelcast searches for hazelcast.xml on class path 
! 
• Will use hazelcast-default.xml for everything else. 
! 
• Hazelcast can be configured via XML,API or Spring 
! 
• Configure Networks, Data Structures, 
Indexes,Compute 
© 2014 Hazelcast Inc. 
10
Form a cluster 
1. Sample hazelcast.xml looks like this 
© 2014 Hazelcast Inc. 
11
TOP TIP 
• The <group> configuration element is your friend. 
! 
• It will help you isolate your cluster on the multicast 
network. 
! 
• Don’t make the mistake of joining another developers 
cluster or worse still a Production Cluster! 
© 2014 Hazelcast Inc. 
12
Configuration via API 
1. Add GroupConfig to the Config instance. 
© 2014 Hazelcast Inc. 
13
TOP TIP 
• You can run multiple Hazelcast instances in one JVM. 
! 
• Handy for unit testing. 
! 
© 2014 Hazelcast Inc. 
14
Configure Cluster to use TCP/IP 
1. Edit multicast enabled = false 
2. Add tcp-ip element with your ip address 
© 2014 Hazelcast Inc. 
15
Client Configuration 
© 2014 Hazelcast Inc. 
16
Hazelcast Configuration - Client 
• Hazelcast searches for hazelcast-client.xml on class path 
• Full API stack - Client API same as Server API 
• Clients in Java, C#, C++, Memcache, REST 
© 2014 Hazelcast Inc. 
17
Starting as a Client or Cluster JVM 
© 2014 Hazelcast Inc. 
18 
Notice Client and Cluster return same HazelcastInstance reference.
Code Migration 
© 2014 Hazelcast Inc. 
19
Migration - Terracotta to Hazelcast 
• Terracotta implementation of cache puts/gets: 
! 
! 
! 
! 
• Replace Terracotta implementation by Hazelcast 
code: 
© 2014 Hazelcast Inc. 
20
Migration - Terracotta to Hazelcast 
• Terracotta implementation of Blocking Queue(notice the 
complex APIs): 
! 
! 
! 
! 
• Replace Terracotta by Hazelcast Queue (notice the 
simplicity): 
© 2014 Hazelcast Inc. 
21
Topologies 
© 2014 Hazelcast Inc. 
22
Hazelcast Topologies 
• Traditional Client -> Server (Client -> Cluster) 
! 
• Clients do not take part in standard cluster coms. 
! 
• Consider Client -> Cluster topology to segregate service 
from storage. 
! 
• Smart Clients connect to all Clusters nodes. Operations go 
directly to node holding data. 
! 
• Embedded model, for example in a J2EE container. service 
and storage within one JVM. 
© 2014 Hazelcast Inc. 
23
Terracotta Cluster 
© 2014 Hazelcast Inc. 
24
Embedded Hazelcast 
© 2014 Hazelcast Inc. 
25
Client Server -> (Client -> Cluster) 
© 2014 Hazelcast Inc. 
26
Distributed Collections 
© 2014 Hazelcast Inc. 
27
Maps 
© 2014 Hazelcast Inc. 
28
Distributed Maps - IMap 
• Conforms to the java.util.Map interface 
! 
• Conforms to the java.util.ConcurrentMap interface 
! 
• Hazelcast IMap interface provides extra features 
EntryListeners 
Aggregators 
Predicate Queries 
Locking 
Eviction 
© 2014 Hazelcast Inc. 
29
Wildcard Configuration 
• Hazelcast support wildcards for config. 
© 2014 Hazelcast Inc. 
30 
• Beware of ambiguous config though. 
• Hazelcast doesn’t pick best match and what it picks is 
random not in the order it appears in config.
Properties 
• Hazelcast supports property replacement in XML config 
© 2014 Hazelcast Inc. 
31 
• Uses System Properties by default 
• A Properties Loader can be configured
Near Cache 
• Terracotta L1 Cache -> Hazelcast Near Cache 
! 
• Highly recommended for read-mostly maps 
© 2014 Hazelcast Inc. 
32
Replicated Map 
© 2014 Hazelcast Inc. 
33 
• Does not partition data. 
• Copies Map Entry to every Cluster JVM. 
! 
• Consider for immutable slow moving data like config. 
! 
• ReplicatedMap interface supports EntryListeners. 
!
Data Distribution and Resource 
Management 
© 2014 Hazelcast Inc. 
34
Data Distribution 
• Data (primary + backup) is distributed in cluster using partitions 
! 
• 271 default partitions 
! 
• Partitions are divided among running cluster JVMs. 
! 
• Discovery of resident partition performed by the client before 
sending out update/get calls 
! 
• In smart-client setup, requests go directly to the host node 
! 
• Hazelcast places a backup of the Map Entry on another partition 
as part of the Map.put 
© 2014 Hazelcast Inc. 
35
Data Distribution 
• The backup operation can be sync (default) or async to the 
Map.put 
! 
• Each node acts as Primary and Backup compare to Active-Passive 
on dedicated resources setup in Terracotta - efficient use of 
resources 
! 
• When cluster JVM enters or leaves, cluster partitions are 
rebalanced 
! 
• In event of a node failure - 
– Primary data is retrieved from backup and distributed across 
remaining nodes in cluster 
– New backup is created on good nodes 
© 2014 Hazelcast Inc. 
36
Data Distribution 
© 2014 Hazelcast Inc. 
37 
Fixed number of partitions (default 271) 
Each key falls into a partition 
partitionId = hash(keyData)%PARTITION_COUNT 
Partition ownerships are reassigned upon membership 
A B C
New Node Added 
A B C D 
© 2014 Hazelcast Inc.
Migration 
A B C D 
© 2014 Hazelcast Inc.
Migration 
A B C D 
© 2014 Hazelcast Inc.
Migration 
A B C D 
© 2014 Hazelcast Inc.
Migration 
A B C D 
© 2014 Hazelcast Inc.
Migration 
A B C D 
© 2014 Hazelcast Inc.
Migration 
A B C D 
© 2014 Hazelcast Inc.
Migration Complete 
A B C D 
© 2014 Hazelcast Inc. 
Crash
Fault Tolerance & Recovery 
© 2014 Hazelcast Inc. 
46
Node Crashes 
A B C D 
© 2014 Hazelcast Inc. 
Crash
Backups are Restored 
A B C D 
© 2014 Hazelcast Inc. 
Crash
Backups are Restored 
A B C D 
© 2014 Hazelcast Inc. 
Crash
Backups are Restored 
A B C D 
© 2014 Hazelcast Inc. 
Crash
Backups are Restored 
A B C D 
© 2014 Hazelcast Inc. 
Crash
Data is Recovered from backup 
A B C D 
© 2014 Hazelcast Inc. 
Crash
Data is Recovered from backup 
A B C D 
© 2014 Hazelcast Inc. 
Crash
Backup for Recovered Data 
A B C D 
© 2014 Hazelcast Inc. 
Crash
Backup for Recovered Data 
A B C D 
© 2014 Hazelcast Inc. 
Crash
Backup for Recovered Data 
A B C D 
© 2014 Hazelcast Inc. 
Crash
All Safe 
© 2014 Hazelcast Inc. 
A C D
In Memory Format & Serialization 
© 2014 Hazelcast Inc. 
58
In Memory Format 
• Flexibility in data store format compared to Terracotta’s 
binary only 
• By default, data in memory is binary (serialised) format. 
• Local Processing on a node has to keep deserialising. 
• Use OBJECT if local processing (entry processor,executors) 
• Use BINARY if get(ing) data over the network 
© 2014 Hazelcast Inc. 
59
Serialization 
© 2014 Hazelcast Inc. 
60 
• Custom Serialization as against “Serializable” only option in Terracotta 
– DataSerializable 
• Fine grained control over serialization 
• Uses Reflection to create class instance 
• “implements DataSerializable” 
– public void writeData(ObjectDataOutput out) 
– public void readData(ObjectDataInput in) 
– IdentifiedDataSerializable 
• Better version of DataSerializable 
• Avoids Reflection - faster serialization 
• extends DataSerializable 
• Two new methods - 
– int getId() - used instead of classname 
– int getFactoryId() - used to load the class given to Id
Distributed Compute 
© 2014 Hazelcast Inc. 
61
Distributed Executor Service 
© 2014 Hazelcast Inc. 
62
Distributed Executor 
© 2014 Hazelcast Inc. 
63 
• IExectorService extends 
java.util.concurrent.ExecutorService 
• Send a Runnable or Callable into the Cluster 
• Targetable Execution 
All Members 
Member 
MemberSelector 
KeyOwner 
• sync/async blocking based on Futures 
• Or ExecutionCallback notifies onResponse 
!
Distributed Executor 
• If System Resources permit you can scale up the number of 
threads the ExecutorService uses. 
© 2014 Hazelcast Inc. 
64 
!! 
! 
!
Distributed Executor 
© 2014 Hazelcast Inc. 
65 
! 
! 
• Each Member creates its own work queue. 
• Tasks are not partitioned or load balanced. 
• If member dies while task is enqueue on member it is lost. 
• You need to lock any data you access, but beware of 
Deadlocks! 
!
EntryProcessor 
© 2014 Hazelcast Inc. 
66
EntryProcessor 
• A Distributed Map Entry Processor Function 
• Provides locking guarantees 
• Work directly on the Entry object in a node 
• Executed on the Partition Thread rather than the Executor 
• Submitted via the IMap 
• Best to apply delta updates without moving the object 
across the network 
© 2014 Hazelcast Inc. 
67
EntryProcessor 
© 2014 Hazelcast Inc. 
68 
• EntryProcessor also mutates the Backup copy 
• Use the AbstractEntryProcesssor for default backup 
behaviour 
• Implement EntryProcessor directly to provide your own 
Backup behaviour, for example sending delta only 
! 
• Only alternative to Terracotta DSO
EntryProcessor 
© 2014 Hazelcast Inc. 
69
EntryProcessor 
© 2014 Hazelcast Inc. 
70 
• Other tasks run on Partition Thread (Puts, Gets) 
• It is important to yield the EntryProcessor 
• hazelcast.entryprocessor.batch.max.size: 
Defaults to 10.000 
• Hazelcast will not interrupt a running operation it only 
yields when the current Key has been processed.
In-memory Map Reduce 
© 2014 Hazelcast Inc. 
71
MAP Reduce 
© 2014 Hazelcast Inc. 
72 
• In-memory Map/Reduce compared to disk bound M/R 
• Similar paradigm to Hadoop Map/Reduce 
• Familiar nomenclature for ease of understanding and 
use 
– JobTracker 
– Job 
– Mapper 
– CombinerFactory 
– Reducer 
– Collator
Distributed Aggregation 
© 2014 Hazelcast Inc. 
73
Aggregators 
© 2014 Hazelcast Inc. 
74 
• Ready-to-use in-memory data aggregation algorithms 
• Implemented on top of Hazelcast MapReduce framework 
• More convenient than MR for large set of standard operations 
• Work on both - IMap and MultiMap 
• Types of aggregation: 
– Average, Sum, Min, Max, DistinctValues, Count
Querying 
© 2014 Hazelcast Inc. 
75
Querying with Predicates 
• Rich Predicate API that can be run against IMap, similar to 
criterion based Terracotta Search 
Collection<V> IMap.values(Predicate p) 
Set<K> IMap.keySet(Predicate p) 
Set<Map.Entry<K,V>> IMap.entrySet(Predicate p) 
Set<K> IMap.localKeySet(Predicate p) 
© 2014 Hazelcast Inc. 
76 
!!
Querying with Predicates 
© 2014 Hazelcast Inc. 
77 
notEqual instanceOf like (%,_) greaterThan 
greaterEqual lessThan lessEqual between 
in isNot regex
Querying with Predicates 
© 2014 Hazelcast Inc. 
78 
• Create your own Predicates 
!!
SQL like queries 
© 2014 Hazelcast Inc. 
79 
• SQLPredicate class. 
• Runs only on Values. 
• Converts the String to a set of concrete Predicates. 
!!
Indexes 
© 2014 Hazelcast Inc. 
80 
• Prevent full Map scans. 
• Indexes can be ordered or unordered. 
• Indexes can work along the Object Graph (x.y.z). 
• When indexing non primitives they must implement 
Comparable. 
• Indexes can be created at runtime. 
!!
Conclusion 
© 2014 Hazelcast Inc. 
81
Conclusion 
• Hazelcast is easy to use 
! 
• Easy to migrate from Terracotta 
! 
• Familiar naming convention 
! 
• Lot more features and use cases than just a data store 
! 
• On the fly scale 
! 
• Zero downtime 
! 
• No single point of failure 
© 2014 Hazelcast Inc. 
82
© 2014 Hazelcast Inc. 
Thank You 
! 
@wildnez 
! 
rahul@hazelcast.com 
83

Hazelcast for Terracotta Users

  • 1.
    From Terracotta ToHazelcast Introduction on Hazelcast for Terracotta Users © 2014 Hazelcast Inc. AUTUMN 2014
  • 2.
    About me ©2014 Hazelcast Inc. Rahul Gupta @wildnez ! Senior Solutions Architect for Hazelcast Worked with Terracotta and Coherence Worked for Major Investment Banks Java Programmer since 1996 Started programming in VHDL and later on 8048, 80286 CPU 2
  • 3.
    How this isgoing down © 2014 Hazelcast Inc. 3 • Limitations of Terracotta • What is Hazelcast • Migration • Important Features
  • 4.
    Limitations of Terracotta ! • Only an in-memory data store ! • Complex APIs to use distributed collections ! • No capabilities of processing data in memory ! • Data needs to be fetched by the application resulting in network hops ! • Inflexible - Only Client-Server architecture ! • Dedicated environment for backup, Extra Server Licenses (Passive/Mirror) ! • Requires dedicated environment ! • Requires downtime to scale © 2014 Hazelcast Inc. 4
  • 5.
    Hazelcast overcomes thelimitations • True IMDG space © 2014 Hazelcast Inc. – In-Memory Distributed Data Caching » Native Memory – In-Memory Parallel Data Processing » Distributed ExecutorService » EntryProcessors – In-Memory Map-Reduce ! • Distributed Pub-Sub Messaging Model ! • Simple Access to Distributed Collections 5
  • 6.
    Hazelcast overcomes thelimitations • Highly Flexible Deployments © 2014 Hazelcast Inc. – Client-Server » Servers run in a separate tier in dedicated environment » Does not require dedicated infrastructure for running backup – Embedded » Hazelcast node runs within the application JVM » Application nodes made distributed by Hazelcast running within their JVM » Does not require dedicated environment 6
  • 7.
    Hazelcast overcomes thelimitations • Backups also serve as Main nodes ! • No extra licenses for backup ! • Scales on the fly ! • No downtime required to add/remove nodes © 2014 Hazelcast Inc. 7
  • 8.
    Configuring & forminga cluster © 2014 Hazelcast Inc. 8
  • 9.
    Forming a Cluster • Hazelcast Clusters run on JVM • Hazelcast discovers other instances via Multicast (Default) • Use TCP/IP lists when Multicast not possible • Segregate Clusters on same network via configuration • Hazelcast can form clusters on Amazon EC2. © 2014 Hazelcast Inc. 9
  • 10.
    Hazelcast Configuration -Server • Only one jar - look for hazelcast-all-x.x.x.jar ! • Hazelcast searches for hazelcast.xml on class path ! • Will use hazelcast-default.xml for everything else. ! • Hazelcast can be configured via XML,API or Spring ! • Configure Networks, Data Structures, Indexes,Compute © 2014 Hazelcast Inc. 10
  • 11.
    Form a cluster 1. Sample hazelcast.xml looks like this © 2014 Hazelcast Inc. 11
  • 12.
    TOP TIP •The <group> configuration element is your friend. ! • It will help you isolate your cluster on the multicast network. ! • Don’t make the mistake of joining another developers cluster or worse still a Production Cluster! © 2014 Hazelcast Inc. 12
  • 13.
    Configuration via API 1. Add GroupConfig to the Config instance. © 2014 Hazelcast Inc. 13
  • 14.
    TOP TIP •You can run multiple Hazelcast instances in one JVM. ! • Handy for unit testing. ! © 2014 Hazelcast Inc. 14
  • 15.
    Configure Cluster touse TCP/IP 1. Edit multicast enabled = false 2. Add tcp-ip element with your ip address © 2014 Hazelcast Inc. 15
  • 16.
    Client Configuration ©2014 Hazelcast Inc. 16
  • 17.
    Hazelcast Configuration -Client • Hazelcast searches for hazelcast-client.xml on class path • Full API stack - Client API same as Server API • Clients in Java, C#, C++, Memcache, REST © 2014 Hazelcast Inc. 17
  • 18.
    Starting as aClient or Cluster JVM © 2014 Hazelcast Inc. 18 Notice Client and Cluster return same HazelcastInstance reference.
  • 19.
    Code Migration ©2014 Hazelcast Inc. 19
  • 20.
    Migration - Terracottato Hazelcast • Terracotta implementation of cache puts/gets: ! ! ! ! • Replace Terracotta implementation by Hazelcast code: © 2014 Hazelcast Inc. 20
  • 21.
    Migration - Terracottato Hazelcast • Terracotta implementation of Blocking Queue(notice the complex APIs): ! ! ! ! • Replace Terracotta by Hazelcast Queue (notice the simplicity): © 2014 Hazelcast Inc. 21
  • 22.
    Topologies © 2014Hazelcast Inc. 22
  • 23.
    Hazelcast Topologies •Traditional Client -> Server (Client -> Cluster) ! • Clients do not take part in standard cluster coms. ! • Consider Client -> Cluster topology to segregate service from storage. ! • Smart Clients connect to all Clusters nodes. Operations go directly to node holding data. ! • Embedded model, for example in a J2EE container. service and storage within one JVM. © 2014 Hazelcast Inc. 23
  • 24.
    Terracotta Cluster ©2014 Hazelcast Inc. 24
  • 25.
    Embedded Hazelcast ©2014 Hazelcast Inc. 25
  • 26.
    Client Server ->(Client -> Cluster) © 2014 Hazelcast Inc. 26
  • 27.
    Distributed Collections ©2014 Hazelcast Inc. 27
  • 28.
    Maps © 2014Hazelcast Inc. 28
  • 29.
    Distributed Maps -IMap • Conforms to the java.util.Map interface ! • Conforms to the java.util.ConcurrentMap interface ! • Hazelcast IMap interface provides extra features EntryListeners Aggregators Predicate Queries Locking Eviction © 2014 Hazelcast Inc. 29
  • 30.
    Wildcard Configuration •Hazelcast support wildcards for config. © 2014 Hazelcast Inc. 30 • Beware of ambiguous config though. • Hazelcast doesn’t pick best match and what it picks is random not in the order it appears in config.
  • 31.
    Properties • Hazelcastsupports property replacement in XML config © 2014 Hazelcast Inc. 31 • Uses System Properties by default • A Properties Loader can be configured
  • 32.
    Near Cache •Terracotta L1 Cache -> Hazelcast Near Cache ! • Highly recommended for read-mostly maps © 2014 Hazelcast Inc. 32
  • 33.
    Replicated Map ©2014 Hazelcast Inc. 33 • Does not partition data. • Copies Map Entry to every Cluster JVM. ! • Consider for immutable slow moving data like config. ! • ReplicatedMap interface supports EntryListeners. !
  • 34.
    Data Distribution andResource Management © 2014 Hazelcast Inc. 34
  • 35.
    Data Distribution •Data (primary + backup) is distributed in cluster using partitions ! • 271 default partitions ! • Partitions are divided among running cluster JVMs. ! • Discovery of resident partition performed by the client before sending out update/get calls ! • In smart-client setup, requests go directly to the host node ! • Hazelcast places a backup of the Map Entry on another partition as part of the Map.put © 2014 Hazelcast Inc. 35
  • 36.
    Data Distribution •The backup operation can be sync (default) or async to the Map.put ! • Each node acts as Primary and Backup compare to Active-Passive on dedicated resources setup in Terracotta - efficient use of resources ! • When cluster JVM enters or leaves, cluster partitions are rebalanced ! • In event of a node failure - – Primary data is retrieved from backup and distributed across remaining nodes in cluster – New backup is created on good nodes © 2014 Hazelcast Inc. 36
  • 37.
    Data Distribution ©2014 Hazelcast Inc. 37 Fixed number of partitions (default 271) Each key falls into a partition partitionId = hash(keyData)%PARTITION_COUNT Partition ownerships are reassigned upon membership A B C
  • 38.
    New Node Added A B C D © 2014 Hazelcast Inc.
  • 39.
    Migration A BC D © 2014 Hazelcast Inc.
  • 40.
    Migration A BC D © 2014 Hazelcast Inc.
  • 41.
    Migration A BC D © 2014 Hazelcast Inc.
  • 42.
    Migration A BC D © 2014 Hazelcast Inc.
  • 43.
    Migration A BC D © 2014 Hazelcast Inc.
  • 44.
    Migration A BC D © 2014 Hazelcast Inc.
  • 45.
    Migration Complete AB C D © 2014 Hazelcast Inc. Crash
  • 46.
    Fault Tolerance &Recovery © 2014 Hazelcast Inc. 46
  • 47.
    Node Crashes AB C D © 2014 Hazelcast Inc. Crash
  • 48.
    Backups are Restored A B C D © 2014 Hazelcast Inc. Crash
  • 49.
    Backups are Restored A B C D © 2014 Hazelcast Inc. Crash
  • 50.
    Backups are Restored A B C D © 2014 Hazelcast Inc. Crash
  • 51.
    Backups are Restored A B C D © 2014 Hazelcast Inc. Crash
  • 52.
    Data is Recoveredfrom backup A B C D © 2014 Hazelcast Inc. Crash
  • 53.
    Data is Recoveredfrom backup A B C D © 2014 Hazelcast Inc. Crash
  • 54.
    Backup for RecoveredData A B C D © 2014 Hazelcast Inc. Crash
  • 55.
    Backup for RecoveredData A B C D © 2014 Hazelcast Inc. Crash
  • 56.
    Backup for RecoveredData A B C D © 2014 Hazelcast Inc. Crash
  • 57.
    All Safe ©2014 Hazelcast Inc. A C D
  • 58.
    In Memory Format& Serialization © 2014 Hazelcast Inc. 58
  • 59.
    In Memory Format • Flexibility in data store format compared to Terracotta’s binary only • By default, data in memory is binary (serialised) format. • Local Processing on a node has to keep deserialising. • Use OBJECT if local processing (entry processor,executors) • Use BINARY if get(ing) data over the network © 2014 Hazelcast Inc. 59
  • 60.
    Serialization © 2014Hazelcast Inc. 60 • Custom Serialization as against “Serializable” only option in Terracotta – DataSerializable • Fine grained control over serialization • Uses Reflection to create class instance • “implements DataSerializable” – public void writeData(ObjectDataOutput out) – public void readData(ObjectDataInput in) – IdentifiedDataSerializable • Better version of DataSerializable • Avoids Reflection - faster serialization • extends DataSerializable • Two new methods - – int getId() - used instead of classname – int getFactoryId() - used to load the class given to Id
  • 61.
    Distributed Compute ©2014 Hazelcast Inc. 61
  • 62.
    Distributed Executor Service © 2014 Hazelcast Inc. 62
  • 63.
    Distributed Executor ©2014 Hazelcast Inc. 63 • IExectorService extends java.util.concurrent.ExecutorService • Send a Runnable or Callable into the Cluster • Targetable Execution All Members Member MemberSelector KeyOwner • sync/async blocking based on Futures • Or ExecutionCallback notifies onResponse !
  • 64.
    Distributed Executor •If System Resources permit you can scale up the number of threads the ExecutorService uses. © 2014 Hazelcast Inc. 64 !! ! !
  • 65.
    Distributed Executor ©2014 Hazelcast Inc. 65 ! ! • Each Member creates its own work queue. • Tasks are not partitioned or load balanced. • If member dies while task is enqueue on member it is lost. • You need to lock any data you access, but beware of Deadlocks! !
  • 66.
    EntryProcessor © 2014Hazelcast Inc. 66
  • 67.
    EntryProcessor • ADistributed Map Entry Processor Function • Provides locking guarantees • Work directly on the Entry object in a node • Executed on the Partition Thread rather than the Executor • Submitted via the IMap • Best to apply delta updates without moving the object across the network © 2014 Hazelcast Inc. 67
  • 68.
    EntryProcessor © 2014Hazelcast Inc. 68 • EntryProcessor also mutates the Backup copy • Use the AbstractEntryProcesssor for default backup behaviour • Implement EntryProcessor directly to provide your own Backup behaviour, for example sending delta only ! • Only alternative to Terracotta DSO
  • 69.
    EntryProcessor © 2014Hazelcast Inc. 69
  • 70.
    EntryProcessor © 2014Hazelcast Inc. 70 • Other tasks run on Partition Thread (Puts, Gets) • It is important to yield the EntryProcessor • hazelcast.entryprocessor.batch.max.size: Defaults to 10.000 • Hazelcast will not interrupt a running operation it only yields when the current Key has been processed.
  • 71.
    In-memory Map Reduce © 2014 Hazelcast Inc. 71
  • 72.
    MAP Reduce ©2014 Hazelcast Inc. 72 • In-memory Map/Reduce compared to disk bound M/R • Similar paradigm to Hadoop Map/Reduce • Familiar nomenclature for ease of understanding and use – JobTracker – Job – Mapper – CombinerFactory – Reducer – Collator
  • 73.
    Distributed Aggregation ©2014 Hazelcast Inc. 73
  • 74.
    Aggregators © 2014Hazelcast Inc. 74 • Ready-to-use in-memory data aggregation algorithms • Implemented on top of Hazelcast MapReduce framework • More convenient than MR for large set of standard operations • Work on both - IMap and MultiMap • Types of aggregation: – Average, Sum, Min, Max, DistinctValues, Count
  • 75.
    Querying © 2014Hazelcast Inc. 75
  • 76.
    Querying with Predicates • Rich Predicate API that can be run against IMap, similar to criterion based Terracotta Search Collection<V> IMap.values(Predicate p) Set<K> IMap.keySet(Predicate p) Set<Map.Entry<K,V>> IMap.entrySet(Predicate p) Set<K> IMap.localKeySet(Predicate p) © 2014 Hazelcast Inc. 76 !!
  • 77.
    Querying with Predicates © 2014 Hazelcast Inc. 77 notEqual instanceOf like (%,_) greaterThan greaterEqual lessThan lessEqual between in isNot regex
  • 78.
    Querying with Predicates © 2014 Hazelcast Inc. 78 • Create your own Predicates !!
  • 79.
    SQL like queries © 2014 Hazelcast Inc. 79 • SQLPredicate class. • Runs only on Values. • Converts the String to a set of concrete Predicates. !!
  • 80.
    Indexes © 2014Hazelcast Inc. 80 • Prevent full Map scans. • Indexes can be ordered or unordered. • Indexes can work along the Object Graph (x.y.z). • When indexing non primitives they must implement Comparable. • Indexes can be created at runtime. !!
  • 81.
    Conclusion © 2014Hazelcast Inc. 81
  • 82.
    Conclusion • Hazelcastis easy to use ! • Easy to migrate from Terracotta ! • Familiar naming convention ! • Lot more features and use cases than just a data store ! • On the fly scale ! • Zero downtime ! • No single point of failure © 2014 Hazelcast Inc. 82
  • 83.
    © 2014 HazelcastInc. Thank You ! @wildnez ! rahul@hazelcast.com 83