Skill files2 files

references/

SKILL.md96 lines
1
---
2
name: spark-optimization
3
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.
4
---
5
6
# Apache Spark Optimization
7
8
Production 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
```
24
Driver Program
25
↓
26
Job (triggered by action)
27
↓
28
Stages (separated by shuffles)
29
↓
30
Tasks (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
46
from pyspark.sql import SparkSession
47
from pyspark.sql import functions as F
48
49
# Create optimized Spark session
50
spark = (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
60
df = (spark.read
61
.format("parquet")
62
.option("mergeSchema", "false")
63
.load("s3://bucket/data/"))
64
65
# Efficient transformations
66
result = (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
72
result.write.mode("overwrite").parquet("s3://bucket/output/")
73
```
74
75
## Detailed patterns and worked examples
76
77
Detailed 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

© Seth Hobson · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…