SlideShare a Scribd company logo
CODE GENERATION IN
SERIALIZERS AND
COMPARATORS OF APACHE
FLINK
GÁBOR HORVÁTH
PARADIGM SHIFT IN BIG DATA PLATFORMS
•Applications used to be I/O bound (Network,
Disk)
•InfiniBand, SSDs reduced I/O overhead
significantly
•CPU increasingly became a bottleneck
•Even in I/O bound applications, reduced CPU
usage might mean reduced electricity costs
SERIALIZATION IN FLINK
•Several methods: Avro, Kryo, Flink
•Flink serialization is more efficient than Kryo
• Not to mention the default Java serialization
•Crucial, not just for I/O, operating on serialized
data
•Still some room for improvements
SERIALIZATION IN FLINK
INEFFICIENCIES OF CURRENT FLINK
SERIALIZERS
• Fields accessed using reflection
• Each iteration might dispatch to a different method, inhibits
inlining
• Null checks and null and subclass flags
• Extra code to deal with subclasses
• Hard to unroll the loop, upper bound is not a compile time
for (int i = 0; i < numFields; i++) {
Object o = fields[i].get(value);
if (o == null) {
target.writeBoolean(true);
} else {
target.writeBoolean(false);
fieldSerializers[i].serialize(o, target);
}
}
SEVERAL SERIALIZER RELATED
INNOVATIONS IN APACHE FLINK
•Object reusing overloads
•Delicate type system
•Code generation (not mainline yet, this talk’s
topic)
• Fix the inefficiencies of Flink serializers
RUNTIME CODE GENERATION
• Focus on POJOs (Plain Old Java Objects)
• Best ROI due to eliminating reflection
• Specialization
• No reflection for serialization (direct field access code
generated)
• No null checks, subclass handling for primitive types
• No subclass handling for final types
• Unrolled loops, better for inlining
QUESTIONNAIRE
• Who has written a custom serializer to improve
performance?
• Who has written a custom comparator to improve
performance?
• Who used Tuples instead of POJOs only to improve
performance?
Who wants performance close to Tuples with null
value support?
LET’S SEE THE NUMBERS!
6X PERFORMANCE
IMPROVEMENT
Rest of Flink Job
Serializers/Compara
tors
NINE MEN’S MORRIS BENCHMARK
•Calculates game-theoretical values of game
states
•Iterative job
•Group by, reduce, outer joins, flat maps, and
filter
•Heavy use of POJOs
•Real world complexity
LET’S SEE THE NUMBERS!
•Measured on ReducePerformance,
WordCountPojo and Nine Men’s Morris on local
machine
•Measured ReducePerformance and Nine Men’s
Morris on a cluster
•The results were consistent
LET’S SEE THE NUMBERS! (LOCAL MACHINE)
0
10
20
30
40
50
60
Serializer: Flink Handwritten Generated Handwritten
Comparator: Flink Flink Generated Generated
CLOSE TO HAND WRITTEN SERIALIZERS
•About 20% speedup compared to Flink
serializers
•Some gap left to handwritten
• Smarter getLength
• Flattening
• Null and subclass flags
• Better handling of primitives (less
boxing/unboxing, inlining)
HOW DOES THIS WORK?
HIGH LEVEL OVERVIEW: THE TRADITIONAL
WAY
POJO
Object
Serialize
d
POJO
TypeInfo
Serialize
rPOJO
Class
Instantiate
HIGH LEVEL OVERVIEW: THE NEW WAY
POJO
Object
Generate
d
Serialize
r
Serialize
d
POJO
TypeInfo
FreeMark
er
Template
Janino
Serialize
r
Generato
r
POJO
Class
ClassLoad
er
Gábor Horváth - Code Generation in Serializers and Comparators of Apache Flink
HOW TO LOAD GENERATED CODE?
•We need to serialize serializers
•First step of deserialization: load the class
•Which ClassLoader to use?
•Custom ClassLoader to the rescue!
Sourc
e
Code
Class
Loader
MULTIPLE NODES/JVMS?
JVM
A
JVM
B
Serializer ?Serializ
er
MULTIPLE NODES/JVMS?
JVM
A
JVM
B
Wrapper
Serializ
er
Serializ
er
LET’S TRY IT OUT!
Class cast exception:
SerializerA cannot be
cast to SerializerA.
Gábor Horváth - Code Generation in Serializers and Comparators of Apache Flink
Gábor Horváth - Code Generation in Serializers and Comparators of Apache Flink
LETS CACHE AND TRY IT OUT!
Class cast exception:
UserObjectA cannot be
cast to UserObjcetA.
Gábor Horváth - Code Generation in Serializers and Comparators of Apache Flink
LETS CACHE AND INVALIDATE AND TRY IT
OUT!
ACTUALLY... THERE ARE COUPLE OF MORE
•Janino bugs
•Compatibility with Scala POJO like classes
•Generated code harder to debug
•…
WHAT’S NEXT?
• Versioning serialization format
• Replace reflection where performance matters
• d.sortPartition("f0.author", Order.DESCENDING);
• Better utilization of getLength information
• Eliminate redundant null/subclass flags
• Beating Tuples!
DISTANT FUTURE
•Vision: more JVM independent optimizations!
•Columnar serialization format (end to end
optimization)
• Final goal: Faster than naive handwritten serializers!
•Customized NormalizedKeySorter
•Lots of opportunities due to the delicate type
system
CONCLUSION
•Significant performance improvement
•Ground work for lots of possible performance
improvements
•ClassLoader issues are not newcommer
friendly
•Not part of mainline Flink yet, happy to receive
reviews 
ACKNOWLEDGEMENT
•Huge thanks to GSoC:
•Márton Balassi
•Gábor Gévay
•Thanks to data
Artisans for
brainstorming
•Thanks for your

More Related Content

PDF
Thomas Lamirault_Mohamed Amine Abdessemed -A brief history of time with Apac...
PPTX
Eron Wright - Flink Security Enhancements
PDF
Márton Balassi Streaming ML with Flink-
PPTX
Stephan Ewen - Scaling to large State
PDF
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
PPTX
RocksDB compaction
PPTX
RocksDB detail
PPTX
JVM++: The Graal VM
Thomas Lamirault_Mohamed Amine Abdessemed -A brief history of time with Apac...
Eron Wright - Flink Security Enhancements
Márton Balassi Streaming ML with Flink-
Stephan Ewen - Scaling to large State
Graal and Truffle: Modularity and Separation of Concerns as Cornerstones for ...
RocksDB compaction
RocksDB detail
JVM++: The Graal VM

Viewers also liked (20)

PPTX
Taking a look under the hood of Apache Flink's relational APIs.
PPTX
Eron Wright - Introducing Flink on Mesos
PDF
Trevor Grant - Apache Zeppelin - A friendlier way to Flink
PDF
Alexander Kolb - Flinkspector – Taming the squirrel
PDF
Ana M Martinez - AMIDST Toolbox- Scalable probabilistic machine learning with...
PDF
Maxim Fateev - Beyond the Watermark- On-Demand Backfilling in Flink
PPTX
Ted Dunning-Faster and Furiouser- Flink Drift
PDF
Dynamic Scaling: How Apache Flink Adapts to Changing Workloads (at FlinkForwa...
PDF
Julian Hyde - Streaming SQL
PPTX
Ted Dunning - Keynote: How Can We Take Flink Forward?
PDF
Sanjar Akhmedov - Joining Infinity – Windowless Stream Processing with Flink
PDF
Zoltán Zvara - Advanced visualization of Flink and Spark jobs

PPTX
Aljoscha Krettek - The Future of Apache Flink
PDF
Jamie Grier - Robust Stream Processing with Apache Flink
PPTX
Kostas Tzoumas_Stephan Ewen - Keynote -The maturing data streaming ecosystem ...
PDF
Malo Denielou - No shard left behind: Dynamic work rebalancing in Apache Beam
PPTX
Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...
PPTX
Stephan Ewen - Running Flink Everywhere
PPTX
Robert Metzger - Connecting Apache Flink to the World - Reviewing the streami...
PDF
Flink Case Study: Amadeus
Taking a look under the hood of Apache Flink's relational APIs.
Eron Wright - Introducing Flink on Mesos
Trevor Grant - Apache Zeppelin - A friendlier way to Flink
Alexander Kolb - Flinkspector – Taming the squirrel
Ana M Martinez - AMIDST Toolbox- Scalable probabilistic machine learning with...
Maxim Fateev - Beyond the Watermark- On-Demand Backfilling in Flink
Ted Dunning-Faster and Furiouser- Flink Drift
Dynamic Scaling: How Apache Flink Adapts to Changing Workloads (at FlinkForwa...
Julian Hyde - Streaming SQL
Ted Dunning - Keynote: How Can We Take Flink Forward?
Sanjar Akhmedov - Joining Infinity – Windowless Stream Processing with Flink
Zoltán Zvara - Advanced visualization of Flink and Spark jobs

Aljoscha Krettek - The Future of Apache Flink
Jamie Grier - Robust Stream Processing with Apache Flink
Kostas Tzoumas_Stephan Ewen - Keynote -The maturing data streaming ecosystem ...
Malo Denielou - No shard left behind: Dynamic work rebalancing in Apache Beam
Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...
Stephan Ewen - Running Flink Everywhere
Robert Metzger - Connecting Apache Flink to the World - Reviewing the streami...
Flink Case Study: Amadeus
Ad

Similar to Gábor Horváth - Code Generation in Serializers and Comparators of Apache Flink (20)

PDF
VoltDB and Erlang - Tech planet 2012
PDF
FP Days: Down the Clojure Rabbit Hole
PDF
Exploitation and State Machines
KEY
Messaging, interoperability and log aggregation - a new framework
PDF
CONDOR @ NGCLE@e-Novia 15.11.2017
PDF
Make static instrumentation great again, High performance fuzzing for Windows...
KEY
Bluffers guide to elitist jargon - Martijn Verburg, Richard Warburton, James ...
PDF
Smashing the stack with Hydra
PDF
Know thy cost (or where performance problems lurk)
PDF
When DevOps and Networking Intersect by Brent Salisbury of socketplane.io
PDF
DConf2015 - Using D for Development of Large Scale Primary Storage
PDF
Serving Deep Learning Models At Scale With RedisAI: Luca Antiga
PPTX
Realtime web2012
PPTX
The_Final_Presentation
PPTX
Blazingly-Fast:Introduction to Apache Fury Serialization
PDF
Redis Day Keynote Salvatore Sanfillipo Redis Labs
PDF
Ratpack for Real
PDF
PDF
To Infiniband and Beyond
VoltDB and Erlang - Tech planet 2012
FP Days: Down the Clojure Rabbit Hole
Exploitation and State Machines
Messaging, interoperability and log aggregation - a new framework
CONDOR @ NGCLE@e-Novia 15.11.2017
Make static instrumentation great again, High performance fuzzing for Windows...
Bluffers guide to elitist jargon - Martijn Verburg, Richard Warburton, James ...
Smashing the stack with Hydra
Know thy cost (or where performance problems lurk)
When DevOps and Networking Intersect by Brent Salisbury of socketplane.io
DConf2015 - Using D for Development of Large Scale Primary Storage
Serving Deep Learning Models At Scale With RedisAI: Luca Antiga
Realtime web2012
The_Final_Presentation
Blazingly-Fast:Introduction to Apache Fury Serialization
Redis Day Keynote Salvatore Sanfillipo Redis Labs
Ratpack for Real
To Infiniband and Beyond
Ad

More from Flink Forward (20)

PDF
Building a fully managed stream processing platform on Flink at scale for Lin...
PPTX
Evening out the uneven: dealing with skew in Flink
PPTX
“Alexa, be quiet!”: End-to-end near-real time model building and evaluation i...
PDF
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
PDF
Introducing the Apache Flink Kubernetes Operator
PPTX
Autoscaling Flink with Reactive Mode
PDF
Dynamically Scaling Data Streams across Multiple Kafka Clusters with Zero Fli...
PPTX
One sink to rule them all: Introducing the new Async Sink
PPTX
Tuning Apache Kafka Connectors for Flink.pptx
PDF
Flink powered stream processing platform at Pinterest
PPTX
Apache Flink in the Cloud-Native Era
PPTX
Where is my bottleneck? Performance troubleshooting in Flink
PPTX
Using the New Apache Flink Kubernetes Operator in a Production Deployment
PPTX
The Current State of Table API in 2022
PDF
Flink SQL on Pulsar made easy
PPTX
Dynamic Rule-based Real-time Market Data Alerts
PPTX
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
PPTX
Processing Semantically-Ordered Streams in Financial Services
PDF
Tame the small files problem and optimize data layout for streaming ingestion...
PDF
Batch Processing at Scale with Flink & Iceberg
Building a fully managed stream processing platform on Flink at scale for Lin...
Evening out the uneven: dealing with skew in Flink
“Alexa, be quiet!”: End-to-end near-real time model building and evaluation i...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing the Apache Flink Kubernetes Operator
Autoscaling Flink with Reactive Mode
Dynamically Scaling Data Streams across Multiple Kafka Clusters with Zero Fli...
One sink to rule them all: Introducing the new Async Sink
Tuning Apache Kafka Connectors for Flink.pptx
Flink powered stream processing platform at Pinterest
Apache Flink in the Cloud-Native Era
Where is my bottleneck? Performance troubleshooting in Flink
Using the New Apache Flink Kubernetes Operator in a Production Deployment
The Current State of Table API in 2022
Flink SQL on Pulsar made easy
Dynamic Rule-based Real-time Market Data Alerts
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
Processing Semantically-Ordered Streams in Financial Services
Tame the small files problem and optimize data layout for streaming ingestion...
Batch Processing at Scale with Flink & Iceberg

Recently uploaded (20)

PDF
[EN] Industrial Machine Downtime Prediction
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
Introduction to machine learning and Linear Models
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
PDF
Introduction to the R Programming Language
PPTX
SAP 2 completion done . PRESENTATION.pptx
PPTX
STERILIZATION AND DISINFECTION-1.ppthhhbx
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PDF
annual-report-2024-2025 original latest.
PPTX
Database Infoormation System (DBIS).pptx
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PDF
Mega Projects Data Mega Projects Data
PDF
Business Analytics and business intelligence.pdf
PPTX
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
PDF
.pdf is not working space design for the following data for the following dat...
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
[EN] Industrial Machine Downtime Prediction
Data_Analytics_and_PowerBI_Presentation.pptx
IBA_Chapter_11_Slides_Final_Accessible.pptx
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
Introduction to machine learning and Linear Models
STUDY DESIGN details- Lt Col Maksud (21).pptx
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
Introduction to the R Programming Language
SAP 2 completion done . PRESENTATION.pptx
STERILIZATION AND DISINFECTION-1.ppthhhbx
Galatica Smart Energy Infrastructure Startup Pitch Deck
annual-report-2024-2025 original latest.
Database Infoormation System (DBIS).pptx
Miokarditis (Inflamasi pada Otot Jantung)
Mega Projects Data Mega Projects Data
Business Analytics and business intelligence.pdf
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
.pdf is not working space design for the following data for the following dat...
Clinical guidelines as a resource for EBP(1).pdf
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx

Gábor Horváth - Code Generation in Serializers and Comparators of Apache Flink

  • 1. CODE GENERATION IN SERIALIZERS AND COMPARATORS OF APACHE FLINK GÁBOR HORVÁTH
  • 2. PARADIGM SHIFT IN BIG DATA PLATFORMS •Applications used to be I/O bound (Network, Disk) •InfiniBand, SSDs reduced I/O overhead significantly •CPU increasingly became a bottleneck •Even in I/O bound applications, reduced CPU usage might mean reduced electricity costs
  • 3. SERIALIZATION IN FLINK •Several methods: Avro, Kryo, Flink •Flink serialization is more efficient than Kryo • Not to mention the default Java serialization •Crucial, not just for I/O, operating on serialized data •Still some room for improvements
  • 5. INEFFICIENCIES OF CURRENT FLINK SERIALIZERS • Fields accessed using reflection • Each iteration might dispatch to a different method, inhibits inlining • Null checks and null and subclass flags • Extra code to deal with subclasses • Hard to unroll the loop, upper bound is not a compile time for (int i = 0; i < numFields; i++) { Object o = fields[i].get(value); if (o == null) { target.writeBoolean(true); } else { target.writeBoolean(false); fieldSerializers[i].serialize(o, target); } }
  • 6. SEVERAL SERIALIZER RELATED INNOVATIONS IN APACHE FLINK •Object reusing overloads •Delicate type system •Code generation (not mainline yet, this talk’s topic) • Fix the inefficiencies of Flink serializers
  • 7. RUNTIME CODE GENERATION • Focus on POJOs (Plain Old Java Objects) • Best ROI due to eliminating reflection • Specialization • No reflection for serialization (direct field access code generated) • No null checks, subclass handling for primitive types • No subclass handling for final types • Unrolled loops, better for inlining
  • 8. QUESTIONNAIRE • Who has written a custom serializer to improve performance? • Who has written a custom comparator to improve performance? • Who used Tuples instead of POJOs only to improve performance? Who wants performance close to Tuples with null value support?
  • 9. LET’S SEE THE NUMBERS! 6X PERFORMANCE IMPROVEMENT Rest of Flink Job Serializers/Compara tors
  • 10. NINE MEN’S MORRIS BENCHMARK •Calculates game-theoretical values of game states •Iterative job •Group by, reduce, outer joins, flat maps, and filter •Heavy use of POJOs •Real world complexity
  • 11. LET’S SEE THE NUMBERS! •Measured on ReducePerformance, WordCountPojo and Nine Men’s Morris on local machine •Measured ReducePerformance and Nine Men’s Morris on a cluster •The results were consistent
  • 12. LET’S SEE THE NUMBERS! (LOCAL MACHINE) 0 10 20 30 40 50 60 Serializer: Flink Handwritten Generated Handwritten Comparator: Flink Flink Generated Generated
  • 13. CLOSE TO HAND WRITTEN SERIALIZERS •About 20% speedup compared to Flink serializers •Some gap left to handwritten • Smarter getLength • Flattening • Null and subclass flags • Better handling of primitives (less boxing/unboxing, inlining)
  • 14. HOW DOES THIS WORK?
  • 15. HIGH LEVEL OVERVIEW: THE TRADITIONAL WAY POJO Object Serialize d POJO TypeInfo Serialize rPOJO Class Instantiate
  • 16. HIGH LEVEL OVERVIEW: THE NEW WAY POJO Object Generate d Serialize r Serialize d POJO TypeInfo FreeMark er Template Janino Serialize r Generato r POJO Class ClassLoad er
  • 18. HOW TO LOAD GENERATED CODE? •We need to serialize serializers •First step of deserialization: load the class •Which ClassLoader to use? •Custom ClassLoader to the rescue! Sourc e Code Class Loader
  • 21. LET’S TRY IT OUT! Class cast exception: SerializerA cannot be cast to SerializerA.
  • 24. LETS CACHE AND TRY IT OUT! Class cast exception: UserObjectA cannot be cast to UserObjcetA.
  • 26. LETS CACHE AND INVALIDATE AND TRY IT OUT!
  • 27. ACTUALLY... THERE ARE COUPLE OF MORE •Janino bugs •Compatibility with Scala POJO like classes •Generated code harder to debug •…
  • 28. WHAT’S NEXT? • Versioning serialization format • Replace reflection where performance matters • d.sortPartition("f0.author", Order.DESCENDING); • Better utilization of getLength information • Eliminate redundant null/subclass flags • Beating Tuples!
  • 29. DISTANT FUTURE •Vision: more JVM independent optimizations! •Columnar serialization format (end to end optimization) • Final goal: Faster than naive handwritten serializers! •Customized NormalizedKeySorter •Lots of opportunities due to the delicate type system
  • 30. CONCLUSION •Significant performance improvement •Ground work for lots of possible performance improvements •ClassLoader issues are not newcommer friendly •Not part of mainline Flink yet, happy to receive reviews 
  • 31. ACKNOWLEDGEMENT •Huge thanks to GSoC: •Márton Balassi •Gábor Gévay •Thanks to data Artisans for brainstorming •Thanks for your