Spark Optimization skill for Claude

Optimize Apache Spark jobs with partitioning, caching, shuffle optimization, and memory tuning.

When Claude uses it

Use when improving Spark performance, debugging slow jobs, or scaling data processing pipelines.

Spark Optimization SKILL.md

The full skill file from wshobson/agents (MIT).

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()

How to install Spark Optimization

Claude Code

Copy the skill into your personal skills folder (or into .claude/skills/ inside a project):

npx degit wshobson/agents/plugins/data-engineering/skills/spark-optimization#main ~/.claude/skills/spark-optimization

Codex

npx degit wshobson/agents/plugins/data-engineering/skills/spark-optimization#main ~/.codex/skills/spark-optimization

Claude.ai and Claude Desktop

Download the skill folder from GitHub, zip it, and upload it under Settings → Capabilities → Skills.

Frequently asked questions

+What does the Spark Optimization skill do?

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.

+How do I install Spark Optimization in Claude Code?

Copy the skill folder into ~/.claude/skills/spark-optimization, for example with "npx degit wshobson/agents/plugins/data-engineering/skills/spark-optimization#main ~/.claude/skills/spark-optimization". Claude Code loads it automatically and uses it when a task matches.

+Does Spark Optimization work with ChatGPT or Codex?

Yes. Spark Optimization uses the open SKILL.md format. In Codex, put the folder in ~/.codex/skills/spark-optimization. In Claude.ai, zip the folder and upload it under Settings → Capabilities → Skills.

+Is Spark Optimization free?

Spark Optimization is published on GitHub by wshobson under the MIT license, which allows free use.

Related software development skills

  1. Code Review

    Review the changes since a fixed point (commit, branch, tag, or merge-base) along two axes: Standards (does the code follow this repo's…

    mattpocock/skills★ 327k
  2. Using Agent Skills

    Discovers and invokes agent skills. Use when starting a session, or when you need to decide which skill or workflow applies to the piece of…

    addyosmani/agent-skills★ 119k
  3. Build

    Fully automate a coding task with make-plan, do, and babysit.

    thedotmack/claude-mem★ 118k
  4. Team Communication Protocols

    Structured messaging protocols for agent team communication including message type selection, plan approval, shutdown procedures, and…

    wshobson/agents★ 43k
  5. Turborepo Caching

    Configure Turborepo for efficient monorepo builds with local and remote caching.

    wshobson/agents★ 43k
  6. Typescript Advanced Types

    Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for…

    wshobson/agents★ 43k
  7. Uv Package Manager

    Master the uv package manager for fast Python dependency management, virtual environments, and modern Python project workflows.

    wshobson/agents★ 43k
  8. Workflow Patterns

    Use this skill when implementing tasks according to Conductor's TDD workflow, handling phase checkpoints, managing git commits for tasks,…

    wshobson/agents★ 43k
  9. Agenthub

    Run several agents on one task in parallel and keep the best result: faster code, copy variants, research angles.

    alirezarezvani/claude-skills★ 30k

See all software development skills →

More skills from wshobson

  1. Spark Training Gotchas

    Preflight and diagnose the ten known failure modes for ML training on NVIDIA DGX Spark.

    wshobson/agents★ 43k
  2. Sql Optimization Patterns

    Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow…

    wshobson/agents★ 43k
  3. Startup Financial Modeling

    Build comprehensive 3-5 year financial models with revenue projections, cost structures, cash flow analysis, and scenario planning for…

    wshobson/agents★ 43k

All skills by wshobson →

Give your whole team an AI agent with skills

Cody runs managed AI agents your team can message in Slack, Teams, WhatsApp and the web, with 50+ business integrations, scheduled tasks and memory. No terminal required.