spark-optimization

Optimizes Apache Spark jobs through partitioning, caching, shuffle tuning, and memory configuration.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill spark-optimization-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spark-optimization
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/spark-optimization
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill spark-optimization-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pyspark.

What problem does it solve? Slow Spark jobs, data skew, memory pressure, and excessive shuffles make data pipelines expensive and unreliable. This Skill provides production-tested patterns to diagnose and fix Spark performance bottlenecks. ## Core Features & Use Cases - Partitioning & Shuffle Optimization: Right-size partitions, use coalesce vs repartition correctly, and enable Adaptive Query Execution (AQE) for automatic skew handling. - Join & Caching Strategies: Apply broadcast joins, bucketed joins, salting for skewed keys, and proper storage levels for cached DataFrames. - Memory Tuning & Monitoring: Configure executor memory, detect partition skew programmatically, and inspect query plans with explain modes. - Use Case: A nightly ETL job processing terabytes of Parquet data takes 6 hours due to a skewed join. Use this Skill to apply salting and AQE skew join configuration, cutting runtime dramatically. ## Quick Start Ask the AI to optimize your slow PySpark job by analyzing its partitioning, joins, and memory configuration using the spark-optimization patterns.

Frequently Asked Questions about spark-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize a slow Spark job?

Start by enabling Adaptive Query Execution (AQE), right-sizing partitions to 128-256MB each, and using Kryo serialization. Then check the Spark UI for data skew, shuffle spills, and GC pressure to target the specific bottleneck.

How to handle data skew in Spark joins?

Enable spark.sql.adaptive.skewJoin.enabled so AQE splits skewed partitions automatically. For severe skew, apply manual salting by adding a random salt key to the skewed side and exploding the other side across all salt values.

When should I use broadcast join vs sort-merge join in Spark?

Use a broadcast join when one table is small (under the autoBroadcastJoinThreshold, typically 10-50MB) to avoid shuffling the large side. Sort-merge join is the default for two large tables and handles any data size but requires a shuffle.

What is the difference between repartition and coalesce in Spark?

Repartition performs a full shuffle to create evenly distributed partitions and can increase or decrease partition count. Coalesce only reduces partitions without a shuffle, making it cheaper but potentially creating uneven partitions.

How much memory should I allocate to Spark executors?

A common starting point is 8GB executor memory with 2GB overhead, where spark.memory.fraction (0.6) reserves 60% for execution and storage. Monitor GC time and spills in the Spark UI and adjust based on observed pressure.

Why does my Spark job run out of memory during shuffle?

OOM during shuffle usually comes from too few shuffle partitions, oversized partitions, or skewed keys concentrating data on few executors. Increase spark.sql.shuffle.partitions, enable AQE coalescing, and check partition skew with spark_partition_id counts.