Serialization and
performance
Сергей Моренец
23 мая 2014 г.
About author
Works in IT since 2000
10 year of Java SE/EE experience
Occupied senior Java developer/Team
Lead positions
Wi...
Agenda
• Purpose of serialization
• Frameworks overview
• Performance testing
• Q & A
Serialization
File storages
Database
Network communication
Web usage
Serialization
Simple
Flexible
Compact
Versioning
Fast Scalable
Data formats
Binary
XML
JSON
YAML
Performance
• Native memory copying using C operations
• “Unsafe” operations
• Ignore object introspection
• Direct object...
Java serialization
• The easiest programming effort
• Out-of-the-box functionality
Java serialization
• Serializable interface
• Decreases the flexibility to change a class’s
implementation once it has bee...
Java externalization
• Serialization but by implementing
Externalizable interface to persist and
restore the object
• Resp...
Java externalization
Avro
• Schema evolution
• Binary and JSON encoding
• Dynamic typing
• Support of Java, C, C++, C# and Python
• Apache Hado...
Avro
Avro
XML
• Interchangeable format
• Supported schemas
• Space intensive and huge performance loss
• Complex navigating
Simple
• High performance XML serialization and
configuration framework for Java.
• Requires absolutely no configuration
•...
Simple
Javolution
• Fast real-time library for safety-critical
applications
• Based on OSGi context
• Parallel computing support
Javolution
Json-io
• Doesn’t require custom interfaces/attributes
usage/source code
• Handles cyclic references
• Reader/writer custo...
Google gson
• Java library to convert JSON to Java objects and
vice-versa
• Doesn’t require source code of serialized obje...
Google gson
Jackson
• High-performance, ergonomic JSON processor
Java library
• Extensive customization tools
• Mix-in annotations
• M...
Jackson
• JSON
• CSV
• Smile(binary JSON)
• XML
• YAML(similar to JSON)
BSON for Jackson
• Binary encoded JSON
• Main data exchange format for MongoDB
• Allows writing custom extensions
Protocol buffers
• Way of encoding structured data in an efficient
yet extensible format.
• Google uses Protocol Buffers f...
Protocol buffers
message User {
required string login = 1;
repeated Order orders = 2;
}
message Order {
required int32 id ...
Protocol buffers
FST
• Java-to-java library
• No support for versioning
• Use case is high performance message oriented
software
• Drop-in ...
FST
GridGain
• Part of distributed computing system
• Don’t require any custom interfaces or API
• Direct memory copying by in...
GridGain
Kryo
• Fast and efficient object graph serialization
framework for Java
• Open source project on Google code
• Automatic d...
Kryo
• Twitter
• Apache Hive
• Akka
• Storm
• S4
Kryo
Kryo
Benchmark
• JDK 1.8.0.5
• Apache Avro 1.7.6
• Simple 2.7.1
• Json-io 2.5.2
• Google GSON 2.2.4
• Jackson 2.3.2
• BSON for ...
Benchmark
• Speed(serialization and deserialization)
• Size(complex and ordinary objects)
• Flexibility
Benchmark
Benchmark
Issues
Library Description
Gson, Jackson Crashed when serializing cyclic
dependency
Simple Crashed for very big XML file
A...
Serialization (complex)
# Library Time(ms)
1 Kryo(optimized) 134
2 Protocol buffers 165
3 GridGain 196
4 FST 207
5 Kryo 20...
Serialization (simple)
# Library Time(ms)
1 Protocol buffers <1
2 Google GSON 5
3 Java serialization 10
4 BSON for Jackson...
Deserialization (complex)
# Library Time(ms)
1 Kryo(optimized) 113
2 Protocol buffers 165
3 GridGain 196
4 FST 207
5 Kryo ...
Deserialization (simple)
# Library Time(ms)
1 Protocol buffers 1
2 GridGain 3
3 Google GSON 6
4 Jackson(smile) 9
5 BSON fo...
Size (complex)
# Library Size(bytes)
1 Kryo(optimized) 33904
2 FST 34069
3 Kryo 35674
4 Protocol buffers 39517
5 Kryo(unsa...
Size (simple)
# Library Size(bytes)
1 Kryo(optimized) 18
2 Kryo 18
3 Protocol buffers 20
4 Kryo(unsafe) 21
5 GridGain 33
6...
Usability
# Library
1 Google GSON
2 Kryo
2 Kryo(unsafe)
3 Jackson
3 Jackson(XML, Smile, YAML)
3 BSON for Jackson
4 Json-io...
Overall rating (2014)
# Library Rating
1 Kryo(optimized) 67
2 Protocol buffers 65
3 Kryo 58
4 Jackson(smile) 55
5 Kryo(uns...
Overall rating (2013)
# Library Rating
1 Kryo(optimized) 67
2 Kryo(unsafe) 65
3 Protocol buffers 63
4 Kryo 59
5 Jackson(sm...
Advices
Library Usage
Kryo Fast and compact serializer for complex
objects over network
Protocol buffers Fast serializer f...
Сергей Моренец
morenets@mail.ru
Q&A
Upcoming SlideShare
Loading in...5
×

Serialization and performance in Java

2,143

Published on

1. Serialization overview
2. Java libraries for serialization.
3. Benchmarking

Published in: Technology, Education
0 Comments
35 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,143
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
77
Comments
0
Likes
35
Embeds 0
No embeds

No notes for slide

Serialization and performance in Java

  1. 1. Serialization and performance Сергей Моренец 23 мая 2014 г.
  2. 2. About author Works in IT since 2000 10 year of Java SE/EE experience Occupied senior Java developer/Team Lead positions Winner of 2013 JBoss Community Recognition Award. https://www.jboss.org/jbcra
  3. 3. Agenda • Purpose of serialization • Frameworks overview • Performance testing • Q & A
  4. 4. Serialization File storages Database Network communication Web usage
  5. 5. Serialization Simple Flexible Compact Versioning Fast Scalable
  6. 6. Data formats Binary XML JSON YAML
  7. 7. Performance • Native memory copying using C operations • “Unsafe” operations • Ignore object introspection • Direct object-object copying
  8. 8. Java serialization • The easiest programming effort • Out-of-the-box functionality
  9. 9. Java serialization • Serializable interface • Decreases the flexibility to change a class’s implementation once it has been released • Doesn’t allow to exchange data with C++/Python applications • Due to default constructors hole for invariant corruption and illegal access • No customization • You should have access to the source code No customization You should have access to the source code
  10. 10. Java externalization • Serialization but by implementing Externalizable interface to persist and restore the object • Responsibility of the class to save and restore the contents of its instances • Requires modifications in marshalling/unmarshalling code if the class contents changed No customization You should have access to the source code
  11. 11. Java externalization
  12. 12. Avro • Schema evolution • Binary and JSON encoding • Dynamic typing • Support of Java, C, C++, C# and Python • Apache Hadoop integration
  13. 13. Avro
  14. 14. Avro
  15. 15. XML • Interchangeable format • Supported schemas • Space intensive and huge performance loss • Complex navigating
  16. 16. Simple • High performance XML serialization and configuration framework for Java. • Requires absolutely no configuration • Can handle cycles in the object graph
  17. 17. Simple
  18. 18. Javolution • Fast real-time library for safety-critical applications • Based on OSGi context • Parallel computing support
  19. 19. Javolution
  20. 20. Json-io • Doesn’t require custom interfaces/attributes usage/source code • Handles cyclic references • Reader/writer customization • Does not depend on any native or 3rd party libraries.
  21. 21. Google gson • Java library to convert JSON to Java objects and vice-versa • Doesn’t require source code of serialized objects • Allow custom representatives
  22. 22. Google gson
  23. 23. Jackson • High-performance, ergonomic JSON processor Java library • Extensive customization tools • Mix-in annotations • Materialized interfaces • Multiple data formats
  24. 24. Jackson • JSON • CSV • Smile(binary JSON) • XML • YAML(similar to JSON)
  25. 25. BSON for Jackson • Binary encoded JSON • Main data exchange format for MongoDB • Allows writing custom extensions
  26. 26. Protocol buffers • Way of encoding structured data in an efficient yet extensible format. • Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats. • Supported in Java, C++, Python
  27. 27. Protocol buffers message User { required string login = 1; repeated Order orders = 2; } message Order { required int32 id = 1; optional string date = 2; }
  28. 28. Protocol buffers
  29. 29. FST • Java-to-java library • No support for versioning • Use case is high performance message oriented software • Drop-in replacement • Custom optimization using annotations, custom serializers
  30. 30. FST
  31. 31. GridGain • Part of distributed computing system • Don’t require any custom interfaces or API • Direct memory copying by invoking native "unsafe" operations • Predefined fields introspection
  32. 32. GridGain
  33. 33. Kryo • Fast and efficient object graph serialization framework for Java • Open source project on Google code • Automatic deep and shallow copying/cloning • Doesn’t put requirements on the source classes (in most cases)
  34. 34. Kryo • Twitter • Apache Hive • Akka • Storm • S4
  35. 35. Kryo
  36. 36. Kryo
  37. 37. Benchmark • JDK 1.8.0.5 • Apache Avro 1.7.6 • Simple 2.7.1 • Json-io 2.5.2 • Google GSON 2.2.4 • Jackson 2.3.2 • BSON for Jackson 2.3.1 • Protocol buffers 2.5 • Kryo 2.23 • FST 1.54 • GridGain 6.0.2
  38. 38. Benchmark • Speed(serialization and deserialization) • Size(complex and ordinary objects) • Flexibility
  39. 39. Benchmark
  40. 40. Benchmark
  41. 41. Issues Library Description Gson, Jackson Crashed when serializing cyclic dependency Simple Crashed for very big XML file Avro Bug during deserialization
  42. 42. Serialization (complex) # Library Time(ms) 1 Kryo(optimized) 134 2 Protocol buffers 165 3 GridGain 196 4 FST 207 5 Kryo 209 6 Jackson(smile) 275 7 Kryo(unsafe) 306 8 Jackson 491 9 Java serialization 605 10 Javolution 1043
  43. 43. Serialization (simple) # Library Time(ms) 1 Protocol buffers <1 2 Google GSON 5 3 Java serialization 10 4 BSON for Jackson 10 5 Jackson(smile) 11 6 Kryo(optimized) 17 7 Kryo 18 8 Jackson 18 9 Kryo(unsafe) 20 10 Javolution 21
  44. 44. Deserialization (complex) # Library Time(ms) 1 Kryo(optimized) 113 2 Protocol buffers 165 3 GridGain 196 4 FST 207 5 Kryo 209 6 Jackson(smile) 275 7 Kryo(unsafe) 306 8 Jackson 491 9 Java serialization 605 10 BSON for Jackson 930
  45. 45. Deserialization (simple) # Library Time(ms) 1 Protocol buffers 1 2 GridGain 3 3 Google GSON 6 4 Jackson(smile) 9 5 BSON for Jackson 9 6 Kryo(optimized) 18 7 Kryo 18 8 Jackson 18 9 Kryo(unsafe) 20 10 FST 42
  46. 46. Size (complex) # Library Size(bytes) 1 Kryo(optimized) 33904 2 FST 34069 3 Kryo 35674 4 Protocol buffers 39517 5 Kryo(unsafe) 40554 6 Jackson(smile) 44840 7 Java serialization 49757 8 GridGain 58288 9 Jackson 67858 10 Google GSON 68338
  47. 47. Size (simple) # Library Size(bytes) 1 Kryo(optimized) 18 2 Kryo 18 3 Protocol buffers 20 4 Kryo(unsafe) 21 5 GridGain 33 6 Jackson(smile) 40 7 Jackson 41 8 Google GSON 41 9 Jackson(YAML) 41 10 BSON for Jackson 46
  48. 48. Usability # Library 1 Google GSON 2 Kryo 2 Kryo(unsafe) 3 Jackson 3 Jackson(XML, Smile, YAML) 3 BSON for Jackson 4 Json-io 5 FST 6 Java serialization 7 Kryo(optimized)
  49. 49. Overall rating (2014) # Library Rating 1 Kryo(optimized) 67 2 Protocol buffers 65 3 Kryo 58 4 Jackson(smile) 55 5 Kryo(unsafe) 46 6 GridGain 44 7 Google GSON 43 8 FST 43 9 Jackson 40 10 BSON for Jackson 33 11 Java serialization 32
  50. 50. Overall rating (2013) # Library Rating 1 Kryo(optimized) 67 2 Kryo(unsafe) 65 3 Protocol buffers 63 4 Kryo 59 5 Jackson(smile) 51 6 Google GSON 45 7 FST 42 8 GridGain 34 9 Jackson 32 10 Java serialization 30 11 BSON for Jackson 24
  51. 51. Advices Library Usage Kryo Fast and compact serializer for complex objects over network Protocol buffers Fast serializer for simple objects Jackson(smile) Jackson-based serializer for Web usage Google JSON Dirty solution to quickly serialize/deserialize objects Apache Avro Serialize objects into files with possible schema changes Java Out-of-the-box trusted solution without additional libraries
  52. 52. Сергей Моренец morenets@mail.ru Q&A
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×