Jump to content

Driver (Apache Spark)

From Open Lakehouse Wiki
Driver (Apache Spark)
Also known as Spark driver, driver program
Field Distributed data processing
Key parts SparkContext, DAG scheduler, task scheduler, query planner, web UI (port 4040)
Open source implementations Apache Spark
Related Executor, SparkContext, SparkSession, Spark Connect, Job, stage and task
Last verified 23 November 2026 against the v4.3.0 tag of apache/spark (docs/cluster-overview.md, docs/submitting-applications.md, docs/configuration.md, docs/rdd-programming-guide.md, docs/running-on-kubernetes.md, docs/spark-connect-overview.md, python/pyspark/sql/dataframe.py, BroadcastExchangeExec.scala, QueryExecutionErrors.scala), a PySpark 4.3.0 run, and the Trino 484 concepts page.

In Apache Spark, the driver is the process that runs an application's main() function, creates the SparkContext, turns the program into tasks and schedules those tasks on executors.[1] Every Spark application has exactly one driver. The driver plans the work and coordinates the cluster; the executors read data, run the tasks and hold cached and shuffled data. Where the driver runs is set by the deploy mode, and its memory is a common cause of failures when results or broadcast tables are pulled back to it.

What runs in the driver and what runs in executors?

The Spark driver holds the application's control flow. It connects to a cluster manager (standalone, YARN or Kubernetes), acquires executors, sends them the application code, and then sends them tasks to run.[1] For DataFrame and SQL work, the driver also parses, analyzes and optimizes each query with the Catalyst optimizer and builds the physical plan. The DAG scheduler in the driver splits each job into stages and the task scheduler hands the tasks to executors.[2] Each driver serves a web UI, typically on port 4040, that shows its jobs, stages, tasks, executors and storage.[1]

Work Runs in the driver Runs in executors
Program logic outside Spark operations (loops, Python variables, print) Yes No
Query parsing, analysis, optimization and physical planning Yes No
Job, stage and task scheduling; retry decisions Yes No
Functions passed to map, filter and UDFs No Yes, inside tasks
Reading files, shuffling, joining and aggregating rows No Yes
Results of collect(), take() or toPandas() Received here Computed and serialized here

The split matters for side effects. Calling rdd.foreach(println) in cluster mode prints to each executor's standard output, not the driver's, because the function runs inside the executors.[3]

The driver must stay reachable by its executors for its whole lifetime, so it has to be network addressable from the worker nodes. The Spark documentation recommends running it close to the workers, preferably on the same local network.[1]

Client mode vs cluster mode

The deploy mode decides where the Spark driver process runs. In client mode the submitter launches the driver outside the cluster; in cluster mode the cluster framework launches the driver inside the cluster.[1] spark-submit --deploy-mode (or spark.submit.deployMode) selects it, and the default is client.[4][5]

Client mode Cluster mode
Where the driver runs Inside the spark-submit process on the submitting machine[4] On a node inside the cluster; on Kubernetes, in a driver pod[4][6]
Console input and output Attached to the submitting console; suited to the Spark shell and other REPLs[4] Not attached; read the driver log from the cluster
Typical use A gateway machine co-located with the workers[4] Submitting from a machine far from the workers, such as a laptop, to reduce driver to executor latency[4]
Setting driver memory Must be passed as --driver-memory or in the defaults file, because the driver JVM has already started when SparkConf is read[5] spark.driver.memory works as a normal setting; spark.driver.cores applies only in this mode[5]

Spark's standalone cluster manager does not support cluster mode for Python applications.[4] A PySpark 4.3.0 session started without options reports spark.submit.deployMode as client.

Why does the driver run out of memory?

The Spark driver's JVM heap is set by spark.driver.memory (default 1g). On YARN and Kubernetes in cluster mode, spark.driver.memoryOverhead adds non-heap memory, which also has to cover a Python process that goes with a PySpark driver.[5] The common causes of a driver out-of-memory error all move data into this process:

  • Collecting large results. collect() fetches the entire dataset to a single machine and can make the driver run out of memory; the Spark guide suggests take(n) when only some rows are needed.[3] The PySpark API reference gives the same warning for DataFrame.collect(), toPandas() and toArrow(): all the data is loaded into the driver's memory.[7]
  • Large total result size. spark.driver.maxResultSize (default 1g) limits the total serialized results of all partitions for one action; a job above the limit is aborted. Setting it high, or to 0 for unlimited, can lead to driver out-of-memory errors instead.[5]
  • Broadcast joins. For a broadcast join, Spark SQL collects the small side to the driver, builds the hash table there and then broadcasts it. If the driver runs out of memory while doing so, Spark reports that there is not enough memory to build and broadcast the table and suggests disabling broadcast with spark.sql.autoBroadcastJoinThreshold=-1 or raising the driver memory.[8][9]

Driver and Spark Connect

With Spark Connect, the client application no longer runs in the same process as the Spark driver. The client sends unresolved logical plans to a Spark Connect server, and that server runs the driver and its SparkContext. The client therefore cannot reach the driver JVM directly and has no access to the SparkContext or the static Spark configuration.[10] Several Connect sessions share one server's driver; state backed by the shared SparkContext, such as cached datasets and global temporary views, is shared across those sessions.[10]

Spark driver compared with other uses of the word

The word "driver" means something different in Trino, which causes confusion when reading Trino documentation next to Spark's.

Spark driver Trino driver
What it is One process per Spark application that plans and schedules all work[1] A sequence of operator instances inside a Trino task[11]
Closest counterpart in the other engine The Trino coordinator, which receives statements from clients and plans them[11] A Spark task, which runs a pipelined chain of narrow operations inside an executor[2]
How many per query One for the whole application, across all its queries Many, running on the workers[11]

See also

References

  1. ↑ 1.0 1.1 1.2 1.3 1.4 1.5 Cluster Mode Overview (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  2. ↑ 2.0 2.1 DAGScheduler.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  3. ↑ 3.0 3.1 RDD Programming Guide (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  4. ↑ 4.0 4.1 4.2 4.3 4.4 4.5 4.6 Submitting Applications (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  5. ↑ 5.0 5.1 5.2 5.3 5.4 Spark Configuration (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  6. ↑ Running Spark on Kubernetes (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  7. ↑ dataframe.py (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  8. ↑ BroadcastExchangeExec.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  9. ↑ QueryExecutionErrors.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  10. ↑ 10.0 10.1 Spark Connect Overview (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  11. ↑ 11.0 11.1 11.2 Trino concepts (Trino 484). Trino Software Foundation.Retrieved 2026-11-23.