SlideShare a Scribd company logo
From HDFS to S3: Migrate Pinterest Apache Spark Clusters
From HDFS to S3: Migrate
Pinterest Apache Spark Clusters
Xin Yao, Daniel Dai
Pinterest
About us
Xin Yao xyao@pinterest.com
▪ Tech Lead at Pinterest (Ads Team)
▪ Previously on Data Warehouse team at Facebook and Hulu
Daniel Dai jdai@pinterest.com
▪ Tech Lead at Pinterest (Data Team)
▪ PMC member for Apache Hive and Pig
▪ Previously work at Cloudera/Hortonworks and Yahoo
Agenda
▪ NextGen Big Data Platform
▪ Performance
▪ S3 Consistency
▪ Storage Difference
▪ Scheduling
▪ Spark at Pinterest
Agenda
▪ NextGen Big Data Platform
▪ Performance
▪ S3 Consistency
▪ Storage Difference
▪ Scheduling
▪ Spark at Pinterest
Big Data Platform
Spark Hive
Mesos/Aurora
HDFS
Kafka
Presto
▪ Use Cases
▪ Ads
▪ Machine Learning
▪ Recommendations
▪ ...
Old vs New cluster
Spark Hive
Mesos/Aurora
HDFS
Kafka
Old Cluster New Cluster
Presto
Spark Hive
YARN
S3
Kafka
Presto
Agenda
▪ NextGen Big Data Platform
▪ Performance
▪ S3 Consistency
▪ Storage Difference
▪ Scheduling
▪ Spark at Pinterest
Identify Bottleneck of Old Cluster
Low local
disk IOPS
Slow
Shuffle
Slow Job
Slow
Workflow
Old Cluster: Performance Bottleneck
Why Local Disk IO is important for Spark
▪ Spark mappers write shuffle data to local disk
▪ Spark mappers read local disk to serve shuffle data for reducer
▪ Spark spills data to local disk when data is bigger than memory
A Simple Aggregation Query
SELECT id, max(value)
FROM table
GROUP BY id
9k Mappers * 9k Reducers
map
map
map
...
reducer
reducer
reducer
...
9K Mappers
Network
9k ReducersMapper Local Disk
Mappers Reducers
9k * 9k | One Mapper Machine
map
map
reducer
reducer
reducer
Local Disk 270k IO Ops
Too many for our machine
...
30 Mappers
...
One Mapper Machine | 30 Mappers
Mapper machine
...
...
How to optimize jobs in old Cluster
Optimization. Reduce # of Mapper/Reducer
map
map
map
...
reducer
reducer
reducer
...
3K Mappers Network 3k Reducersmapper local disk
input
input
input
input
input
input
input
input
input
More files per Mapper
NetworkMappers Reducers
Optimization
map
map
map
...
reducer
reducer
reducer
input
input
input
input
input
input
input
input
input
mapper local disk 30k Ops
9X better
One Mapper Machine | 10 Mappers
...
10 Mappers
...
Mapper machine
...
input
input
input
...
Result
Building NEW cluster
New Cluster: Choose the right EC2 instance
Old Cluster New Cluster
EC2 Node Local Disk IOPS
Cap 3k 40k
EC2 Node Type r4.16xlarge r5d.12xlarge
EC2 Node CPU 64 vcores 48 vcores
EC2 Node Mem 480 GB 372 GB
Production Result
§ After migration, prod jobs have 25% improvement on avg,
without any extra resources and tuning
§ One typical heavy job even got 35% improvement from 90
minutes to 57 minutes
Old Cluster New Cluster
Key Takeaways
▪ Measure before Optimize
▪ Premature optimization is the root of all evil
Key Takeaways
▪ Optimization could happen at different levels
▪ Cluster level
▪ New EC2 instance type
▪ Spark level
▪ Mapper number/cpu/mem tuning
▪ Job level
▪ Simplify logic
Agenda
▪ NextGen Big Data Platform
▪ Performance
▪ S3 Consistency
▪ Storage Difference
▪ Scheduling
▪ Spark at Pinterest
S3 != HDFS
▪ HDFS is a filesystem that is strong consistent. Changes are
immediately visible
▪ S3 is an object storage service that is eventually consistent. There
is no guarantee a change is immediately visible to the client. This
might cause missing file issue without reader even know it.
Read after write consistency
Spark Job read less files from S3
How often does this happen
▪ Numbers from AWS: less than 1 in 10 million
▪ Numbers from our test: less than 1 in 50 million
Solution. Considerations
▪ Write Consistency
▪ Whether the job could write the output consistently, without partial or
corrupted data as long as the job succeed. Even when some of the tasks
failed or retried.
▪ Read Consistency
▪ Whether the job could read files in a folder, no more or less than it supposed
to read.
▪ Monitor Consistency
▪ Requires Reader or Writer side change
▪ Query Performance
Solution. Considerations
▪ Storage
▪ Isolation
▪ Transaction
▪ Supports Spark
▪ Supports Hive/Presto
▪ Project Origin
▪ Adoption Effort
Solutions sorted by the complexity, simple => complex
Raw S3 Data
Quality
Read
Monitor
Write
Waiting
Write Listing S3Committe
r
Consistent
Listing
S3Guard
Iceberg Delta Lake
Monitor
Consistency
No Partial Partial No No No N/A N/A N/A
Write
Consistency
No No No No No Yes Yes Yes Yes
Read
Consistency
No No Partial Partial Partial No Yes Yes Yes
Reader/Writer
change
No No No Writer Writer Writer R/W R/W R/W
Query
Performance
Normal Normal Normal Normal Normal Normal Normal Good Good
Storage Normal Normal Normal Normal Normal Normal Normal Good Good
Isolation No No No No No No No Strong
Snapshot
Strong
Snapshot
Transaction No No No No No No No Table Table
Supports Spark Yes Yes Yes Yes Yes Yes Yes Yes Yes
Supports
Hive/Presto
Yes Yes Yes Yes* Yes* Yes Yes WIP WIP
Project Origin In House In House Not Exist Not Exist Not Exist Netflix OSS Hadoop 3.0 Apache
Incubator
Databricks OSS
Effort None M M M M L XL XL
Our Approach
▪ Short Term
▪ S3 Committer
▪ Number of file monitor
▪ Data quality tool
▪ Long Term
▪ Systematical solutions
Agenda
▪ NextGen Big Data Platform
▪ Performance
▪ S3 Consistency
▪ Storage Difference
▪ Scheduling
▪ Spark at Pinterest
Performance Comparison: S3 vs HDFS
▪ Similar throughput
▪ Metadata operation is slow, especially move operation
▪ Our Spark streaming job is heavily impacted
▪ Spending most time moving output files around (3 times)
13s
55s
Microbatch Runtime
Dealing with Metadata Operation
▪ Move file at least twice in a Spark Application
▪ commitTask
▪ commitJob
▪ May also move to the Hive table location
output/_temporary/taskId/_temporary/taskAttemptID/part-xxxxxx
output/_temporary/taskId/part-xxxxxx
output/part-xxxxxx
/warehouse/pinterest.db/table/date=20200626
commitTask
commitJob
Hive MoveTask
df.write.mode(SaveMode.Append).insertInto(partitionedTable)
Reduce Move Operations
▪ FileOutputCommitter algorithm 2
▪ spark.hadoop.mapreduce.fileoutputcommitter.algorithm.version=2
▪ Skip move operation in job level, only task level
▪ DirectOutputCommitter
▪ Further skip move operation at task level
▪ Problem: File corruption when job fail
▪ Netflix s3committer
▪ spark.sql.sources.outputCommitterClass=com.netflix.bdp.s3.S3PartitionedOutputCommitter
▪ Use multi-part upload api, no move operation
▪ Other solutions
▪ Iceberg
▪ Hadoop s3acommitter
Multipart Upload API
▪ For every file
▪ initiateMultipartUpload
▪ Multiple uploadPart
▪ Finally completeMultipartUpload/abortMultipartUpload
▪ AWS will save all parts until
completeMultipartUpload/abortMultipartUpload
▪ Setup a lifecycle policy
▪ Separate s3 permission for abortMultipartUpload
S3committer
▪ Upload File to Output Directly use multi-part upload api
▪ Atomic completeMultipartUpload leaves no corrupt output
▪ Parallel upload parts of a file to increase throughput
uploadPart
completeMultipartUpload
commitTask
commitJob
The Last Move Operation
▪ Before: Use staging directory to figure out the new partitions
▪ After: A table level tracking file for the new partitions
ds=20200101
ds=20200102
ds=20200103
ds=20200104
ds=20200105
ds=20200106
ds=20200107
ds=20200108
ds=20200109
ds=20200110
ds=20200111
Table
ds=20200112
Staging Directory
.s3_dyn_parts
ds=20200101
ds=20200102
ds=20200103
ds=20200104
ds=20200105
ds=20200106
ds=20200107
ds=20200108
ds=20200109
ds=20200110
ds=20200111
ds=20200112
Table
ds=20200112
The Result
13s
11s
Microbatch runtime
13s
55s
Microbatch runtime
HFDS
S3
HFDS
S3
Fix Bucket Rate Limit Issue (503)
▪ S3 bucket partition
▪ Task and Job level retry
▪ Tune the parallelism in part file uploads
Improving S3Committer
▪ Fix Bucket Rate Limit (503)
▪ Parallel upload parts of a file to increase throughput
▪ Integrity check of S3 multipart upload ETags
▪ Fix thread pool leaking for long-running application
▪ Remove local output early
S3 Benefit Compare to HDFS
▪ Reduce 80% storage cost
▪ S3: 99.99% availability, 99.999999999% durability
▪ HDFS: 99.9% target availability
▪ Namenode single point failure
▪ Potential data lost
Agenda
▪ NextGen Big Data Platform
▪ Performance
▪ S3 Consistency
▪ Storage Difference
▪ Scheduling
▪ Spark at Pinterest
Things We Miss in Mesos
▪ Manage services inside Mesos
▪ Simple workflow, long running job and cron job via Aurora
▪ Rolling restart
▪ Built-in health check
Things We Like in Yarn
▪ Global view of all running applications
▪ Better queue management for organization isolation
▪ Consolidate with the rest of clusters
Cost Saving
▪ We achieve cost savings with YARN
▪ Queue isolation
▪ Preemption
Agenda
▪ NextGen Big Data Platform
▪ Performance
▪ S3 Consistency
▪ Storage Difference
▪ Scheduling
▪ Spark at Pinterest
Spark at Pinterest
▪ We are still in the early stages
▪ Spark represents 12% of all compute resource usage
▪ Batch use case
▪ Mostly Scala, also PySpark
We Are Working On
▪ Automatic migration from Hive -> Spark SQL
▪ Cascading/Scalding -> Spark
▪ Adopting Dr Elephant for Spark
▪ Used for code review
▪ Integrate with internal metrics system
▪ Include features from Sparklens
▪ Spark history server performance
xyao@pinterest.com
jdai@pinterest.com
Feedback
Your feedback is important to us.
Don’t forget to rate and
review the sessions.

More Related Content

What's hot (20)

PDF
Incremental View Maintenance with Coral, DBT, and Iceberg
Walaa Eldin Moustafa
 
PDF
Introduction to apache spark
Aakashdata
 
PDF
Apache Iceberg - A Table Format for Hige Analytic Datasets
Alluxio, Inc.
 
PDF
Apache Iceberg: An Architectural Look Under the Covers
ScyllaDB
 
PDF
Databricks Delta Lake and Its Benefits
Databricks
 
PDF
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Databricks
 
PDF
Deep Dive into the New Features of Apache Spark 3.0
Databricks
 
PDF
Understanding and Improving Code Generation
Databricks
 
PDF
Scaling your Data Pipelines with Apache Spark on Kubernetes
Databricks
 
PDF
Building Lakehouses on Delta Lake with SQL Analytics Primer
Databricks
 
PPTX
Siligong.Data - May 2021 - Transforming your analytics workflow with dbt
Jon Su
 
PDF
Lakehouse in Azure
Sergio Zenatti Filho
 
PDF
Introduction to Spark Internals
Pietro Michiardi
 
PDF
Pipelines and Data Flows: Introduction to Data Integration in Azure Synapse A...
Cathrine Wilhelmsen
 
PDF
Building End-to-End Delta Pipelines on GCP
Databricks
 
PDF
Cosco: An Efficient Facebook-Scale Shuffle Service
Databricks
 
PPTX
Azure Databricks - An Introduction (by Kris Bock)
Daniel Toomey
 
PDF
The Parquet Format and Performance Optimization Opportunities
Databricks
 
PDF
Apache flink
pranay kumar
 
PDF
Intro to Delta Lake
Databricks
 
Incremental View Maintenance with Coral, DBT, and Iceberg
Walaa Eldin Moustafa
 
Introduction to apache spark
Aakashdata
 
Apache Iceberg - A Table Format for Hige Analytic Datasets
Alluxio, Inc.
 
Apache Iceberg: An Architectural Look Under the Covers
ScyllaDB
 
Databricks Delta Lake and Its Benefits
Databricks
 
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Databricks
 
Deep Dive into the New Features of Apache Spark 3.0
Databricks
 
Understanding and Improving Code Generation
Databricks
 
Scaling your Data Pipelines with Apache Spark on Kubernetes
Databricks
 
Building Lakehouses on Delta Lake with SQL Analytics Primer
Databricks
 
Siligong.Data - May 2021 - Transforming your analytics workflow with dbt
Jon Su
 
Lakehouse in Azure
Sergio Zenatti Filho
 
Introduction to Spark Internals
Pietro Michiardi
 
Pipelines and Data Flows: Introduction to Data Integration in Azure Synapse A...
Cathrine Wilhelmsen
 
Building End-to-End Delta Pipelines on GCP
Databricks
 
Cosco: An Efficient Facebook-Scale Shuffle Service
Databricks
 
Azure Databricks - An Introduction (by Kris Bock)
Daniel Toomey
 
The Parquet Format and Performance Optimization Opportunities
Databricks
 
Apache flink
pranay kumar
 
Intro to Delta Lake
Databricks
 

Similar to From HDFS to S3: Migrate Pinterest Apache Spark Clusters (20)

PDF
Healthcare Claim Reimbursement using Apache Spark
Databricks
 
PDF
Fine Tuning and Enhancing Performance of Apache Spark Jobs
Databricks
 
PDF
700 Queries Per Second with Updates: Spark As A Real-Time Web Service
Spark Summit
 
PDF
700 Updatable Queries Per Second: Spark as a Real-Time Web Service
Evan Chan
 
PDF
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Be...
Codemotion
 
PDF
Leveraging Databricks for Spark pipelines
Rose Toomey
 
PDF
Leveraging Databricks for Spark Pipelines
Rose Toomey
 
PDF
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
Codemotion Tel Aviv
 
PDF
Scala like distributed collections - dumping time-series data with apache spark
Demi Ben-Ari
 
PDF
Revealing the Power of Legacy Machine Data
Databricks
 
PDF
It's Time To Stop Using Lambda Architecture
Yaroslav Tkachenko
 
PDF
Understanding and building big data Architectures - NoSQL
Hyderabad Scalability Meetup
 
PPTX
AWS Big Data Demystified #1: Big data architecture lessons learned
Omid Vahdaty
 
PDF
New Developments in Spark
Databricks
 
PDF
DatEngConf SF16 - Apache Kudu: Fast Analytics on Fast Data
Hakka Labs
 
PDF
Using Databricks as an Analysis Platform
Databricks
 
PPTX
A Comparative Performance Evaluation of Apache Flink
Dongwon Kim
 
PDF
Dongwon Kim – A Comparative Performance Evaluation of Flink
Flink Forward
 
PDF
It's Time To Stop Using Lambda Architecture | Yaroslav Tkachenko, Shopify
HostedbyConfluent
 
PDF
Migrating ETL Workflow to Apache Spark at Scale in Pinterest
Databricks
 
Healthcare Claim Reimbursement using Apache Spark
Databricks
 
Fine Tuning and Enhancing Performance of Apache Spark Jobs
Databricks
 
700 Queries Per Second with Updates: Spark As A Real-Time Web Service
Spark Summit
 
700 Updatable Queries Per Second: Spark as a Real-Time Web Service
Evan Chan
 
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Be...
Codemotion
 
Leveraging Databricks for Spark pipelines
Rose Toomey
 
Leveraging Databricks for Spark Pipelines
Rose Toomey
 
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
Codemotion Tel Aviv
 
Scala like distributed collections - dumping time-series data with apache spark
Demi Ben-Ari
 
Revealing the Power of Legacy Machine Data
Databricks
 
It's Time To Stop Using Lambda Architecture
Yaroslav Tkachenko
 
Understanding and building big data Architectures - NoSQL
Hyderabad Scalability Meetup
 
AWS Big Data Demystified #1: Big data architecture lessons learned
Omid Vahdaty
 
New Developments in Spark
Databricks
 
DatEngConf SF16 - Apache Kudu: Fast Analytics on Fast Data
Hakka Labs
 
Using Databricks as an Analysis Platform
Databricks
 
A Comparative Performance Evaluation of Apache Flink
Dongwon Kim
 
Dongwon Kim – A Comparative Performance Evaluation of Flink
Flink Forward
 
It's Time To Stop Using Lambda Architecture | Yaroslav Tkachenko, Shopify
HostedbyConfluent
 
Migrating ETL Workflow to Apache Spark at Scale in Pinterest
Databricks
 
Ad

More from Databricks (20)

PPTX
DW Migration Webinar-March 2022.pptx
Databricks
 
PPTX
Data Lakehouse Symposium | Day 1 | Part 1
Databricks
 
PPT
Data Lakehouse Symposium | Day 1 | Part 2
Databricks
 
PPTX
Data Lakehouse Symposium | Day 2
Databricks
 
PPTX
Data Lakehouse Symposium | Day 4
Databricks
 
PDF
5 Critical Steps to Clean Your Data Swamp When Migrating Off of Hadoop
Databricks
 
PDF
Learn to Use Databricks for Data Science
Databricks
 
PDF
Why APM Is Not the Same As ML Monitoring
Databricks
 
PDF
The Function, the Context, and the Data—Enabling ML Ops at Stitch Fix
Databricks
 
PDF
Stage Level Scheduling Improving Big Data and AI Integration
Databricks
 
PDF
Simplify Data Conversion from Spark to TensorFlow and PyTorch
Databricks
 
PDF
Scaling and Unifying SciKit Learn and Apache Spark Pipelines
Databricks
 
PDF
Sawtooth Windows for Feature Aggregations
Databricks
 
PDF
Redis + Apache Spark = Swiss Army Knife Meets Kitchen Sink
Databricks
 
PDF
Re-imagine Data Monitoring with whylogs and Spark
Databricks
 
PDF
Raven: End-to-end Optimization of ML Prediction Queries
Databricks
 
PDF
Processing Large Datasets for ADAS Applications using Apache Spark
Databricks
 
PDF
Massive Data Processing in Adobe Using Delta Lake
Databricks
 
PDF
Machine Learning CI/CD for Email Attack Detection
Databricks
 
PDF
Jeeves Grows Up: An AI Chatbot for Performance and Quality
Databricks
 
DW Migration Webinar-March 2022.pptx
Databricks
 
Data Lakehouse Symposium | Day 1 | Part 1
Databricks
 
Data Lakehouse Symposium | Day 1 | Part 2
Databricks
 
Data Lakehouse Symposium | Day 2
Databricks
 
Data Lakehouse Symposium | Day 4
Databricks
 
5 Critical Steps to Clean Your Data Swamp When Migrating Off of Hadoop
Databricks
 
Learn to Use Databricks for Data Science
Databricks
 
Why APM Is Not the Same As ML Monitoring
Databricks
 
The Function, the Context, and the Data—Enabling ML Ops at Stitch Fix
Databricks
 
Stage Level Scheduling Improving Big Data and AI Integration
Databricks
 
Simplify Data Conversion from Spark to TensorFlow and PyTorch
Databricks
 
Scaling and Unifying SciKit Learn and Apache Spark Pipelines
Databricks
 
Sawtooth Windows for Feature Aggregations
Databricks
 
Redis + Apache Spark = Swiss Army Knife Meets Kitchen Sink
Databricks
 
Re-imagine Data Monitoring with whylogs and Spark
Databricks
 
Raven: End-to-end Optimization of ML Prediction Queries
Databricks
 
Processing Large Datasets for ADAS Applications using Apache Spark
Databricks
 
Massive Data Processing in Adobe Using Delta Lake
Databricks
 
Machine Learning CI/CD for Email Attack Detection
Databricks
 
Jeeves Grows Up: An AI Chatbot for Performance and Quality
Databricks
 
Ad

Recently uploaded (20)

PDF
Data Chunking Strategies for RAG in 2025.pdf
Tamanna
 
PDF
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 
PDF
apidays Helsinki & North 2025 - How (not) to run a Graphql Stewardship Group,...
apidays
 
PPTX
b6057ea5-8e8c-4415-90c0-ed8e9666ffcd.pptx
Anees487379
 
PPTX
apidays Helsinki & North 2025 - Vero APIs - Experiences of API development in...
apidays
 
PPTX
Aict presentation on dpplppp sjdhfh.pptx
vabaso5932
 
PDF
apidays Helsinki & North 2025 - API-Powered Journeys: Mobility in an API-Driv...
apidays
 
PDF
OOPs with Java_unit2.pdf. sarthak bookkk
Sarthak964187
 
PPTX
Module-5-Measures-of-Central-Tendency-Grouped-Data-1.pptx
lacsonjhoma0407
 
PPTX
Advanced_NLP_with_Transformers_PPT_final 50.pptx
Shiwani Gupta
 
PPTX
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
PPTX
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
PDF
Building Production-Ready AI Agents with LangGraph.pdf
Tamanna
 
PPTX
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
PPTX
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
PDF
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
PPTX
AI Presentation Tool Pitch Deck Presentation.pptx
ShyamPanthavoor1
 
PPTX
Listify-Intelligent-Voice-to-Catalog-Agent.pptx
nareshkottees
 
PPTX
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
Data Chunking Strategies for RAG in 2025.pdf
Tamanna
 
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 
apidays Helsinki & North 2025 - How (not) to run a Graphql Stewardship Group,...
apidays
 
b6057ea5-8e8c-4415-90c0-ed8e9666ffcd.pptx
Anees487379
 
apidays Helsinki & North 2025 - Vero APIs - Experiences of API development in...
apidays
 
Aict presentation on dpplppp sjdhfh.pptx
vabaso5932
 
apidays Helsinki & North 2025 - API-Powered Journeys: Mobility in an API-Driv...
apidays
 
OOPs with Java_unit2.pdf. sarthak bookkk
Sarthak964187
 
Module-5-Measures-of-Central-Tendency-Grouped-Data-1.pptx
lacsonjhoma0407
 
Advanced_NLP_with_Transformers_PPT_final 50.pptx
Shiwani Gupta
 
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
Building Production-Ready AI Agents with LangGraph.pdf
Tamanna
 
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
AI Presentation Tool Pitch Deck Presentation.pptx
ShyamPanthavoor1
 
Listify-Intelligent-Voice-to-Catalog-Agent.pptx
nareshkottees
 
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 

From HDFS to S3: Migrate Pinterest Apache Spark Clusters

  • 2. From HDFS to S3: Migrate Pinterest Apache Spark Clusters Xin Yao, Daniel Dai Pinterest
  • 3. About us Xin Yao [email protected] ▪ Tech Lead at Pinterest (Ads Team) ▪ Previously on Data Warehouse team at Facebook and Hulu Daniel Dai [email protected] ▪ Tech Lead at Pinterest (Data Team) ▪ PMC member for Apache Hive and Pig ▪ Previously work at Cloudera/Hortonworks and Yahoo
  • 4. Agenda ▪ NextGen Big Data Platform ▪ Performance ▪ S3 Consistency ▪ Storage Difference ▪ Scheduling ▪ Spark at Pinterest
  • 5. Agenda ▪ NextGen Big Data Platform ▪ Performance ▪ S3 Consistency ▪ Storage Difference ▪ Scheduling ▪ Spark at Pinterest
  • 6. Big Data Platform Spark Hive Mesos/Aurora HDFS Kafka Presto ▪ Use Cases ▪ Ads ▪ Machine Learning ▪ Recommendations ▪ ...
  • 7. Old vs New cluster Spark Hive Mesos/Aurora HDFS Kafka Old Cluster New Cluster Presto Spark Hive YARN S3 Kafka Presto
  • 8. Agenda ▪ NextGen Big Data Platform ▪ Performance ▪ S3 Consistency ▪ Storage Difference ▪ Scheduling ▪ Spark at Pinterest
  • 10. Low local disk IOPS Slow Shuffle Slow Job Slow Workflow Old Cluster: Performance Bottleneck
  • 11. Why Local Disk IO is important for Spark ▪ Spark mappers write shuffle data to local disk ▪ Spark mappers read local disk to serve shuffle data for reducer ▪ Spark spills data to local disk when data is bigger than memory
  • 12. A Simple Aggregation Query SELECT id, max(value) FROM table GROUP BY id
  • 13. 9k Mappers * 9k Reducers map map map ... reducer reducer reducer ... 9K Mappers Network 9k ReducersMapper Local Disk Mappers Reducers
  • 14. 9k * 9k | One Mapper Machine map map reducer reducer reducer Local Disk 270k IO Ops Too many for our machine ... 30 Mappers ... One Mapper Machine | 30 Mappers Mapper machine ... ...
  • 15. How to optimize jobs in old Cluster
  • 16. Optimization. Reduce # of Mapper/Reducer map map map ... reducer reducer reducer ... 3K Mappers Network 3k Reducersmapper local disk input input input input input input input input input More files per Mapper NetworkMappers Reducers
  • 17. Optimization map map map ... reducer reducer reducer input input input input input input input input input mapper local disk 30k Ops 9X better One Mapper Machine | 10 Mappers ... 10 Mappers ... Mapper machine ... input input input ...
  • 20. New Cluster: Choose the right EC2 instance Old Cluster New Cluster EC2 Node Local Disk IOPS Cap 3k 40k EC2 Node Type r4.16xlarge r5d.12xlarge EC2 Node CPU 64 vcores 48 vcores EC2 Node Mem 480 GB 372 GB
  • 21. Production Result § After migration, prod jobs have 25% improvement on avg, without any extra resources and tuning § One typical heavy job even got 35% improvement from 90 minutes to 57 minutes Old Cluster New Cluster
  • 22. Key Takeaways ▪ Measure before Optimize ▪ Premature optimization is the root of all evil
  • 23. Key Takeaways ▪ Optimization could happen at different levels ▪ Cluster level ▪ New EC2 instance type ▪ Spark level ▪ Mapper number/cpu/mem tuning ▪ Job level ▪ Simplify logic
  • 24. Agenda ▪ NextGen Big Data Platform ▪ Performance ▪ S3 Consistency ▪ Storage Difference ▪ Scheduling ▪ Spark at Pinterest
  • 25. S3 != HDFS ▪ HDFS is a filesystem that is strong consistent. Changes are immediately visible ▪ S3 is an object storage service that is eventually consistent. There is no guarantee a change is immediately visible to the client. This might cause missing file issue without reader even know it.
  • 26. Read after write consistency
  • 27. Spark Job read less files from S3
  • 28. How often does this happen ▪ Numbers from AWS: less than 1 in 10 million ▪ Numbers from our test: less than 1 in 50 million
  • 29. Solution. Considerations ▪ Write Consistency ▪ Whether the job could write the output consistently, without partial or corrupted data as long as the job succeed. Even when some of the tasks failed or retried. ▪ Read Consistency ▪ Whether the job could read files in a folder, no more or less than it supposed to read. ▪ Monitor Consistency ▪ Requires Reader or Writer side change ▪ Query Performance
  • 30. Solution. Considerations ▪ Storage ▪ Isolation ▪ Transaction ▪ Supports Spark ▪ Supports Hive/Presto ▪ Project Origin ▪ Adoption Effort
  • 31. Solutions sorted by the complexity, simple => complex Raw S3 Data Quality Read Monitor Write Waiting Write Listing S3Committe r Consistent Listing S3Guard Iceberg Delta Lake Monitor Consistency No Partial Partial No No No N/A N/A N/A Write Consistency No No No No No Yes Yes Yes Yes Read Consistency No No Partial Partial Partial No Yes Yes Yes Reader/Writer change No No No Writer Writer Writer R/W R/W R/W Query Performance Normal Normal Normal Normal Normal Normal Normal Good Good Storage Normal Normal Normal Normal Normal Normal Normal Good Good Isolation No No No No No No No Strong Snapshot Strong Snapshot Transaction No No No No No No No Table Table Supports Spark Yes Yes Yes Yes Yes Yes Yes Yes Yes Supports Hive/Presto Yes Yes Yes Yes* Yes* Yes Yes WIP WIP Project Origin In House In House Not Exist Not Exist Not Exist Netflix OSS Hadoop 3.0 Apache Incubator Databricks OSS Effort None M M M M L XL XL
  • 32. Our Approach ▪ Short Term ▪ S3 Committer ▪ Number of file monitor ▪ Data quality tool ▪ Long Term ▪ Systematical solutions
  • 33. Agenda ▪ NextGen Big Data Platform ▪ Performance ▪ S3 Consistency ▪ Storage Difference ▪ Scheduling ▪ Spark at Pinterest
  • 34. Performance Comparison: S3 vs HDFS ▪ Similar throughput ▪ Metadata operation is slow, especially move operation ▪ Our Spark streaming job is heavily impacted ▪ Spending most time moving output files around (3 times) 13s 55s Microbatch Runtime
  • 35. Dealing with Metadata Operation ▪ Move file at least twice in a Spark Application ▪ commitTask ▪ commitJob ▪ May also move to the Hive table location output/_temporary/taskId/_temporary/taskAttemptID/part-xxxxxx output/_temporary/taskId/part-xxxxxx output/part-xxxxxx /warehouse/pinterest.db/table/date=20200626 commitTask commitJob Hive MoveTask df.write.mode(SaveMode.Append).insertInto(partitionedTable)
  • 36. Reduce Move Operations ▪ FileOutputCommitter algorithm 2 ▪ spark.hadoop.mapreduce.fileoutputcommitter.algorithm.version=2 ▪ Skip move operation in job level, only task level ▪ DirectOutputCommitter ▪ Further skip move operation at task level ▪ Problem: File corruption when job fail ▪ Netflix s3committer ▪ spark.sql.sources.outputCommitterClass=com.netflix.bdp.s3.S3PartitionedOutputCommitter ▪ Use multi-part upload api, no move operation ▪ Other solutions ▪ Iceberg ▪ Hadoop s3acommitter
  • 37. Multipart Upload API ▪ For every file ▪ initiateMultipartUpload ▪ Multiple uploadPart ▪ Finally completeMultipartUpload/abortMultipartUpload ▪ AWS will save all parts until completeMultipartUpload/abortMultipartUpload ▪ Setup a lifecycle policy ▪ Separate s3 permission for abortMultipartUpload
  • 38. S3committer ▪ Upload File to Output Directly use multi-part upload api ▪ Atomic completeMultipartUpload leaves no corrupt output ▪ Parallel upload parts of a file to increase throughput uploadPart completeMultipartUpload commitTask commitJob
  • 39. The Last Move Operation ▪ Before: Use staging directory to figure out the new partitions ▪ After: A table level tracking file for the new partitions ds=20200101 ds=20200102 ds=20200103 ds=20200104 ds=20200105 ds=20200106 ds=20200107 ds=20200108 ds=20200109 ds=20200110 ds=20200111 Table ds=20200112 Staging Directory .s3_dyn_parts ds=20200101 ds=20200102 ds=20200103 ds=20200104 ds=20200105 ds=20200106 ds=20200107 ds=20200108 ds=20200109 ds=20200110 ds=20200111 ds=20200112 Table ds=20200112
  • 41. Fix Bucket Rate Limit Issue (503) ▪ S3 bucket partition ▪ Task and Job level retry ▪ Tune the parallelism in part file uploads
  • 42. Improving S3Committer ▪ Fix Bucket Rate Limit (503) ▪ Parallel upload parts of a file to increase throughput ▪ Integrity check of S3 multipart upload ETags ▪ Fix thread pool leaking for long-running application ▪ Remove local output early
  • 43. S3 Benefit Compare to HDFS ▪ Reduce 80% storage cost ▪ S3: 99.99% availability, 99.999999999% durability ▪ HDFS: 99.9% target availability ▪ Namenode single point failure ▪ Potential data lost
  • 44. Agenda ▪ NextGen Big Data Platform ▪ Performance ▪ S3 Consistency ▪ Storage Difference ▪ Scheduling ▪ Spark at Pinterest
  • 45. Things We Miss in Mesos ▪ Manage services inside Mesos ▪ Simple workflow, long running job and cron job via Aurora ▪ Rolling restart ▪ Built-in health check
  • 46. Things We Like in Yarn ▪ Global view of all running applications ▪ Better queue management for organization isolation ▪ Consolidate with the rest of clusters
  • 47. Cost Saving ▪ We achieve cost savings with YARN ▪ Queue isolation ▪ Preemption
  • 48. Agenda ▪ NextGen Big Data Platform ▪ Performance ▪ S3 Consistency ▪ Storage Difference ▪ Scheduling ▪ Spark at Pinterest
  • 49. Spark at Pinterest ▪ We are still in the early stages ▪ Spark represents 12% of all compute resource usage ▪ Batch use case ▪ Mostly Scala, also PySpark
  • 50. We Are Working On ▪ Automatic migration from Hive -> Spark SQL ▪ Cascading/Scalding -> Spark ▪ Adopting Dr Elephant for Spark ▪ Used for code review ▪ Integrate with internal metrics system ▪ Include features from Sparklens ▪ Spark history server performance
  • 52. Feedback Your feedback is important to us. Don’t forget to rate and review the sessions.