LAB 02 · SPARK
One partition is enormous.
The cluster is not the first thing to change.
A daily customer aggregate loses an executor with java.lang.OutOfMemoryError: Java heap space.
The same code completes on most days. Adding one executor did not move the failing task.
Use the stage shape to decide whether this is broad memory pressure or one uneven key.
JOB EXCERPT
Relevant transformation only
events = spark.read.parquet("s3://analytics/events")
daily_customer_metrics = (
events
.filter(F.col("event_date") == run_date)
.groupBy("customer_id")
.agg(
F.count("*").alias("events"),
F.sum("amount").alias("revenue"),
)
)
The aggregate causes a shuffle: matching customer_id values must meet in the same partition.
EVIDENCE TRAIL
Open the signals in order
01Failed stageDid every task run out of memory?
Stage 41 · 200 tasks
Median shuffle read: 118 MB
Task 184 shuffle read: 7.6 GB
Task 184: ExecutorLostFailure (java.lang.OutOfMemoryError)
199 tasks completed successfullyThis is not an even cluster-wide shortage. One reduce task received far more data than the rest.
02Key sampleWhat filled the oversized partition?
customer_id rows in the run
unknown 18,402,119
cust_8421 22,104
cust_1109 21,889
other values < 20,000 eachThe fallback value unknown is acting as one customer. All of those rows hash to one shuffle partition.
03Run comparisonWhat changed on the failing date?
The normalisation job that populates customer_id was late. The upstream source therefore emitted the fallback value for 61% of this run.
Reference: Apache Spark SQL performance tuning.
LIKELY ROOT CAUSEA fallback customer key created one hot shuffle partition; executor memory is the symptom, not the first cause.
The job concentrates millions of unrelated events under a single key. More executor memory can delay the same failure, but it does not make that partition balanced.
.groupBy("customer_id").filter((F.col("customer_id").isNotNull()) & (F.col("customer_id") != "unknown"))REVIEW BEFORE APPLYINGDo not silently drop a valid business bucket. Quarantine these rows or give them a deliberate reporting path, then repair the late enrichment that created them.