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.zipInstalls 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.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
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
| 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
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
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.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| spark-optimization (this skill) | 4 | 2mo | No flags | Advanced |
| dataeng-codebase-analyst | 0 | 3mo | No flags | Intermediate |
| feast-user-guide | 0 | 1mo | Review | Intermediate |
| django-insights | 0 | 4mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by wshobson
View all by wshobson →You might also like
dataeng-codebase-analyst
juankmvanegas
Analyze existing Data Engineering codebase — data pipeline, reproducibility, artifacts, and operational flow
feast-user-guide
feast-dev
Guide for working with Feast (Feature Store) — defining features, configuring feature_store.yaml, retrieving features online/offline, using the CLI, and building RAG retrieval pipelines. Use when the user asks about creating entities, feature views, on-demand feature views, stream feature views, fea
django-insights
carlosapgomes
Diagnóstico de saúde para projetos Django: performance, segurança e arquitetura.
spark-optimization
bika11
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.
gcp-spark
ironkid90
|
senior-data-engineer
davila7
World-class data engineering skill for building scalable data pipelines, ETL/ELT systems, and data infrastructure. Expertise in Python, SQL, Spark, Airflow, dbt, Kafka, and modern data stack. Includes data modeling, pipeline orchestration, data quality, and DataOps. Use when designing data architectures, building data pipelines, optimizing data workflows, or implementing data governance.