How to Monitor Long running session in Azure Databricks

To monitor and troubleshoot long-running sessions in Azure Databricks, it’s essential to understand the execution hierarchy and how to navigate through the Spark UI. Below is a complete guide with explanations, insights, and key areas to monitor.


๐Ÿ” How Spark Jobs Execute in Azure Databricks

Hierarchy of Execution:

LevelDescription
NotebookUser-triggered execution unit, can contain multiple cells and logic
Spark JobRepresents an action (e.g., collect(), show(), save()) triggered
StageA set of tasks that can be executed in parallel. One job = multiple stages
TaskSmallest unit of execution; assigned to executor slots on worker nodes

๐Ÿšฆ Step-by-Step: How to Monitor a Long-Running Notebook

๐ŸŸข Step 1: Open the Spark UI

  • Go to the notebook.
  • Click on the “View” link beside a running job to drill down into details.

๐Ÿ“Š Step 2: Analyze Jobs and Stages

TabWhat to Look For
Jobs TabDuration of each job. Look for jobs taking unusually long.
Stages TabCheck if any stage is stuck, retrying, or has skewed partitions.
Tasks per StageHigh variance in task durations = skew. Look for stages with large input sizes.
Executors TabMonitor CPU/memory usage, GC time, input/output shuffle sizes.

๐Ÿ”ง Common Causes of Long-Running Jobs & Fixes

IssueWhere to LookFix/Strategy
Skewed JoinsStages โ†’ Task durationUse salting or broadcast joins
Too Many Partitionsspark.sql.shuffle.partitionsDecrease shuffle partitions
Insufficient ExecutorsExecutors tabEnable dynamic allocation or increase executors
High GC TimeExecutors โ†’ GC TimeIncrease executor memory or tune garbage collection
Collect() on Large DataDAG & SQL tabAvoid using collect() on large datasets

๐Ÿ“Œ Deep Dive: Tools and Values to Track

MetricMeaningThresholds/Insights
Shuffle Read/WriteIndicates shuffling of data between stagesHigh shuffle = poor partitioning or bad join strategy
GC TimeTime spent in Garbage Collection>10% of task time = memory tuning required
Executor Logs (stdout/stderr)Shows actual logs/errorsUse for debugging job-specific issues
DAG VisualizationShows flow of job execution (narrow vs wide transformations)Wide = shuffle boundaries

๐Ÿง  What Happens During collect()?

  • collect() pulls entire data from executors into the driver.
  • โš ๏ธ Dangerous for large datasets: Can crash driver or lead to Out of Memory.

Use only for small datasets, or switch to:

df.limit(1000).toPandas()  # safer for sampling

๐Ÿ“‚ Common Optimization Techniques

StrategyWhen to Use
Broadcast JoinWhen one table is small (few MBs)
SaltingWhen data is skewed on a join key
RepartitioningWhen uneven partitions or high shuffle is detected
CachingWhen reused across multiple stages
Dynamic AllocationWhen job needs vary in executor count

Spark Monitoring Checklist

AreaCheck What?Tool/UI TabFix/Action
Job DurationLong-running jobs in Spark UIJobs tabBreak logic into smaller actions
Stage DelayStages stuck or retriedStages tabRepartition or fix logic causing retries
Task SkewUneven task execution timeStages > TasksApply salting or broadcast joins
GC TimeGC Time >10% of task timeExecutors tabIncrease executor memory or tune GC
Shuffle Read/WriteHigh shuffle size or imbalanceStages tabAvoid wide transformations, optimize joins
Broadcast JoinUsed for small dimension tablesSQL Tab / DAGEnable broadcast hint
Executor MemoryMemory pressure or OOMExecutors tabIncrease memory or reduce collect()
Dynamic AllocationIs it enabled, limits tuned?Environment tabEnable + tune min/max executors
RepartitioningIs partitioning optimal?Spark config & Stage DAGUse coalesce/repartition with balance
DAG VisualizationVisual flow of transformationsJobs > DAGDebug performance bottlenecks

๐Ÿ’ฌ Conclusion

When investigating a long-running Databricks notebook, always start from the Job panel โ†’ drill down into Stages โ†’ Tasks โ†’ Executors. Keep an eye on GC time, shuffle behavior, and data movement. Visual aids like DAG visualization and thread dumps help you uncover skew, serialization issues, and resource bottlenecks.

Related Posts

Z-ORDER in Databricks: Magic or Myth?

When it helps, when it hurts, how to pick columns, and what KPIs to measure. Introduction: Why the Hype Around Z-ORDER? If youโ€™ve spent time in Databricks,…

Read More

Taming Small Files in Delta Lake

Optimal file sizes, compaction strategies, and how to keep your Delta tables lightning-fast Why Small Files Are a Big Problem Delta Lake is powerful, but it inherits…

Read More

Databrick Serverless compute plane networking

Hereโ€™s a simple line-by-line summary of the Serverless compute plane networking (08/04/2025): General idea Serverless egress control (outbound connections) Network Connectivity Configuration (NCC) What NCC enables: Extra…

Read More

Databrick Serverless compute limitations

Hereโ€™s a simple, line-by-line summary of the Serverless compute limitations (09/29/2025): General limitations Streaming limitations Machine learning limitations Notebook limitations Job limitations Compute-specific limitations Caching limitations Hive…

Read More

Best practices for Databrick serverless compute

Best practices for serverless compute Big picture Before you migrate Ingesting data (getting data in) Querying external data (without moving it) Spark configurations Watch your costs Quick…

Read More

Databrick Serverless compute release

Hereโ€™s a simple line-by-line summary of the important points from the Serverless Compute release notes (09/24/2025): Perfect ๐Ÿ‘ Hereโ€™s a one-page cheat sheet table for the Serverless…

Read More
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x