Local mode runs Spark on a single machine using one or more threads. It is useful for development, testing, and learning because it does not require a cluster setup.
Click to reveal answer
beginner
What is Cluster mode in Apache Spark?
Cluster mode runs Spark on multiple machines (nodes) working together. It allows processing large datasets by distributing tasks across many computers.
Click to reveal answer
beginner
Name one advantage of Local mode over Cluster mode.
Local mode is easier to set up and faster to start because it runs on a single machine without needing a cluster.
Click to reveal answer
beginner
Why use Cluster mode instead of Local mode?
Cluster mode is used to handle big data that cannot fit or be processed efficiently on one machine. It uses many machines to speed up processing.
Click to reveal answer
intermediate
How does Spark distribute work in Cluster mode?
Spark splits data into parts and sends these parts to different machines (workers). Each machine processes its part, then results are combined.
Click to reveal answer
Which mode runs Spark on a single machine?
ACloud mode
BCluster mode
CDistributed mode
DLocal mode
✗ Incorrect
Local mode runs Spark on one machine using threads.
What is a key benefit of Cluster mode?
ARuns faster on a single machine
BProcesses large datasets using multiple machines
CRequires no setup
DUses less memory
✗ Incorrect
Cluster mode uses many machines to handle big data efficiently.
Which mode is best for learning and testing Spark?
ACluster mode
BCloud mode
CLocal mode
DHybrid mode
✗ Incorrect
Local mode is simple and good for learning and testing.
In Cluster mode, how is data processed?
AData is split and processed on multiple machines
BData is processed only on the driver node
CData is processed manually
DAll data processed on one machine
✗ Incorrect
Cluster mode splits data and processes it across many machines.
Which of these is NOT true about Local mode?
ARequires a cluster setup
BGood for small datasets
CRuns on a single machine
DFaster to start than cluster mode
✗ Incorrect
Local mode does NOT require a cluster setup.
Explain the main differences between Local mode and Cluster mode in Apache Spark.
Think about where Spark runs and why you would choose each mode.
You got /5 concepts.
Describe a scenario where you would prefer to use Local mode over Cluster mode.
Consider ease of setup and dataset size.
You got /4 concepts.
Practice
(1/5)
1. What is the main difference between local mode and cluster mode in Apache Spark?
easy
A. Local mode requires a cluster manager; cluster mode does not.
B. Local mode is used only for streaming data; cluster mode is for batch data.
C. Local mode runs Spark on one computer; cluster mode runs Spark on many computers.
D. Local mode uses more memory than cluster mode.
Solution
Step 1: Understand local vs cluster mode
Local mode runs Spark on a single machine, suitable for small data and testing. Cluster mode runs Spark across multiple machines to handle big data.
Final Answer:
Local mode runs Spark on one computer; cluster mode runs Spark on many computers. -> Option C
Quick Check:
Local = single machine, Cluster = multiple machines [OK]
Hint: Local = one computer, cluster = many computers [OK]
Common Mistakes:
Confusing local mode with cluster mode resource needs
Thinking local mode requires cluster manager
Assuming local mode is only for streaming
2. Which of the following is the correct way to set Spark to run in local mode on all CPU cores using SparkSession in Python?
easy
A. spark = SparkSession.builder.master('remote').getOrCreate()
B. spark = SparkSession.builder.master('cluster').getOrCreate()
C. spark = SparkSession.builder.master('local').getOrCreate()
D. spark = SparkSession.builder.master('local[*]').getOrCreate()
Solution
Step 1: Recall local mode syntax for all cores
Local mode can be set with 'local[*]' to use all CPU cores. The correct syntax is spark = SparkSession.builder.master('local[*]').getOrCreate().
Final Answer:
spark = SparkSession.builder.master('local[*]').getOrCreate() -> Option D
Quick Check:
Use 'local[*]' for local mode with all cores [OK]
Hint: Use 'local[*]' to run Spark locally on all CPU cores [OK]
Common Mistakes:
Using 'cluster' or 'remote' as master for local mode
Forgetting to call getOrCreate()
Using 'local' without brackets when multiple cores needed
3. Given this code snippet, what will be the output if Spark is run in local mode?
from pyspark.sql import SparkSession
spark = SparkSession.builder.master('local').appName('TestApp').getOrCreate()
data = [('Alice', 30), ('Bob', 25)]
df = spark.createDataFrame(data, ['Name', 'Age'])
df.show()
medium
A. A table showing two rows: Alice 30 and Bob 25
B. An error because local mode cannot create DataFrame
C. Empty output with no rows
D. A table showing only one row: Alice 30
Solution
Step 1: Analyze code in local mode
Local mode runs Spark on one machine and supports DataFrame creation and display. The code creates a DataFrame with two rows: ('Alice', 30) and ('Bob', 25), and df.show() prints both rows as a table.
Final Answer:
A table showing two rows: Alice 30 and Bob 25 -> Option A
Quick Check:
Local mode supports DataFrame and df.show() prints all rows [OK]
Hint: df.show() prints all DataFrame rows in local mode [OK]
Common Mistakes:
Thinking local mode cannot create DataFrames
Expecting empty output without data
Assuming only one row prints by default
4. You wrote this code to run Spark in cluster mode but get an error:
B. Using 'local' instead of a cluster manager URL in master setting
C. Missing import statement for SparkSession
D. Using appName instead of clusterName
Solution
Step 1: Identify mistake in cluster mode setup
Cluster mode requires a cluster manager URL like 'spark://...' or 'yarn', not 'local'. Using 'local' runs Spark locally, causing the cluster setup to fail.
Final Answer:
Using 'local' instead of a cluster manager URL in master setting -> Option B
Quick Check:
Cluster mode needs cluster manager URL, not 'local' [OK]
Hint: Cluster mode needs cluster manager URL, not 'local' [OK]
Common Mistakes:
Confusing local and cluster master settings
Forgetting to import SparkSession
Missing getOrCreate() call
5. You want to test your Spark code on your laptop before running it on a big cluster. Which setting should you use for the master parameter to simulate cluster behavior locally using all CPU cores?
hard
A. 'local[*]'
B. 'yarn-client'
C. 'spark://master:7077'
D. 'local[1]'
Solution
Step 1: Select local setting to simulate cluster
'local[1]' uses one core; 'local[*]' uses all CPU cores on your laptop to simulate parallelism like a cluster locally.
Final Answer:
'local[*]' -> Option A
Quick Check:
'local[*]' uses all cores to mimic cluster parallelism [OK]
Hint: Use 'local[*]' to simulate cluster with all cores locally [OK]
Common Mistakes:
Choosing 'local[1]' which uses only one core
Using actual cluster URLs when testing locally
Confusing 'yarn-client' with local mode
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.