SlideShare a Scribd company logo
1 of 28
Download to read offline
How to
performance-tune
spark applications in
large clusters
- Omkar Joshi
Omkar Joshi
ojoshi@netflix.com
● Software engineer @ Netflix
● Architect & author of Marmaray
(Generic ingestion framework) @
Uber.
● Architected Object store & NFS
solutions at Hedvig
● Hadoop Yarn committer
● Enjoy gardening & hiking in free
time
01 JVM Profiler
02 Hadoop Profiler
03 Spark Listener
04 Auto tune
05 Storage improvements
06 Cpu / Runtime improvements
07 Efficiency improvements
08 Memory improvements
Agenda
JVM Profiler: Distributed
Profiling at a Large Scale
● Help tracking memory/cpu/stacktrace for large amount of Spark
executors
● Open sourced (https://github.com/uber-common/jvm-profiler)
● Presented in previous Spark Summit
● Some new update
Hadoop Profiler (Recap)
● Java Agent attached to each
executor
● Collects metrics via JMX and
/proc
● Instruments arbitrary Java user
code
● Emits to Kafka, InfluxDB, and
Redis and other data sinks
Method
Argument
Profiler
Method
duration
Profiler
CPU/Memory
Profiler
Reporter
Java Agent
Kafka InfluxDB
https://github.com/uber-common/jvm-profiler
Spark Listener
● Plugable Listener
○ spark.extraListeners=com.foo.MySparkListener
● Modify Spark Code and Send Execution Plan to Spark Listener
● Generate Data Lineage Information
● Offline Analysis for Spark Task Execution
Auto Tune
● Problem: data scientist using team level Spark conf template
● Known Daily Applications
○ Use historical run to set Spark configurations (memory, vcore, etc.) *
● Ad-hoc Repeated (Daily) Applications
○ Use Machine Learning to predict resource usage
○ Challenge: Feature Engineering
■ Execution Plan
Project [user_id, product_id, price]
Filter (date = 2019-01-31 and product_id = xyz)
UnresolvedRelation datalake.user_purchase
Open Sourced in September 2018
https://github.com/uber/marmaray
Blog Post:
https://eng.uber.com/marmaray-hado
op-ingestion-open-source/
High-Level Architecture
Chain of converters
Schema Service
Input
Storage
System
Source
Connector
M3 Monitoring System
Work
Unit
Calculator
Metadata Manager
(Checkpoint store)
Converter1 Converter 2
Sink
Connector
Output
Storage
System
Error Tables
Datafeed Config Store
Spark execution framework
Spark job
improvements
Storage
improvements
Effective data layout (parquet)
● Parquet uses columnar compression
● Columnar compression savings outperform gz or snappy compression
savings
● Align records such that adjacent rows have identical column values
○ Eg. For state column California.
● Sort records with increasing value of cardinality.
● Generalization sometimes is not possible; If it is a framework provide custom
sorting.
User Id First Name City State Rider score
abc123011101 John New York City New York 4.95
abc123011102 Michael San Francisco California 4.92
abc123011103 Andrea Seattle Washington 4.93
abc123011104 Robert Atlanta City Georgia 4.95
User Id First Name City State Rider score
cas123032203 Sheetal Atlanta City Georgia 4.97
dsc123022320 Nikki Atlanta City Georgia 4.95
ssd012320212 Dhiraj Atlanta City Georgia 4.94
abc123011104 Robert Atlanta City Georgia 4.95
CPU / Runtime
improvements
Custom Spark accumulators
● Problem
○ Given a set of ride records; remove duplicate ride records and also count duplicates per state
1. RDD<String> rideRecords =
javaSparkContext.readParquet(some_path);
2. Map<String, Long> ridesPerStateBeforeDup
= rideRecords.map(r ->
getState(r)).countByKey();
3. RDD<String> dedupRideRecords =
dedup(rideRecords);
4. Map<String, Long> ridesPerStateAfterDup =
dedupRideRecords.map(r ->
getState(r)).countByKey();
5. dedupRideRecords.write(some_hdfs_path);
6. Duplicates = Diff(ridesPerStateAfterDup,
ridesPerStateBeforeDup)
7. # spark stages = 5 ( 3 for countByKey)
1. Class RidesPerStateAccumulator extends
AccumulatorV2<Map<String, Long>>
2. RidesPerStateAccumulator
riderPerStateBeforeDup, riderPerStateAfterDup;
3. dedup(javaSparkContext.readParquet(some_pat
h).map(r -> {riderPerStateBeforeDup.add(r);
return r;})).map(r ->
{riderPerStateAfterDup.add(r); return
r;}).write(some_hdfs_path);
4. Duplicates = Diff(ridesPerStateAfterDup,
ridesPerStateBeforeDup)
5. # spark Stages = 2 (no counting overhead!!)
Kafka topic
256 Partitions
3Billion messsages per
run
Increasing kafka read parallelism
Kafka
Broker
1 Kafka
consumer
/ partition
(256
tasks)
1 Kafka
consumer per
Kafka partition
Each consumer
reading 12Million
messages
Spark Stage 1
Sparkshuffleservice
Shuffle
Write
(1.3TB)
Spark Stage 2
8192
tasks
Shuffle
Read
(1.3TB)
Kafka
Broker
>1 Kafka consumer
per Kafka partition
Each consumer reading
384K messages
1 Kafka partition split
into 32 virtual
partitions
Spark Stage 2
8192
tasks
Increasing kafka read parallelism contd..
2
1
● Why Kryo?
○ Lesser memory footprint than Java serializer.
○ Faster and supports custom serializer
● Bug fix to truly enable kryo serialization
○ Spark kryo config prefix change.
● What all is needed to take advantage of that
○ Set “spark.serializer” to “org.apache.spark.serializer.KryoSerializer”
○ Registering avro schemas to spark conf (sparkConf.registerAvroSchemas())
■ Useful if you are using Avro GenericRecord (Schema + Data)
○ Register all classes which are needed while doing spark transformation
■ Use “spark.kryo.classesToRegister”
■ Use “spark.kryo.registrationRequired” to find missing classes
Kryo serialization
Kryo serialization contd..
Data (128)
Data (128)
Data (128)
Data (128)
Data (128)
Avro Schema (4K)
Avro Schema (4K)
Avro Schema (4K)
Avro Schema (4K)
Avro Schema (4K)
Data (128)
Data (128)
Data (128)
Data (128)
Data (128)
Schema identifier(4)
Schema identifier(4)
Schema identifier(4)
Schema identifier(4)
Schema identifier(4)
1 Record = 4228 Bytes 1 Record = 132 Bytes (97% savings)
Reduce ser/deser time by restructuring payload
1. @AllArgsConstructor
2. @Getter
3. private class SparkPayload {
4. private final String sortingKey;
5. // Map with 1000+ entries.
6. private final Map<String, GenericRecord>
data;
7. }
8.
1. @Getter
2. private class SparkPayload {
3. private final String sortingKey;
4. // Map with 1000+ entries.
5. private final byte[] serializedData;
6.
7. public SparkPayload(final String sortingKey,
Map<String, GenericRecord> data) {
8. this.sortingKey = sortingKey;
9. this.serializedData =
KryoSerializer.serialize(data);
10. }
11.
12. public Map<String, GenericRecord> getData() {
13. return
KryoSerializer.deserialize(this.serializedData,
Map.class);
14. }
15. }
Parallelizing spark’s iterator
jsc.mapPartitions (iterator -> while (i.hasnext) { parquetWriter.write(i.next); })
MapPartitions Stage (~45min) MapPartitions Stage (~25min)
Reading from disk
Fetching record from
Spark’s Iterator
Writing to Parquet
Writer in memory
Parquet columnar
compression
FileSystem write
Reading from disk
Fetching record from
Spark’s Iterator
Writing to Parquet
Writer in memory
Parquet columnar
compression
FileSystem write
Spark’s Thread
New writer
Thread
Memory
buffer
Spark’s Thread
Efficiency
improvements
Improve utilization by sharing same spark resources
JavaSparkContext.readFromKafka(“topic
1”).writeToHdfs();
JavaSparkContext.readFromKafka(“topic
1”).writeToHdfs();
JavaSparkContext.readFromKafka(“topic
3”).writeToHdfs();
JavaSparkContext.readFromKafka(“topic
2”).writeToHdfs();
JavaSparkContext.readFromKafka(“topic
N”).writeToHdfs();Threadpoolwith#threads=parallelism
needed
Improve utilization by sharing same spark resources
Time
ExecutorId
Stage Boundaries
Lot of wastage!!!
Improve utilization by sharing same spark resources
Time
ExecutorId
Stage Boundaries
Memory
improvements
Off heap memory improvements (work in progress)
● Symptom
○ Container killed by YARN for exceeding memory limits. 10.4 GB of 10.4 GB physical memory used. Consider
boosting spark.yarn.executor.memoryOverhead
● Solution as per stack overflow :)
○ Increase “spark.yarn.executor.memoryOverhead”
○ Result - Huge memory wastage.
● Spark memory distribution
○ Heap & off-heap memory (direct & memory mapped)
● Possible solutions
○ Avoid memory mapping or perform memory mapping chunk by chunk instead of entire file
(4-16MB vs 1GB)
● Current vs Target
○ Current - 7GB [Heap(4gb) + Off-heap(3gb)]
○ Target - 5GB [Heap(4gb) + Off-heap(1gb)] - ~28% memory reduction (per container)
Thank You!!
We are hiring!!
Please reach out to us if you would like to
work on the amazing problems.
Omkar Joshi (ojoshi@netflix.com)

More Related Content

What's hot

What's hot (20)

Scala+data
Scala+dataScala+data
Scala+data
 
InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...
InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...
InfluxDB IOx Tech Talks: Intro to the InfluxDB IOx Read Buffer - A Read-Optim...
 
Making Structured Streaming Ready for Production
Making Structured Streaming Ready for ProductionMaking Structured Streaming Ready for Production
Making Structured Streaming Ready for Production
 
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to SparkR | Big Data Hadoop Spark Tutorial | CloudxLab
 
hadoop
hadoophadoop
hadoop
 
Big Data Analytics with Scala at SCALA.IO 2013
Big Data Analytics with Scala at SCALA.IO 2013Big Data Analytics with Scala at SCALA.IO 2013
Big Data Analytics with Scala at SCALA.IO 2013
 
scalable machine learning
scalable machine learningscalable machine learning
scalable machine learning
 
Data Source API in Spark
Data Source API in SparkData Source API in Spark
Data Source API in Spark
 
Spark Streaming Tips for Devs and Ops
Spark Streaming Tips for Devs and OpsSpark Streaming Tips for Devs and Ops
Spark Streaming Tips for Devs and Ops
 
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Basics of RDD | Big Data Hadoop Spark Tutorial | CloudxLab
 
Advanced goldengate training ⅰ
Advanced goldengate training ⅰAdvanced goldengate training ⅰ
Advanced goldengate training ⅰ
 
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLabApache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
Apache Spark - Key-Value RDD | Big Data Hadoop Spark Tutorial | CloudxLab
 
MapReduce - Basics | Big Data Hadoop Spark Tutorial | CloudxLab
MapReduce - Basics | Big Data Hadoop Spark Tutorial | CloudxLabMapReduce - Basics | Big Data Hadoop Spark Tutorial | CloudxLab
MapReduce - Basics | Big Data Hadoop Spark Tutorial | CloudxLab
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Shrug2017 arcpy data_and_you
Shrug2017 arcpy data_and_youShrug2017 arcpy data_and_you
Shrug2017 arcpy data_and_you
 
Distributed Real-Time Stream Processing: Why and How 2.0
Distributed Real-Time Stream Processing:  Why and How 2.0Distributed Real-Time Stream Processing:  Why and How 2.0
Distributed Real-Time Stream Processing: Why and How 2.0
 
Dive into Catalyst
Dive into CatalystDive into Catalyst
Dive into Catalyst
 
Apache Calcite: A Foundational Framework for Optimized Query Processing Over ...
Apache Calcite: A Foundational Framework for Optimized Query Processing Over ...Apache Calcite: A Foundational Framework for Optimized Query Processing Over ...
Apache Calcite: A Foundational Framework for Optimized Query Processing Over ...
 
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
PSUG #52 Dataflow and simplified reactive programming with Akka-streamsPSUG #52 Dataflow and simplified reactive programming with Akka-streams
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
 
Sparkling Water
Sparkling WaterSparkling Water
Sparkling Water
 

Similar to How to performance tune spark applications in large clusters

Similar to How to performance tune spark applications in large clusters (20)

Speed up UDFs with GPUs using the RAPIDS Accelerator
Speed up UDFs with GPUs using the RAPIDS AcceleratorSpeed up UDFs with GPUs using the RAPIDS Accelerator
Speed up UDFs with GPUs using the RAPIDS Accelerator
 
Build Large-Scale Data Analytics and AI Pipeline Using RayDP
Build Large-Scale Data Analytics and AI Pipeline Using RayDPBuild Large-Scale Data Analytics and AI Pipeline Using RayDP
Build Large-Scale Data Analytics and AI Pipeline Using RayDP
 
Spark ETL Techniques - Creating An Optimal Fantasy Baseball Roster
Spark ETL Techniques - Creating An Optimal Fantasy Baseball RosterSpark ETL Techniques - Creating An Optimal Fantasy Baseball Roster
Spark ETL Techniques - Creating An Optimal Fantasy Baseball Roster
 
Apache Spark Workshop
Apache Spark WorkshopApache Spark Workshop
Apache Spark Workshop
 
Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...
Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...
Updates from Project Hydrogen: Unifying State-of-the-Art AI and Big Data in A...
 
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
Spark SQL Catalyst Code Optimization using Function Outlining with Kavana Bha...
 
Advanced .NET Data Access with Dapper
Advanced .NET Data Access with Dapper Advanced .NET Data Access with Dapper
Advanced .NET Data Access with Dapper
 
Jump Start into Apache® Spark™ and Databricks
Jump Start into Apache® Spark™ and DatabricksJump Start into Apache® Spark™ and Databricks
Jump Start into Apache® Spark™ and Databricks
 
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-MallaKerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
Kerberizing Spark: Spark Summit East talk by Abel Rincon and Jorge Lopez-Malla
 
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Exploiting GPU's for Columnar DataFrrames by Kiran LonikarExploiting GPU's for Columnar DataFrrames by Kiran Lonikar
Exploiting GPU's for Columnar DataFrrames by Kiran Lonikar
 
20170126 big data processing
20170126 big data processing20170126 big data processing
20170126 big data processing
 
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
 
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
 
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
[AI04] Scaling Machine Learning to Big Data Using SparkML and SparkR
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache Calcite
 
DAGScheduler - The Internals of Apache Spark.pdf
DAGScheduler - The Internals of Apache Spark.pdfDAGScheduler - The Internals of Apache Spark.pdf
DAGScheduler - The Internals of Apache Spark.pdf
 
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
 
Parallelizing Existing R Packages
Parallelizing Existing R PackagesParallelizing Existing R Packages
Parallelizing Existing R Packages
 
Apache Spark
Apache SparkApache Spark
Apache Spark
 

Recently uploaded

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 

How to performance tune spark applications in large clusters

  • 1. How to performance-tune spark applications in large clusters - Omkar Joshi
  • 2. Omkar Joshi ojoshi@netflix.com ● Software engineer @ Netflix ● Architect & author of Marmaray (Generic ingestion framework) @ Uber. ● Architected Object store & NFS solutions at Hedvig ● Hadoop Yarn committer ● Enjoy gardening & hiking in free time
  • 3. 01 JVM Profiler 02 Hadoop Profiler 03 Spark Listener 04 Auto tune 05 Storage improvements 06 Cpu / Runtime improvements 07 Efficiency improvements 08 Memory improvements Agenda
  • 4. JVM Profiler: Distributed Profiling at a Large Scale ● Help tracking memory/cpu/stacktrace for large amount of Spark executors ● Open sourced (https://github.com/uber-common/jvm-profiler) ● Presented in previous Spark Summit ● Some new update
  • 5. Hadoop Profiler (Recap) ● Java Agent attached to each executor ● Collects metrics via JMX and /proc ● Instruments arbitrary Java user code ● Emits to Kafka, InfluxDB, and Redis and other data sinks Method Argument Profiler Method duration Profiler CPU/Memory Profiler Reporter Java Agent Kafka InfluxDB https://github.com/uber-common/jvm-profiler
  • 6. Spark Listener ● Plugable Listener ○ spark.extraListeners=com.foo.MySparkListener ● Modify Spark Code and Send Execution Plan to Spark Listener ● Generate Data Lineage Information ● Offline Analysis for Spark Task Execution
  • 7. Auto Tune ● Problem: data scientist using team level Spark conf template ● Known Daily Applications ○ Use historical run to set Spark configurations (memory, vcore, etc.) * ● Ad-hoc Repeated (Daily) Applications ○ Use Machine Learning to predict resource usage ○ Challenge: Feature Engineering ■ Execution Plan Project [user_id, product_id, price] Filter (date = 2019-01-31 and product_id = xyz) UnresolvedRelation datalake.user_purchase
  • 8. Open Sourced in September 2018 https://github.com/uber/marmaray Blog Post: https://eng.uber.com/marmaray-hado op-ingestion-open-source/
  • 9. High-Level Architecture Chain of converters Schema Service Input Storage System Source Connector M3 Monitoring System Work Unit Calculator Metadata Manager (Checkpoint store) Converter1 Converter 2 Sink Connector Output Storage System Error Tables Datafeed Config Store Spark execution framework
  • 12. Effective data layout (parquet) ● Parquet uses columnar compression ● Columnar compression savings outperform gz or snappy compression savings ● Align records such that adjacent rows have identical column values ○ Eg. For state column California. ● Sort records with increasing value of cardinality. ● Generalization sometimes is not possible; If it is a framework provide custom sorting.
  • 13. User Id First Name City State Rider score abc123011101 John New York City New York 4.95 abc123011102 Michael San Francisco California 4.92 abc123011103 Andrea Seattle Washington 4.93 abc123011104 Robert Atlanta City Georgia 4.95 User Id First Name City State Rider score cas123032203 Sheetal Atlanta City Georgia 4.97 dsc123022320 Nikki Atlanta City Georgia 4.95 ssd012320212 Dhiraj Atlanta City Georgia 4.94 abc123011104 Robert Atlanta City Georgia 4.95
  • 15. Custom Spark accumulators ● Problem ○ Given a set of ride records; remove duplicate ride records and also count duplicates per state 1. RDD<String> rideRecords = javaSparkContext.readParquet(some_path); 2. Map<String, Long> ridesPerStateBeforeDup = rideRecords.map(r -> getState(r)).countByKey(); 3. RDD<String> dedupRideRecords = dedup(rideRecords); 4. Map<String, Long> ridesPerStateAfterDup = dedupRideRecords.map(r -> getState(r)).countByKey(); 5. dedupRideRecords.write(some_hdfs_path); 6. Duplicates = Diff(ridesPerStateAfterDup, ridesPerStateBeforeDup) 7. # spark stages = 5 ( 3 for countByKey) 1. Class RidesPerStateAccumulator extends AccumulatorV2<Map<String, Long>> 2. RidesPerStateAccumulator riderPerStateBeforeDup, riderPerStateAfterDup; 3. dedup(javaSparkContext.readParquet(some_pat h).map(r -> {riderPerStateBeforeDup.add(r); return r;})).map(r -> {riderPerStateAfterDup.add(r); return r;}).write(some_hdfs_path); 4. Duplicates = Diff(ridesPerStateAfterDup, ridesPerStateBeforeDup) 5. # spark Stages = 2 (no counting overhead!!)
  • 16. Kafka topic 256 Partitions 3Billion messsages per run Increasing kafka read parallelism Kafka Broker 1 Kafka consumer / partition (256 tasks) 1 Kafka consumer per Kafka partition Each consumer reading 12Million messages Spark Stage 1 Sparkshuffleservice Shuffle Write (1.3TB) Spark Stage 2 8192 tasks Shuffle Read (1.3TB) Kafka Broker >1 Kafka consumer per Kafka partition Each consumer reading 384K messages 1 Kafka partition split into 32 virtual partitions Spark Stage 2 8192 tasks
  • 17. Increasing kafka read parallelism contd.. 2 1
  • 18. ● Why Kryo? ○ Lesser memory footprint than Java serializer. ○ Faster and supports custom serializer ● Bug fix to truly enable kryo serialization ○ Spark kryo config prefix change. ● What all is needed to take advantage of that ○ Set “spark.serializer” to “org.apache.spark.serializer.KryoSerializer” ○ Registering avro schemas to spark conf (sparkConf.registerAvroSchemas()) ■ Useful if you are using Avro GenericRecord (Schema + Data) ○ Register all classes which are needed while doing spark transformation ■ Use “spark.kryo.classesToRegister” ■ Use “spark.kryo.registrationRequired” to find missing classes Kryo serialization
  • 19. Kryo serialization contd.. Data (128) Data (128) Data (128) Data (128) Data (128) Avro Schema (4K) Avro Schema (4K) Avro Schema (4K) Avro Schema (4K) Avro Schema (4K) Data (128) Data (128) Data (128) Data (128) Data (128) Schema identifier(4) Schema identifier(4) Schema identifier(4) Schema identifier(4) Schema identifier(4) 1 Record = 4228 Bytes 1 Record = 132 Bytes (97% savings)
  • 20. Reduce ser/deser time by restructuring payload 1. @AllArgsConstructor 2. @Getter 3. private class SparkPayload { 4. private final String sortingKey; 5. // Map with 1000+ entries. 6. private final Map<String, GenericRecord> data; 7. } 8. 1. @Getter 2. private class SparkPayload { 3. private final String sortingKey; 4. // Map with 1000+ entries. 5. private final byte[] serializedData; 6. 7. public SparkPayload(final String sortingKey, Map<String, GenericRecord> data) { 8. this.sortingKey = sortingKey; 9. this.serializedData = KryoSerializer.serialize(data); 10. } 11. 12. public Map<String, GenericRecord> getData() { 13. return KryoSerializer.deserialize(this.serializedData, Map.class); 14. } 15. }
  • 21. Parallelizing spark’s iterator jsc.mapPartitions (iterator -> while (i.hasnext) { parquetWriter.write(i.next); }) MapPartitions Stage (~45min) MapPartitions Stage (~25min) Reading from disk Fetching record from Spark’s Iterator Writing to Parquet Writer in memory Parquet columnar compression FileSystem write Reading from disk Fetching record from Spark’s Iterator Writing to Parquet Writer in memory Parquet columnar compression FileSystem write Spark’s Thread New writer Thread Memory buffer Spark’s Thread
  • 23. Improve utilization by sharing same spark resources JavaSparkContext.readFromKafka(“topic 1”).writeToHdfs(); JavaSparkContext.readFromKafka(“topic 1”).writeToHdfs(); JavaSparkContext.readFromKafka(“topic 3”).writeToHdfs(); JavaSparkContext.readFromKafka(“topic 2”).writeToHdfs(); JavaSparkContext.readFromKafka(“topic N”).writeToHdfs();Threadpoolwith#threads=parallelism needed
  • 24. Improve utilization by sharing same spark resources Time ExecutorId Stage Boundaries Lot of wastage!!!
  • 25. Improve utilization by sharing same spark resources Time ExecutorId Stage Boundaries
  • 27. Off heap memory improvements (work in progress) ● Symptom ○ Container killed by YARN for exceeding memory limits. 10.4 GB of 10.4 GB physical memory used. Consider boosting spark.yarn.executor.memoryOverhead ● Solution as per stack overflow :) ○ Increase “spark.yarn.executor.memoryOverhead” ○ Result - Huge memory wastage. ● Spark memory distribution ○ Heap & off-heap memory (direct & memory mapped) ● Possible solutions ○ Avoid memory mapping or perform memory mapping chunk by chunk instead of entire file (4-16MB vs 1GB) ● Current vs Target ○ Current - 7GB [Heap(4gb) + Off-heap(3gb)] ○ Target - 5GB [Heap(4gb) + Off-heap(1gb)] - ~28% memory reduction (per container)
  • 28. Thank You!! We are hiring!! Please reach out to us if you would like to work on the amazing problems. Omkar Joshi (ojoshi@netflix.com)