spark-optimization — Claude Code skill: Spark tuning
This skill helps diagnose slow Apache Spark jobs and tune partitioning, caching, shuffle, and memory. Use it when scaling data-processing pipelines.
/plugin marketplace add wshobson/agents
/plugin install data-engineering@claude-code-workflowsWhat spark-optimization does
spark-optimization focuses on the causes of slow Apache Spark jobs: excess shuffle, data skew, poor partition sizing, memory pressure, and unnecessary UDFs. It covers AQE, broadcast joins, built-in functions, and columnar formats such as Parquet and Delta.
The package includes a Spark execution model, a PySpark SparkSession setup example, and guidance for checking Spark UI. More worked patterns are stored in references/details.md. Install it when you maintain or troubleshoot Spark pipelines; it adds little value to projects that do not use Apache Spark.
What it helps with
- trace the cause of a slow Spark job
- choose a better partitioning strategy
- reduce shuffle and data skew
- tune executor and memory settings
- replace unnecessary UDFs with built-in functions
Example prompts for the agent
- Inspect this Apache Spark job and identify the sources of excess shuffle.
- Review this PySpark pipeline for caching, broadcast joins, and partition sizing.
- Set up a SparkSession for Parquet input and an aggregate without collecting a large dataset.
How to install spark-optimization
1Plugin marketplace
/plugin marketplace add wshobson/agents/plugin install data-engineering@claude-code-workflowsThis installs the whole data-engineering plugin with all its skills
2Skills CLI (Vercel)
npx skills add wshobson/agents --skill spark-optimization -a claude-code3Manually: put the files in place
~/.claude/skills/spark-optimization/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/spark-optimization/
1Skills CLI (Vercel)
npx skills add wshobson/agents --skill spark-optimization -a codex2Manually: put the files in place
.agents/skills/spark-optimization/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add wshobson/agents --skill spark-optimization -a cursor2Manually: put the files in place
.cursor/skills/spark-optimization/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install wshobson/agents spark-optimization2Manually: put the files in place
.github/skills/spark-optimization/SKILL.mdPlatform CLI
gemini skills install https://github.com/wshobson/agents --path plugins/data-engineering/skills/spark-optimizationManually: put the files in place
.devin/skills/spark-optimization/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
From the same set213
The whole set →Similar
Questions about spark-optimization
How do I install spark-optimization in Claude Code?
Run npx skills add wshobson/agents --skill spark-optimization -a claude-code. The skill file is placed at ~/.claude/skills/spark-optimization/SKILL.md.
What does spark-optimization do?
It helps tune Apache Spark jobs by addressing shuffle, skew, partition sizing, memory, caching, joins, and serialization choices.
Which Spark tools and formats does it cover?
The material covers PySpark, Spark UI, AQE, Parquet, Delta, and KryoSerializer. It also discusses caching and adaptive partition coalescing.
Source text
SKILL.md · MIT
---
name: spark-optimization
description: 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.
---
# 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
| Factor | Impact | Solution |
| ----------------- | --------------------- | ----------------------------- |
| **Shuffle** | Network I/O, disk I/O | Minimize wide transformations |
| **Data Skew** | Uneven task duration | Salting, broadcast joins |
| **Serialization** | CPU overhead | Use Kryo, columnar formats |
| **Memory** | GC pressure, spills | Tune executor memory |
| **Partitions** | Parallelism | Right-size partitions |
## Quick Start
```python
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()`
© Seth Hobson · MIT · wshobson/agents