The Spark UI: Advanced
First error versus loudest error
When an executor dies, every task that depended on it fails as well, and each failure writes its own lines. A reducer fetching shuffle blocks from the dead executor logs a FetchFailedException, retries, and logs again. Across a few hundred reducers that is thousands of lines, all of which read like a network fault. The cause is usually a single line, earlier, on a different machine.
| Time | Where | Line |
|---|---|---|
| 13:42:03 | executor 7 | WARN TaskMemoryManager: Failed to allocate a page (67108864 bytes), try again. |
| 13:42:05 | executor 7 | WARN TaskMemoryManager: Failed to allocate a page (67108864 bytes), try again. |
| 13:42:09 | executor 7 | ERROR Executor: Exception in task 41.0 in stage 10.0 (TID 3302): java.lang.OutOfMemoryError: Java heap space |
| 13:42:11 | driver | ERROR TaskSchedulerImpl: Lost executor 7 on 10.0.4.21: Command exited with code 52 |
| 13:42:12 | executor 12 | ERROR RetryingBlockTransferor: Exception while beginning fetch of 38 outstanding blocks: java.io.IOException: Failed to connect to /10.0.4.21:43117 |
| 13:42:12 | driver | WARN TaskSetManager: Lost task 3.0 in stage 10.0 (TID 3390): FetchFailed(BlockManagerId(7, 10.0.4.21, 43117), shuffleId=4, mapIndex=17, reduceId=3) |
| 13:42:12 to 13:47:40 | driver and 31 executors | about 4,800 more FetchFailed and connection lines |
Read in time order, the table shows one failure and its cascade. Executor 7 twice failed to get a 64 MB page of execution memory, then threw OutOfMemoryError in task 41 and exited with code 52, which Spark uses for an executor out of heap. Everything after 13:42:09 is cascade: executor 12 was fetching map output that executor 7 had written in stage 9, found nothing listening on port 43117, and the driver recorded a fetch failure. The FetchFailed lines outnumber the heap error thousands to one, but the heap error comes first.
Classifying a death
| Class | First error | What sets it apart |
|---|---|---|
| Memory, heap | `java.lang.OutOfMemoryError: Java heap space` or `GC overhead limit exceeded`; exit code 52 | `Failed to allocate a page` warnings often come first |
| Memory, outside the heap | No Java error; stderr stops mid-line with exit code 137 (SIGKILL), or ends at `RECEIVED SIGNAL TERM` with exit code 143 when the cluster manager sends SIGTERM first | A signal from outside the JVM: the container limit, the cluster manager or the kernel |
| Serialization | `NotSerializableException`, `InvalidClassException ... local class incompatible`, or `ClassNotFoundException` while reading a task | The same task fails the same way on every attempt, and the executor stays up |
| Network | `FetchFailedException`, `Connection reset by peer` or `RpcTimeoutException`, with nothing earlier on the source executor | Failures follow a host rather than a task |
Heartbeat timeouts need extra care. Each executor reports to the driver every 10 seconds, and after 120 seconds of silence, the default spark.network.timeout, the driver logs Removing executor 5 with no recent heartbeats and drops it. That line names no cause, and a frequent one is memory: an executor trapped in back-to-back full collections stops heartbeating while its network is fine. Before filing a timeout under network, open the silent executor's stderr and read the 2 minutes before it went quiet.
Task not serializable is thrown on the driver before any task launches, so no executor log mentions it. Executor-side serialization errors repeat instead: with spark.task.maxFailures at its default of 4, identical stack traces from different executors that keep running other work rule out the machine.- Driver log: find the first line naming a lost executor, and note its ID, host and time.
- That executor's stderr: start 2 minutes before the loss and read forward.
- Stop at the first ERROR, or the first WARN that repeats. That line sets the class.
- Treat everything later, on any machine, as cascade until it proves otherwise.
A job fails at 03:10. The driver log holds 1,900 FetchFailed lines naming host 10.0.6.14, plus a single line at 03:08:55: Removing executor 22 with no recent heartbeats: 131402 ms exceeds timeout 120000 ms. Executor 22 ran on 10.0.6.14, and its stderr ends at 03:06:41 after 3 repeats of Failed to allocate a page (67108864 bytes), try again. How do you classify the death?
Turning it on
The JVM reads this option when the executor launches, so it belongs in the submit command or the builder of a new application; setting it on a running session changes nothing. Sending the log to stdout puts it behind the stdout link in the Executors tab, beside the stderr from the previous section. For long jobs, write to a rotating file instead, -Xlog:gc:file=/tmp/gc-%p.log:time,uptime:filecount=5,filesize=20M, so a week of collections cannot fill a disk that shuffle files also need.
Reading a line
A G1 pause line looks like this: [1201.002s][info][gc] GC(311) Pause Young (Normal) (G1 Evacuation Pause) 6144M->1210M(8192M) 52.104ms. Read it from the right. 52.104ms is the pause, during which every task thread on the executor stood still. 8192M is the heap's capacity. 6144M->1210M is occupancy before and after, so this collection freed 4,934 MB. The after-value matters most: whatever survives a collection is still referenced by something, so it is an upper bound on the data the executor is keeping alive.
| Uptime | Event | Heap before->after | Pause |
|---|---|---|---|
| 1201.0s | Pause Young | 6144M->1210M | 52 ms |
| 1201.5s | Pause Young | 6150M->1222M | 57 ms |
| 1202.0s | Pause Young | 6139M->1198M | 54 ms |
| 1202.5s | Pause Young | 6160M->1215M | 55 ms |
| Uptime | Event | Heap before->after | Pause |
|---|---|---|---|
| 1840.2s | Pause Young | 7020M->5410M | 120 ms |
| 1846.8s | Pause Young | 7390M->6620M | 180 ms |
| 1851.1s | Pause Young | 7810M->7350M | 240 ms |
| 1853.0s | Pause Full | 8180M->7960M | 9310 ms |
Churn or a full heap
- After-GC heap low and flat
- Each young pause frees most of the heap
- No full collections
- Cause: code creating short-lived objects for each row
- Fix: allocate less, starting from the frames that allocate most
- After-GC heap climbing toward capacity
- Each pause frees less than the last
- Full collections that free little, then OutOfMemoryError
- Cause: tasks holding more than their share of heap
- Fix: hold less per task, or give each task more heap
Executor 14 has a 12 GB heap and its GC Time shows red. During a slow stage its GC log prints a pause every 0.4 seconds: 9800M->2110M 71ms, 9820M->2090M 69ms, 9790M->2150M 73ms, 9810M->2100M 70ms. Which reading is right?
Attaching to an executor
- To a running executor: on the worker, jps -l lists the executor as the process whose main class ends in CoarseGrainedExecutorBackend. Then asprof -d 60 -e cpu -f /tmp/exec7.html 48211 samples process 48211 for 60 seconds while the slow stage runs.
- From launch: load the profiler as an agent through spark.executor.extraJavaOptions, and every executor writes its own profile when it exits.
Reading by width
A 60-second profile of a slow stage
An executor with 4 cores, sampled for 60 seconds at the default 10 ms interval, collects at most 24,000 CPU samples. This profile comes from a stage that pulls the domain out of each page view's referrer URL with regexp_extract:
| Frame | Sits under | Samples | Width |
|---|---|---|---|
| Executor$TaskRunner.run | thread root | 21,600 | 90% |
| GeneratedIteratorForCodegenStage2.processNext | TaskRunner.run | 15,840 | 66% |
| java.util.regex.Matcher.find | processNext | 9,360 | 39% |
| VectorizedParquetRecordReader.nextBatch | processNext | 1,680 | 7% |
| LZ4BlockOutputStream.write | TaskRunner.run | 2,160 | 9% |
| G1 GC worker threads | their own roots | 1,920 | 8% |
The task runner covers 90% because nearly every sample came from a task thread, and processNext, the generated code for the whole stage, covers 66%. Climb further and most of that width belongs to Matcher.find, topped by nothing but regex internals. Matching the pattern against each referrer costs 39% of the executor's CPU, more than reading Parquet, compressing shuffle output and collecting garbage put together, which sum to 24%. That is the hot code. Rewriting the extraction with substring_index, which splits on a fixed delimiter without a pattern engine, or storing the domain once upstream, removes most of that width.
- ▸
-e cpu: where CPU time goes. The default, and the place to start when tasks run hot. - ▸
-e wall: every thread, running or waiting. Shows tasks parked in shuffle fetch or disk I/O, which cpu mode misses. - ▸
-e alloc: which frames allocate the bytes. Answers the churn question the GC log raised. - ▸
-e itimer: CPU sampling for hosts whose kernel blocks perf events.
- Profile while the slow stage runs, using its start and end on the stage timeline
- Profile the executor that runs the straggler task
- Split threads with -t when wall mode mixes in idle pool threads
- Read left-to-right position as the order code ran in
- Read a tall tower as slow code; height is only call depth
- Trust a 2% frame from a 5-second profile
A 60-second cpu profile of a straggler shows Executor$TaskRunner.run at 92%. Above it, UnsafeExternalSorter.spill covers 41%, with LZ4BlockOutputStream.write at 30% on top of that, and processNext covers 35%. What does the graph say?
What the ratio tells you
| Stage | Spill (Memory) | Spill (Disk) | Ratio | Spill time goes to |
|---|---|---|---|---|
| 7 | 96 GB | 12 GB | 8.0 | CPU: serializing and compressing |
| 12 | 30 GB | 27 GB | 1.1 | Disk: writing nearly every byte held |
The ratio also converts shuffle bytes into memory bytes. Shuffle files go through the same serializer and the same lz4 codec as spill files, so a task's Shuffle Read Size times the ratio approximates the memory that task needs to hold its whole input.
Stage 21 shows Spill (Memory) of 44 GB and Spill (Disk) of 40 GB. Its tasks run slowly while executor CPU sits near 30%. Where does the spill time go?
Sizing from what tasks held
spark.conf.set("spark.sql.autoBroadcastJoinThreshold", -1)joined = events.join(users, "user_id")joined.count()
Stage 15: 200 tasks, 16 GB heaps, 4 cores
| Metric | Median task | Max task |
|---|---|---|
| Shuffle Read Size | 690 MB | 705 MB |
| Peak Execution Memory | 2,300 MB | 2,360 MB |
| Spill (Memory) | 3,200 MB | 3,280 MB |
| Spill (Disk) | 400 MB | 410 MB |
Supply first. A 16 GB heap is 16,384 MB; subtract the 300 MB Spark reserves and multiply by spark.memory.fraction, 0.6, to get 9,650 MB of unified memory. With 4 tasks running and nothing cached, each can claim a quarter, about 2,410 MB. Now demand. The max task peaked at 2,360 MB and spilled 3,280 MB more, so it wanted about 5,640 MB, which matches its 705 MB of shuffle input times the ratio of 8. Each task needs about 2.3 times the memory it gets.
The UI's numbers come from the JVM. Below the container boundary, only the worker's own tools report.
The kill the JVM never logs
An executor killed with SIGKILL writes nothing on the way out, so its stderr stops mid-line with no stack trace or shutdown message. Its exit code is 137, which is 128 plus signal 9. The signal comes from the container's memory limit, which counts heap, memoryOverhead and native allocations together, or from the kernel's OOM killer when the whole worker runs short. A cgroup limit or the OOM killer leaves its record in the kernel log; a cluster manager that polls memory and kills on its own writes to its node log instead.
On the worker, run dmesg -T | grep -i -E 'killed process|out of memory' and look for a line such as Memory cgroup out of memory: Killed process 51877 (java) total-vm:21458712kB, anon-rss:18450432kB. The anon-rss figure is what the process held when it died: 18,018 MB. A 16 GB heap with the default 10% overhead sets an 18,022 MB limit, and the kernel kills the process as it reaches that limit, so anon-rss lands at the limit and never past it. The heap holds at most 16,384 MB, so native memory took at least the other 1,634 MB, filled the 1,638 MB of overhead and still asked for more. Raise spark.executor.memoryOverhead to 3 GB for headroom, then check that the kills stop.
Executor 11 on worker 10.0.4.38 disappears with exit code 137. Its stderr ends mid-line with no exception, and its GC log's last after-value was 6.1 GB of a 12 GB heap. Where do you look next, and what do you expect to find?
Disk, memory and network saturation
| Symptom in Spark | Check on the worker | Saturated looks like |
|---|---|---|
| Exit 137, stderr cut off, no Java error | `dmesg -T` | `Killed process ... (java)` at the exit time |
| Tasks slow, GC low, CPU idle | `vmstat 5`, then `iostat -x 5` | High `wa`; `w_await` in tens of ms on the spill disk |
| GC pauses jump from milliseconds to seconds | `vmstat 5` | Nonzero `si` and `so`: the heap is swapping |
| High Shuffle Read Blocked Time | `sar -n DEV 5`, `nstat` | Receive rate near link speed, or retransmits climbing |
| `No space left on device` | `df -h` on each `spark.local.dir` | A local directory at 100% |
A worker during a slow shuffle stage
| r | b | si | so | us | sy | id | wa |
|---|---|---|---|---|---|---|---|
| 3 | 11 | 0 | 0 | 9 | 4 | 49 | 38 |
| 2 | 12 | 0 | 0 | 8 | 4 | 45 | 43 |
| 3 | 12 | 0 | 0 | 10 | 5 | 40 | 45 |
The worker has 16 cores. The b column counts processes blocked in uninterruptible I/O, 11 to 12 here, while user CPU stays between 8% and 10% and wa, the time CPUs sat idle waiting on I/O, climbs from 38% to 45%. With si and so at zero, memory is fine. The executors are ready to work and the disks hold them back: the shuffle and spill files under spark.local.dir are the bottleneck, and iostat -x 5 names the device. Spread spark.local.dir across every local disk as a comma-separated list, or cut the bytes written with the shuffle and spill fixes from earlier sections.
Network saturation surfaces as Shuffle Read Blocked Time, the stage page's measure of how long tasks waited on remote blocks. sar -n DEV 5 prints receive and transmit rates per interface, and a 10 Gb/s link tops out near 1,250 MB/s. If the rate sits well below that while blocked time stays high, run nstat twice and compare TcpRetransSegs: a count rising by thousands per interval means packets are being lost and resent.
A shuffle stage is slow. On a worker, vmstat 5 shows wa at 2% and id at 70%, sar -n DEV 5 shows 410 MB/s received on a 10 Gb/s link, and TcpRetransSegs in nstat rises by 9,000 per interval. What limits the stage?
> The Netflix on-call engineer from the intro sorts the driver log by time. Before the 40,000 fetch-failure lines, the first of the 6 lost executors shows Failed to allocate a page warnings in its stderr, then exit code 52. Its GC log has after-values climbing toward capacity during the aggregation stage, whose Spill (Memory) is 8 times its Spill (Disk) and whose max task wanted far more than its share of execution memory. A flame graph of a surviving executor shows spill and compression frames covering most of its CPU. Compression shrank each spill to an eighth, yet vmstat on the workers still shows wa climbing: every task's compressed spill lands on a single local disk, and that combined volume saturates it. The fix is a shuffle partition count sized from peak plus spill, and spark.local.dir spread across every disk.
wa, nonzero swap and climbing retransmits are failures only the worker's kernel and tools can show.Find why an executor died: its logs, its GC log, a flame graph, its spill ratio and the worker's kernel.
- Category
- Spark
- Difficulty
- advanced
- Duration
- 15 minutes
- Challenges
- 14 hands-on challenges
Topics covered: Reading Executor Logs, GC Logs, Flame Graphs, Spill Ratios, The OS Layer
Lesson Sections
- Reading Executor Logs
The Spark UI tells you an executor was lost and which tasks went down with it. It cannot tell you why the process stopped, because the reason was written to that executor's own stderr seconds before it exited. Each executor is a separate JVM that writes its log lines to a stderr file on its worker, and while it is alive the Executors tab links to that file in the Logs column. After the executor exits and its container is cleaned up, that link goes dead. The file then lives wherever your cluster
- GC Logs
The GC Time column in the Executors tab says how much of a task went to garbage collection. It cannot say whether the collector was clearing short-lived garbage at a furious rate or fighting for room in a heap packed with data the job still needs. Those 2 problems call for opposite fixes, and the JVM's GC log separates them: a line per collection, with heap occupancy before and after. Turning it on Reading a line Here are 2 executors from the same stage, both with GC Time shown in red in the Exe
- Flame Graphs
The GC log can report that executor 3 allocates 9.9 GB a second without saying which code does it, and the stage page stops at the task. A sampling profiler goes a level deeper. Many times a second it records the call stack of every running thread, then merges the stacks into a flame graph in which each frame's width is its share of the samples. Attaching to an executor async-profiler is the usual choice for executor JVMs. It samples without safepoint bias, the distortion that makes profilers bu
- Spill Ratios
A stage that spills adds 2 columns to its stage page, Spill (Memory) and Spill (Disk), and they measure the same records in 2 states. Spill (Memory) is the execution memory a task released by spilling, counted as the memory pages it held at that moment. Spill (Disk) is what those records took up once serialized and compressed into a spill file. Their quotient is a compression ratio for your data in the form the engine holds it. With a ratio of 8, every byte on disk had been 8 bytes of memory. Wh
- The OS Layer
Every tool so far reads the JVM from inside: its stderr, its collector, its stacks, its task metrics. Some failures happen underneath it. The kernel can kill the process, a disk can saturate while the JVM sees only slow writes, and a network card can drop packets that TCP resends without the JVM ever knowing. For those, the UI shows a symptom with no cause, and the evidence is on the worker. The kill the JVM never logs Disk, memory and network saturation A worker during a slow shuffle stage