关注 spark技术分享,
撸spark源码 玩spark最佳实践

Developing Custom SparkListener to monitor DAGScheduler in Scala

Exercise: Developing Custom SparkListener to monitor DAGScheduler in Scala

The example shows how to develop a custom Spark Listener. You should read Spark Listeners — Intercepting Events from Spark Scheduler first to understand the motivation for the example.

Requirements

  1. IntelliJ IDEA (or eventually sbt alone if you’re adventurous).

  2. Access to Internet to download Apache Spark’s dependencies.

Setting up Scala project using IntelliJ IDEA

Create a new project custom-spark-listener.

Add the following line to build.sbt (the main configuration file for the sbt project) that adds the dependency on Apache Spark.

build.sbt should look as follows:

Custom Listener – pl.jaceklaskowski.spark.CustomSparkListener

Create a Scala class — CustomSparkListener — for your custom SparkListener. It should be under src/main/scala directory (create one if it does not exist).

The aim of the class is to intercept scheduler events about jobs being started and tasks completed.

Creating deployable package

Package the custom Spark listener. Execute sbt package command in the custom-spark-listener project’s main directory.

You should find the result jar file with the custom scheduler listener ready under target/scala-2.11 directory, e.g. target/scala-2.11/custom-spark-listener_2.11-1.0.jar.

Activating Custom Listener in Spark shell

Start spark-shell with additional configurations for the extra custom listener and the jar that includes the class.

Create a Dataset and execute an action like show to start a job as follows:

The lines with [CustomSparkListener] came from your custom Spark listener. Congratulations! The exercise’s over.

BONUS Activating Custom Listener in Spark Application

Questions

  1. What are the pros and cons of using the command line version vs inside a Spark application?

赞(0) 打赏
未经允许不得转载:spark技术分享 » Developing Custom SparkListener to monitor DAGScheduler in Scala
分享到: 更多 (0)

关注公众号:spark技术分享

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏