Optimize Apache Spark jobs with partitioning, caching

Apache Spark Optimization

by wshobson · MIT license · ★ 39,857 on GitHub · updated Sep 21

Apache Spark Optimization cover

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.

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

Overview

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

Manual install (npx, ZIP)
Claude Codenpx skills add wshobson/agents --skill spark-optimization -g -a claude-code
Claude Code (manual)mkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/wshobson/agents/tar.gz/4236bb91f839 \ | tar -xz -C ~/.claude/skills --strip-components=4 agents-4236bb91f839/plugins/data-engineering/skills/spark-optimization
Windows (PowerShell)New-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/0ade870cf31857798392/spark-optimization.zip" -OutFile "$env:TEMP\spark-optimization.zip"; Expand-Archive "$env:TEMP\spark-optimization.zip" -DestinationPath "$HOME\.claude\skills" -Force
Claude.ai / desktopDownload the ZIP and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md3.1 KB
  • references/1 file · 9.6 KB
Read the files here
wshobson/4236bb92 files
SKILL.md
Show the full text96 lines

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()
1---
2name: spark-optimization
3description: 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.
4---
5 
6# Apache Spark Optimization
7 
8Production patterns for optimizing Apache Spark jobs including partitioning strategies, memory management, shuffle optimization, and performance tuning.
9 
10## When to Use This Skill
11 
12- Optimizing slow Spark jobs
13- Tuning memory and executor configuration
14- Implementing efficient partitioning strategies
15- Debugging Spark performance issues
16- Scaling Spark pipelines for large datasets
17- Reducing shuffle and data skew
18 
19## Core Concepts
20 
21### 1. Spark Execution Model
22 
23```
24Driver Program
25 ↓
26Job (triggered by action)
27 ↓
28Stages (separated by shuffles)
29 ↓
30Tasks (one per partition)
31```
32 
33### 2. Key Performance Factors
34 
35| Factor | Impact | Solution |
36| ----------------- | --------------------- | ----------------------------- |
37| **Shuffle** | Network I/O, disk I/O | Minimize wide transformations |
38| **Data Skew** | Uneven task duration | Salting, broadcast joins |
39| **Serialization** | CPU overhead | Use Kryo, columnar formats |
40| **Memory** | GC pressure, spills | Tune executor memory |
41| **Partitions** | Parallelism | Right-size partitions |
42 
43## Quick Start
44 
45```python
46from pyspark.sql import SparkSession
47from pyspark.sql import functions as F
48 
49# Create optimized Spark session
50spark = (SparkSession.builder
51 .appName("OptimizedJob")
52 .config("spark.sql.adaptive.enabled", "true")
53 .config("spark.sql.adaptive.coalescePartitions.enabled", "true")
54 .config("spark.sql.adaptive.skewJoin.enabled", "true")
55 .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
56 .config("spark.sql.shuffle.partitions", "200")
57 .getOrCreate())
58 
59# Read with optimized settings
60df = (spark.read
61 .format("parquet")
62 .option("mergeSchema", "false")
63 .load("s3://bucket/data/"))
64 
65# Efficient transformations
66result = (df
67 .filter(F.col("date") >= "2024-01-01")
68 .select("id", "amount", "category")
69 .groupBy("category")
70 .agg(F.sum("amount").alias("total")))
71 
72result.write.mode("overwrite").parquet("s3://bucket/output/")
73```
74 
75## Detailed patterns and worked examples
76 
77Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
78 
79## Best Practices
80 
81### Do's
82 
83- **Enable AQE** - Adaptive query execution handles many issues
84- **Use Parquet/Delta** - Columnar formats with compression
85- **Broadcast small tables** - Avoid shuffle for small joins
86- **Monitor Spark UI** - Check for skew, spills, GC
87- **Right-size partitions** - 128MB - 256MB per partition
88 
89### Don'ts
90 
91- **Don't collect large data** - Keep data distributed
92- **Don't use UDFs unnecessarily** - Use built-in functions
93- **Don't over-cache** - Memory is limited
94- **Don't ignore data skew** - It dominates job time
95- **Don't use `.count()` for existence** - Use `.take(1)` or `.isEmpty()`
96 
View all files on GitHub →

Details

Updated
Sep 21, 2026
License
MIT
Stars on the repo
★ 39,857
Checked
Source
wshobson/agents ↗
Creator
wshobson · 179 listings
View creator

Similar skills

See all →
SkillTranslates Snowflake dbt SQL models to Standardized BigQuerydbt Snowflake to BigQuery Translatorgoogle/skills · by googleTranslates Snowflake dbt SQL models to Standardized BigQuery SQL. Handles SQL compilation, Jinja macro placeholder masking, BigQuery Translation Service migration workflows, AST-based config transformations, explicit type casting, JSON extraction standardization, and deduplication. Use when migrating Snowflake dbt pipelines or models to Google Cloud BigQuery. Don't use for generic BigQuery queries or non-Snowflake SQL migrations.★ 20.9k GitHub starsSkillAnswering business analytics, RevOps, GTM metric, pipelineDeepline analyticsgetaero-io/gtm-eng-skills · by getaero-ioUse this skill when answering business analytics, RevOps, GTM metric, pipeline, revenue, funnel, customer, or warehouse questions with Deepline. Triggers on phrases like 'query Snowflake', 'analyze pipeline', 'total ACV', 'break down by quarter', 'use the semantic layer', 'run a semantic query', or any use of snowflake_get_semantic_layer / snowflake_run_semantic_query. Skip prospecting, enrichment, contact finding, outbound, or personalization workflows; use deepline-gtm for those.★ 66 GitHub starsSkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patternswshobson/agents · by wshobsonBuild production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.★ 39.9k GitHub starsSkillImplement data quality validation with Great ExpectationsData quality frameworkswshobson/agents · by wshobsonImplement data quality validation with Great Expectations, dbt tests, and data contracts. Use when building data quality pipelines, implementing validation rules, or establishing data contracts.★ 39.9k GitHub starsSkillMaster dbt for analytics engineering with model organizationDbt transformation patternswshobson/agents · by wshobsonMaster dbt (data build tool) for analytics engineering with model organization, testing, documentation, and incremental strategies. Use when building data transformations, creating data models, or implementing analytics engineering best practices.★ 39.9k GitHub starsSkillAudit datasets for completeness, consistency, accuracyData quality auditoralirezarezvani/claude-skills · by alirezarezvaniAudit datasets for completeness, consistency, accuracy, and validity. Profile data distributions, detect anomalies and outliers, surface structural issues, and produce an actionable remediation plan. Use when the user asks to check data quality, profile a dataset, hunt outliers or missing values, or validate data before analysis or model training.★ 26.3k GitHub stars

More from wshobson

SkillMaster C/.NET backend development patterns for buildingwshobson/agents · by wshobsonMaster C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuration, caching, and testing with xUnit. Use when developing .NET backends, reviewing C# code, or designing API architectures.★ 39.9k GitHub starsSkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliancewshobson/agents · by wshobsonImplement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.★ 39.9k GitHub starsSkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Designwshobson/agents · by wshobsonMaster Material Design 3 and Jetpack Compose patterns for building native Android apps. Use when designing Android interfaces, implementing Compose UI, or following Google's Material Design guidelines.★ 39.9k GitHub starsSkillMigrate from AngularJS to Angular using hybrid modeAngular migrationwshobson/agents · by wshobsonMigrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.★ 39.9k GitHub starsSkillUnderstand anti-reversing, obfuscationAnti reversing techniqueswshobson/agents · by wshobsonUnderstand anti-reversing, obfuscation, and protection techniques encountered during software analysis. Use this skill when analyzing malware evasion techniques, when implementing anti-debugging protections for CTF challenges, when reverse engineering packed binaries, or when building security research tools that need to detect virtualized environments.★ 39.9k GitHub starsSkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patternswshobson/agents · by wshobsonBuild production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.★ 39.9k GitHub stars