Data Science

How do I handle data skew in Apache Spark 3.x to prevent 'Executor Lost' errors during large joins?

RO Asked by Robert Miller · 12-04-2024
0 upvotes 16,274 views 0 comments
The question

We are running a massive ETL job joining a billion-row fact table with a skewed dimension table. One executor always hangs at 99% while the others idle, eventually leading to a heartbeat timeout and failure. What are the best strategies to handle this? Should I look into salting keys or is Adaptive Query Execution (AQE) enough to automate the skew join optimization? 

3 answers

0
JE
Answered on 15-04-2024

Data skew is a classic bottleneck where a few partitions are significantly larger than others. In Spark 3.0+, your first step should be enabling Adaptive Query Execution (AQE) by setting spark.sql.adaptive.enabled to true. AQE can automatically detect skewed joins and split those large partitions into smaller sub-partitions. However, if the skew is extreme, manual "salting" is more reliable. This involves adding a random suffix to the join key in the skewed table and replicating the corresponding keys in the smaller table. This forces Spark to redistribute the heavy keys across multiple executors, balancing the processing load and preventing the dreaded heartbeat timeouts. 

0
MI
Answered on 17-04-2024

Jennifer’s suggestion on salting is the industry standard for extreme skew. However, have you monitored the Spark UI to see the specific shuffle read/write metrics? Sometimes the issue isn't just the join, but an inefficient groupBy upstream that creates the skew before the join even starts. Are you using any Broadcast hints?

DA 18-04-2024

Michael, I checked the Spark UI and you were right. The skew was originating from a groupBy on a 'null' heavy column. I filtered out the nulls before the transformation, and the shuffle size dropped by 40%. It's a simple fix that BAs and Data Engineers often overlook when focusing solely on join optimization, but it saved us hours of compute time.

0
D
Answered on 18-04-2024

Michael, I checked the Spark UI and you were right. The skew was originating from a groupBy on a 'null' heavy column. I filtered out the nulls before the transformation, and the shuffle size dropped by 40%. It's a simple fix that BAs and Data Engineers often overlook when focusing solely on join optimization, but it saved us hours of compute time. 

DA 18-04-2024

Michael, I checked the Spark UI and you were right. The skew was originating from a groupBy on a 'null' heavy column. I filtered out the nulls before the transformation, and the shuffle size dropped by 40%. It's a simple fix that BAs and Data Engineers often overlook when focusing solely on join optimization, but it saved us hours of compute time.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session