Bird
Raised Fist0
Apache Sparkdata~10 mins

Spark architecture (driver, executors, cluster manager) in Apache Spark - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a SparkSession named spark.

Apache Spark
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName([1]).getOrCreate()
Drag options to blanks, or click blank then click option'
A"MyApp"
BSparkContext
CExecutor
DClusterManager
Attempts:
3 left
💡 Hint
Common Mistakes
Using SparkContext instead of a string for appName
Not using quotes around the app name
2fill in blank
medium

Complete the code to get the SparkContext from the SparkSession.

Apache Spark
sc = spark.[1]
Drag options to blanks, or click blank then click option'
Acontext
BsparkContext
CSparkContext
DgetContext
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'SparkContext' with uppercase S and C
Using 'context' which does not exist
3fill in blank
hard

Fix the error in the code to submit a job to the cluster manager.

Apache Spark
rdd = sc.parallelize([1, 2, 3, 4])
result = rdd.[1](lambda x: x * 2).collect()
Drag options to blanks, or click blank then click option'
AflatMap
Bfilter
Creduce
Dmap
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter which selects elements instead of transforming
Using reduce which aggregates elements
4fill in blank
hard

Fill both blanks to create a dictionary of executor IDs and their memory usage.

Apache Spark
executor_info = {executor.[1]: executor.[2] for executor in sc._jsc.sc().getExecutorMemoryStatus().keySet()}
Drag options to blanks, or click blank then click option'
Aid
BmemoryUsed
Chost
DmemoryTotal
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' which is not a valid attribute here
Using 'memoryUsed' instead of 'memoryTotal'
5fill in blank
hard

Fill all three blanks to filter executors with memory greater than 4GB and create a list of their hostnames.

Apache Spark
hosts = [executor.[1] for executor, memory in sc._jsc.sc().getExecutorMemoryStatus().items() if memory [2] [3]]
Drag options to blanks, or click blank then click option'
Ahost
B>
C4 * 1024 * 1024 * 1024
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'host' for executor identifier
Using '<' instead of '>' for filtering
Not converting 4GB to bytes

Practice

(1/5)
1. Which component in Spark is responsible for planning the tasks and controlling the job execution?
easy
A. Task Scheduler
B. Executor
C. Cluster Manager
D. Driver

Solution

  1. Step 1: Understand the role of the Driver

    The Driver is the main program that creates the SparkContext and plans the tasks to run.
  2. Step 2: Compare with other components

    Executors run the tasks, and the Cluster Manager manages resources, but only the Driver plans and controls the job.
  3. Final Answer:

    Driver -> Option D
  4. Quick Check:

    Driver = plans tasks [OK]
Hint: Driver plans tasks; executors run them [OK]
Common Mistakes:
  • Confusing executors with driver
  • Thinking cluster manager plans tasks
  • Mixing driver with resource manager
2. Which of the following is the correct way to describe the role of executors in Spark?
easy
A. They manage cluster resources and allocate executors
B. They plan the job and schedule tasks
C. They run tasks and store data for the application
D. They submit jobs to the cluster manager

Solution

  1. Step 1: Identify executor responsibilities

    Executors run the tasks assigned by the driver and store data in memory or disk during processing.
  2. Step 2: Eliminate other options

    Cluster manager manages resources, driver plans jobs, and job submission is done by the driver, not executors.
  3. Final Answer:

    They run tasks and store data for the application -> Option C
  4. Quick Check:

    Executors = run tasks + store data [OK]
Hint: Executors run tasks and keep data [OK]
Common Mistakes:
  • Confusing executors with cluster manager
  • Thinking executors plan jobs
  • Mixing driver and executor roles
3. Consider a Spark application running on a cluster. Which component is responsible for requesting resources from the cluster manager?
medium
A. Driver
B. Executor
C. Cluster Manager
D. Task Scheduler

Solution

  1. Step 1: Understand resource request flow

    The Driver requests resources (executors) from the Cluster Manager to run tasks.
  2. Step 2: Clarify roles of other components

    Executors run tasks, Cluster Manager allocates resources, but Driver initiates the request.
  3. Final Answer:

    Driver -> Option A
  4. Quick Check:

    Driver requests resources [OK]
Hint: Driver asks cluster manager for executors [OK]
Common Mistakes:
  • Thinking executors request resources
  • Confusing cluster manager with driver
  • Assuming task scheduler requests resources
4. You see a Spark application failing because no executors are allocated. Which component should you check first to fix this issue?
medium
A. Cluster Manager configuration
B. Executor logs
C. Driver program code
D. Task Scheduler settings

Solution

  1. Step 1: Identify the cause of no executors

    No executors means the cluster manager did not allocate resources.
  2. Step 2: Check cluster manager setup

    Cluster Manager manages resource allocation; misconfiguration here can block executors.
  3. Final Answer:

    Cluster Manager configuration -> Option A
  4. Quick Check:

    Cluster Manager controls executors allocation [OK]
Hint: Check cluster manager if no executors start [OK]
Common Mistakes:
  • Checking driver code first instead of cluster manager
  • Looking at executor logs when none exist
  • Confusing task scheduler with resource manager
5. In a Spark cluster, if the driver fails but executors continue running, what is the expected behavior and why?
hard
A. Executors keep running tasks independently without driver
B. Executors stop working because driver controls task scheduling
C. Cluster manager automatically restarts executors without driver
D. Driver failure does not affect executors as they are independent

Solution

  1. Step 1: Understand driver role in task scheduling

    The driver plans and schedules tasks; executors depend on it for instructions.
  2. Step 2: Analyze executor behavior on driver failure

    Without the driver, executors cannot receive new tasks and will stop processing.
  3. Final Answer:

    Executors stop working because driver controls task scheduling -> Option B
  4. Quick Check:

    Driver failure stops executors [OK]
Hint: Executors need driver to schedule tasks [OK]
Common Mistakes:
  • Assuming executors run independently
  • Thinking cluster manager restarts executors automatically
  • Believing driver failure has no impact
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard