📖 Scenario: You are a data engineer working with Apache Spark. You want to monitor your Spark jobs after they finish by using the Spark History Server. This helps you see job details like stages, tasks, and performance metrics.
🎯 Goal: Set up a simple Spark application log directory, configure Spark to save event logs there, run a Spark job to generate logs, and then verify the logs are available for the Spark History Server to display.
📋 What You'll Learn
Create a directory path variable for Spark event logs
Configure Spark to enable event logging and set the log directory
Run a simple Spark job that generates event logs
Print the path where Spark event logs are saved
💡 Why This Matters
🌍 Real World
Spark History Server is used in real data engineering to monitor and debug Spark jobs after they finish, helping teams improve performance and troubleshoot issues.
💼 Career
Knowing how to configure and use Spark History Server is important for roles like Data Engineer, Big Data Developer, and DevOps Engineer working with Spark clusters.
Progress0 / 4 steps
1
Create Spark Event Log Directory Variable
Create a variable called event_log_dir and set it to the string "/tmp/spark-events" which will be used as the directory to store Spark event logs.
Apache Spark
Hint
Use a simple string assignment to create the variable.
2
Configure Spark to Enable Event Logging
Create a dictionary called spark_conf with two entries: "spark.eventLog.enabled" set to "true" and "spark.eventLog.dir" set to the variable event_log_dir.
Apache Spark
Hint
Use a dictionary with exact keys and values as strings.
3
Run a Simple Spark Job to Generate Logs
Using PySpark, create a SparkSession with the configuration spark_conf. Then create an RDD from the list [1, 2, 3, 4, 5], map each number to its square, and collect the results into a variable called squares.
Apache Spark
Hint
Use SparkSession builder with config, then create RDD and map.
4
Print the Spark Event Log Directory
Write a print statement to display the text "Spark event logs are saved in: " followed by the value of the variable event_log_dir.
Apache Spark
Hint
Use print with string concatenation or f-string.
Practice
(1/5)
1. What is the main purpose of the Spark History Server in monitoring Spark applications?
easy
A. To monitor real-time streaming data only
B. To view details of completed Spark jobs using saved event logs
C. To configure Spark cluster resources dynamically
D. To submit new Spark jobs to the cluster
Solution
Step 1: Understand Spark History Server role
The Spark History Server reads event logs from completed jobs to provide detailed information about them.
Step 2: Differentiate from other Spark components
Unlike job submission or real-time monitoring, it focuses on past job performance using saved logs.
Final Answer:
To view details of completed Spark jobs using saved event logs -> Option B
Quick Check:
Spark History Server = View completed job details [OK]
Hint: History Server shows past jobs, not live or submission tasks [OK]
Common Mistakes:
Confusing History Server with job submission tools
Thinking it monitors only live streaming jobs
Assuming it manages cluster resources
2. Which Spark configuration property must be set to enable event logging for the History Server?
easy
A. spark.sql.shuffle.partitions
B. spark.history.fs.logDirectory
C. spark.executor.memory
D. spark.eventLog.enabled
Solution
Step 1: Identify event logging property
The property spark.eventLog.enabled controls whether Spark saves event logs for completed jobs.
Step 2: Differentiate from other configs
spark.history.fs.logDirectory sets log location, not enabling logging; others relate to memory or shuffle partitions.