SP

spark-optimization

Provides optimization techniques for Apache Spark jobs including memory tuning and shuffle management.

Install

mkdir -p .claude/skills/spark-optimization && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1497" && unzip -o skill.zip -d .claude/skills/spark-optimization && rm skill.zip

Installs to .claude/skills/spark-optimization

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Optimize Apache Spark jobs with partitioning, caching, shuffle optimization, and memory tuning. Use when improving Spark performance, debugging slow jobs, or scaling data processing pipelines.
192 chars✓ has a “when” trigger
Advanced

Key capabilities

  • Configure Spark session for adaptive execution
  • Implement partitioning strategies
  • Optimize shuffle operations
  • Tune executor memory
  • Monitor Spark UI for performance bottlenecks

How it works

It applies performance tuning patterns such as enabling Adaptive Query Execution (AQE), using Kryo serialization, and right-sizing partitions. It provides guidance on avoiding common anti-patterns like unnecessary collection or data skew.

Inputs & outputs

You give it
Spark job configuration and code
You get back
Optimized Spark job configuration and code

When to use spark-optimization

  • Optimizing slow Spark jobs
  • Scaling data pipelines
  • Debugging Spark memory issues
  • Tuning Spark partitions

About this skill

Apache Spark Optimization

Production patterns for optimizing Apache Spark jobs including partitioning strategies, memory management, shuffle optimization, and performance tuning.

When to Use This Skill

  • Optimizing slow Spark jobs
  • Tuning memory and executor configuration
  • Implementing efficient partitioning strategies
  • Debugging Spark performance issues
  • Scaling Spark pipelines for large datasets
  • Reducing shuffle and data skew

Core Concepts

1. Spark Execution Model

Driver Program
    ↓
Job (triggered by action)
    ↓
Stages (separated by shuffles)
    ↓
Tasks (one per partition)

2. Key Performance Factors

FactorImpactSolution
ShuffleNetwork I/O, disk I/OMinimize wide transformations
Data SkewUneven task durationSalting, broadcast joins
SerializationCPU overheadUse Kryo, columnar formats
MemoryGC pressure, spillsTune executor memory
PartitionsParallelismRight-size partitions

Quick Start

from pyspark.sql import SparkSession
from pyspark.sql import functions as F

# Create optimized Spark session
spark = (SparkSession.builder
    .appName("OptimizedJob")
    .config("spark.sql.adaptive.enabled", "true")
    .config("spark.sql.adaptive.coalescePartitions.enabled", "true")
    .config("spark.sql.adaptive.skewJoin.enabled", "true")
    .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
    .config("spark.sql.shuffle.partitions", "200")
    .getOrCreate())

# Read with optimized settings
df = (spark.read
    .format("parquet")
    .option("mergeSchema", "false")
    .load("s3://bucket/data/"))

# Efficient transformations
result = (df
    .filter(F.col("date") >= "2024-01-01")
    .select("id", "amount", "category")
    .groupBy("category")
    .agg(F.sum("amount").alias("total")))

result.write.mode("overwrite").parquet("s3://bucket/output/")

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices

Do's

  • Enable AQE - Adaptive query execution handles many issues
  • Use Parquet/Delta - Columnar formats with compression
  • Broadcast small tables - Avoid shuffle for small joins
  • Monitor Spark UI - Check for skew, spills, GC
  • Right-size partitions - 128MB - 256MB per partition

Don'ts

  • Don't collect large data - Keep data distributed
  • Don't use UDFs unnecessarily - Use built-in functions
  • Don't over-cache - Memory is limited
  • Don't ignore data skew - It dominates job time
  • Don't use .count() for existence - Use .take(1) or .isEmpty()

When not to use it

  • For small datasets where overhead exceeds benefits
  • When the job is already performing optimally

Prerequisites

Apache Spark environmentAccess to Spark UI

Limitations

  • Requires access to Spark UI for debugging
  • Memory tuning depends on cluster resources

How it compares

It provides specific configuration tuning and architectural patterns for Spark rather than general code optimization.

Compared to similar skills

spark-optimization side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
spark-optimization (this skill)42moNo flagsAdvanced
dataeng-codebase-analyst03moNo flagsIntermediate
feast-user-guide01moReviewIntermediate
django-insights04moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

More by wshobson

View all by wshobson

Search skills

Search the agent skills registry