Spark Architecture & Execution model

Spark tutorial · PySpark.in

Spark Architecture & Execution model

Apache Spark works in a master-slave architecture where the master is called “Driver” and slaves are called “Workers".

Master manages, maintains, and monitors the slaves while slaves are the actual workers who perform the processing tasks. You tell the master what wants to be done and the master will take care of the rest. It will complete the task, using its slaves.

Apache Spark Architecture is based on two main abstractions :

Resilient Distributed Dataset (RDD):

RDDs are the building blocks of any Spark application. RDDs Stands

for:

Resilient: Fault tolerant and is capable of rebuilding data on failure

Distributed: Distributed data among the multiple nodes in a cluster

Dataset: Collection of partitioned data with values

  1. Transformations :

They are the operations that are applied to create a new RDD. This function is used to transform the data into new RDD without altering the original data. e.g. groupBy, sum, rename, sort, etc

2) Actions :

They are applied on an RDD to instruct Apache Spark to apply computation and send the result back to the driver.

e.g. write, collect, show,etc

Types of transformations:

  1. Narrow transformations –
  1. Wide transformations –

Lazy Evaluation:

Lazy Evaluation in Sparks means Spark will not start the execution of the process until an ACTION is called.

Spark is not too concerned as long as we are just performing transformations on the RDD, data frame or dataset.

Once Spark notices an ACTION being called, it starts looking at all the transformations, creates a DAG and execute it.

Directed Acyclic Graph (DAG) :

Components of Spark Application Architecture :

Spark Application :

SparkSession / SparkContext :

Job:

Stage:

Task:

Driver :

The Driver is the main program that runs on the master node and is responsible for coordinating the entire Spark application. The Driver is responsible for several tasks, including :

Managing the SparkContext: The Driver is responsible for creating and managing the Spark Context, which is the main entry point fora Spark application.

Breaking down the application into tasks: The Driver is responsible for breaking down the application into a set of tasks that can be executed in parallel on the worker nodes.

Scheduling tasks: The Driver is responsible for scheduling tasks to worker nodes, based on the available resources and the requirements of tasks.

Monitoring tasks: The Driver is responsible for monitoring the tasks and making sure that they are executing correctly. If a task fails, the Driver can reschedule it on a different node.

Gathering results: The Driver is responsible for gathering results of the tasks and combining them to produce the final result of the application.

The Driver is the central component of a Spark application, and it playsa critical role in ensuring that the application runs correctly and efficiently.

Executor :

The Executor is a program that runs on the worker nodes and is responsible for executing the tasks assigned by the Driver. The Executor is responsible for several tasks, including:

Running tasks: The Executor is responsible for running the tasks assigned by the Driver. Each Executor runs a set of tasks, and it can run multiple tasks in parallel, based on the number of cores available on the node.

Reporting status: The Executor is responsible for reporting the status of the tasks to the Driver. The Driver uses this information to monitor the progress of the application and make sure that it is executing correctly.

Storing intermediate data: The Executor can store intermediate data in memory, which can be used by other tasks. This allows Spark to avoid shuffling data between nodes, which can be a performance bottleneck.

Releasing resources: The Executor is responsible for releasing resources when the tasks are completed, which allows Spark to make the most efficient use of the available resources.

The Executor is a critical component of a Spark application, and it plays a crucial role in executing the tasks and producing the final result.

Cluster Manager :

The cluster manager is responsible for managing the resources required for a Spark application, including CPU, memory, and network resources. Its primary functions include :

Resource allocation: The cluster manager receives resource requests from the Spark driver and allocates the necessary resources, such as CPU cores and memory, to the application.

Executor management: The cluster manager launches and manages Spark executors on worker nodes, which are responsible for executing tasks and storing data.

Fault tolerance: The cluster manager monitors the health of the worker nodes and detects failures, ensuring the smooth execution of the application by reallocating resources and restarting failed tasks.

Node management: The cluster manager keeps track of the worker nodes' status and manages their lifecycle, handling node registration, de-registration, and decommissioning.

Types of cluster managers:

Standalone– a simple cluster manager included with Spark that makes it easy to set up a cluster.

Apache Mesos– a general cluster manager that can also run Hadoop MapReduce and service applications.

Hadoop YARN– the resource manager in Hadoop 2.

Kubernetes– an open-source system for automating deployment, scaling, and management of containerized applications.

Execution of Spark Application :


=

Spark Execution Modes :

There are 3 types of execution modes –

1) Local Mode :

  1. Client Mode:

  1. Cluster Mode:

More Spark tutorials

All tutorials · Try the free PySpark compiler · Practice challenges