Intermediate
Open
Pro
A Job That Ran Fine Across the Cluster Crashes on the Last Line
Your pipeline processes 800GB of data spread across a 20-executor
cluster. The Spark UI shows every stage completing successfully —
filters, joins, a large groupBy aggregation all finish within their
expected time. Then the job crashes with:
java.lang.OutOfMemoryError: Java heap space
The stack trace points to this final line:
final_df = aggregated.orderBy(F.desc("total_revenue"))
results = final_df.collect() # <-- crash happens here
for row in results:
send_to_dashboard_api(row)
- Explain why a job that successfully processed 800GB across 20 executors can crash on this specific line, and why the crash is attributed to "Java heap space" rather than an executor running out of resources.
aggregatedwas the output of agroupBythat reduced 800GB down to some number of rows. Does the row count ofaggregatedmatter to this diagnosis? Why or why not, precisely?- Propose two different fixes appropriate for two different
underlying scenarios: one where
aggregatedgenuinely has far too many rows to reasonably act on one at a time in a Python loop, and one where it doesn't.
Share this question