Webinar: Maximizing Hazelcast Performance with Serialization FUAD MALIKOV CO-FOUNDER
About me Fuad Malikov @fuadm Hazelcast co-founder Java Developer since 2005 Worked at Financials and Telco s. Leading Hazelcast Support 2
Agenda - 45 Minutes + Q&A Serialization Basics Java Serialization Data Serializable / Portable Pluggable Serialization More on Configuration Extra Resources Q&A 3
What is Serialization? Serializing a Java object into binary De-serializing a binary data into Java object 4
Where is Serialization used? Key / Value Queue / Set / List Items Executor Service Entry Processor Lock Topic Messages 5
Example serializa(on + de- serializa(on serializa(on serializa(on serializa(on serializa(on de- serializa(on 6
Put Operation Serialization Cycle Request: Key and Value is serialized cartmap.put(1, cart); Response: Old value is de-serialized key: 1 Node A Node B 7
Optimized types 8 Byte Boolean Character Short Integer Long Float Double byte[] char[] short[] int[] long[] float[] double[] String Date BigInteger BigDecimal Class Enum
Special Types Java Serialization java.io.serializable java.io.externalizable Hazelcast com.hazelcast.nio.serialization.dataserializable com.hazelcast.nio.serialization.identifieddataserializable com.hazelcast.nio.serialization.portable Custom Serialization 9
Sample Domain Shopping Cart 10
Shopping Cart Item 11
Shopping Cart 12
Benchmark 100,000 times maxorders = 100 * 1000 maxcartitem= 5 13
java.io.serializable Pros Standard Doesn t require any implementation Cons 14 Takes more time and cpu Occupies more space
java.io.serializable - Results Read Performance 31 ops in ms Write Performance 46 ops in ms Binary object size 15 525 bytes
java.io.externalizable Pros Standard Efficient than Serializable in terms of CPU and Memory Cons Requires to implement the actual serialization 16
ShoppingCartItem - implementation 17
ShoppingCart- implementation 18
java.io.externalizable - Results Read Performance 61 ops in ms Write Performance 60 ops in ms Binary object size 19 235 bytes
DataSerializable Pros Efficient than Serializable in terms of CPU and Memory Cons Hazelcast specific Requires to implement the actual serialization Uses Reflection while de-serializing 20
ShoppingCartItem - implementation 21
ShoppingCart- implementation 22
DataSerializable- Results Read Performance 64 ops in ms Write Performance 59 ops in ms Binary object size 23 231 bytes
IdentifiedDataSerializable Pros Efficient than Serializable in terms of CPU and Memory Doesn t use Reflection while de-serializing Cons 24 Hazelcast specific Requires to implement the actual serialization Requires to implement a Factory and configuration
ShoppingCartItem - implementation 25
ShoppingCart- implementation 26
IdentifiedDataSerializable Factory Implementation 27
IdentifiedDataSerializable- Results Read Performance 68 ops in ms Write Performance 60 ops in ms Binary object size 28 186 bytes
Portable Pros Efficient than Serializable in terms of CPU and Memory Doesn t use Reflection while de-serializing Supports versioning Supports partial de-serialization during Queries Cons Hazelcast specific Requires to implement the actual serialization Requires to implement a Factory and Class Definition Class definition is also sent together with Data but stored only once per class 29
ShoppingCartItem - implementation 30
ShoppingCart- implementation 31
Portable Factory Implementation 32
Portable- Results Read Performance 65 ops in ms Write Performance 54 ops in ms Binary object size 386 bytes 33
Pluggable (ex: Kryo) Pros Doesn t require class to implement an interface Very convenient and flexible Can be stream based or byte array based Cons Requires to implement the actual serialization Requires to plug and configure 34
Stream and ByteArray Serializers 35
ShoppingCartItem - implementation 36
ShoppingCart- implementation 37
ShoppingCart Kryo StreamSerializer 38
Pluggable Serialization Configuration 39
Kryo- Results Read Performance 60 ops in ms Write Performance 51 ops in ms Binary object size 210 bytes 40
Native Byte Order & Unsafe Enables fast copy of primitive arrays like byte[], long[] and etc. Default is big endian. 41
Compression Compresses the data. Can be applied to Serializable and Externalizable only. Very slow (~1000 times) and CPU consuming. Can reduce 525 bytes to 26 bytes. 42
SharedObject Default is false If set true, it will back-reference an object pointing to a previously serialize instance 43
Summary Serializable R:31 ops/ms, W: 46 ops/ms, Size: 525 bytes Externalizable R:61 ops/ms, W: 60 ops/ms, Size: 235 bytes DataSerializable R:64 ops/ms, W: 59 ops/ms, Size: 231 bytes IdentifiedDataSerializable R:68 ops/ms, W: 60 ops/ms, Size: 186 bytes Portable R:65 ops/ms, W: 54 ops/ms, Size: 386 bytes Kryo R:60 ops/ms, W: 51 ops/ms, Size: 210 bytes 44
More resources www.hazelcast.org www.hazelcast.com http://hazelcast.org/comparinghazelcast-3-serialization-methods-withkryo-serialization/ http://www.hazelcast.com/resources/thebook-of-hazelcast/ A more detailed blog post on serialization on real cluster coming soon 45
Any Ques(ons? 46