diff options
Diffstat (limited to 'docs/spark-debugger.md')
-rw-r--r-- | docs/spark-debugger.md | 99 |
1 files changed, 56 insertions, 43 deletions
diff --git a/docs/spark-debugger.md b/docs/spark-debugger.md index 71f9d001d4..f6f0988858 100644 --- a/docs/spark-debugger.md +++ b/docs/spark-debugger.md @@ -27,82 +27,95 @@ _A note on nondeterminism:_ For fault recovery, Spark requires RDD transformatio ### Enabling the event log -* To turn on event logging for your program, set `$SPARK_JAVA_OPTS` in `conf/spark-env.sh` as follows: - - export SPARK_JAVA_OPTS='-Dspark.arthur.logPath=path/to/event-log' - - where `path/to/event-log` is where you want the event log to go relative to `$SPARK_HOME`. +To turn on event logging for your program, set `$SPARK_JAVA_OPTS` in `conf/spark-env.sh` as follows: - **Warning:** If `path/to/event-log` already exists, event logging will be automatically disabled. +{% highlight bash %} +export SPARK_JAVA_OPTS='-Dspark.arthur.logPath=path/to/event-log' +{% endhighlight %} + +where `path/to/event-log` is where you want the event log to go relative to `$SPARK_HOME`. + +**Warning:** If `path/to/event-log` already exists, event logging will be automatically disabled. ### Loading the event log into the debugger 1. Run a Spark shell with `MASTER=<i>host</i> ./spark-shell`. 2. Use `EventLogReader` to load the event log as follows: - - spark> val r = new spark.EventLogReader(sc, Some("path/to/event-log")) - r: spark.EventLogReader = spark.EventLogReader@726b37ad + {% highlight scala %} +spark> val r = new spark.EventLogReader(sc, Some("path/to/event-log")) +r: spark.EventLogReader = spark.EventLogReader@726b37ad +{% endhighlight %} **Warning:** If the event log doesn't exist or is unreadable, this will silently fail and `r.events` will be empty. ### Exploring intermediate RDDs -* Use `r.rdds` to get a list of intermediate RDDs generated during your program's execution. An RDD with id _x_ is located at <code>r.rdds(<i>x</i>)</code>. For example: +Use `r.rdds` to get a list of intermediate RDDs generated during your program's execution. An RDD with id _x_ is located at <code>r.rdds(<i>x</i>)</code>. For example: - scala> r.rdds - res8: scala.collection.mutable.ArrayBuffer[spark.RDD[_]] = ArrayBuffer(spark.HadoopRDD@fe85adf, spark.MappedRDD@5fa5eea1, spark.MappedRDD@6d5bd16, spark.ShuffledRDD@3a70f2db, spark.FlatMappedValuesRDD@4d5825d6, spark.MappedValuesRDD@561c2c45, spark.CoGroupedRDD@539e922d, spark.MappedValuesRDD@4f8ef33e, spark.FlatMappedRDD@32039440, spark.ShuffledRDD@8fa0f67, spark.MappedValuesRDD@590937cb, spark.CoGroupedRDD@6c2e1e17, spark.MappedValuesRDD@47b9af7d, spark.FlatMappedRDD@6fb05c54, spark.ShuffledRDD@237dc815, spark.MappedValuesRDD@16daece7, spark.CoGroupedRDD@7ef73d69, spark.MappedValuesRDD@19e0f99e, spark.FlatMappedRDD@1240158, spark.ShuffledRDD@62d438fd, spark.MappedValuesRDD@5ae99cbb, spark.FilteredRDD@1f30e79e, spark.MappedRDD@43b64611) +{% highlight scala %} +scala> r.rdds +res8: scala.collection.mutable.ArrayBuffer[spark.RDD[_]] = ArrayBuffer(spark.HadoopRDD@fe85adf, spark.MappedRDD@5fa5eea1, spark.MappedRDD@6d5bd16, spark.ShuffledRDD@3a70f2db, spark.FlatMappedValuesRDD@4d5825d6, spark.MappedValuesRDD@561c2c45, spark.CoGroupedRDD@539e922d, spark.MappedValuesRDD@4f8ef33e, spark.FlatMappedRDD@32039440, spark.ShuffledRDD@8fa0f67, spark.MappedValuesRDD@590937cb, spark.CoGroupedRDD@6c2e1e17, spark.MappedValuesRDD@47b9af7d, spark.FlatMappedRDD@6fb05c54, spark.ShuffledRDD@237dc815, spark.MappedValuesRDD@16daece7, spark.CoGroupedRDD@7ef73d69, spark.MappedValuesRDD@19e0f99e, spark.FlatMappedRDD@1240158, spark.ShuffledRDD@62d438fd, spark.MappedValuesRDD@5ae99cbb, spark.FilteredRDD@1f30e79e, spark.MappedRDD@43b64611) +{% endhighlight %} -* Use `r.printRDDs()` to get a formatted list of intermediate RDDs, along with the source location where they were created. For example: +Use `r.printRDDs()` to get a formatted list of intermediate RDDs, along with the source location where they were created. For example: - scala> r.printRDDs - #00: HadoopRDD spark.bagel.examples.WikipediaPageRankStandalone$.main(WikipediaPageRankStandalone.scala:31) - #01: MappedRDD spark.bagel.examples.WikipediaPageRankStandalone$.main(WikipediaPageRankStandalone.scala:31) - #02: MappedRDD spark.bagel.examples.WikipediaPageRankStandalone$.main(WikipediaPageRankStandalone.scala:35) - #03: ShuffledRDD spark.bagel.examples.WikipediaPageRankStandalone$.main(WikipediaPageRankStandalone.scala:35) - #04: FlatMappedValuesRDD spark.bagel.examples.WikipediaPageRankStandalone$.main(WikipediaPageRankStandalone.scala:35) - #05: MappedValuesRDD spark.bagel.examples.WikipediaPageRankStandalone$.pageRank(WikipediaPageRankStandalone.scala:91) - #06: CoGroupedRDD spark.bagel.examples.WikipediaPageRankStandalone$.pageRank(WikipediaPageRankStandalone.scala:92) - [...] +{% highlight scala %} +scala> r.printRDDs +#00: HadoopRDD spark.bagel.examples.WikipediaPageRankStandalone$.main(WikipediaPageRankStandalone.scala:31) +#01: MappedRDD spark.bagel.examples.WikipediaPageRankStandalone$.main(WikipediaPageRankStandalone.scala:31) +#02: MappedRDD spark.bagel.examples.WikipediaPageRankStandalone$.main(WikipediaPageRankStandalone.scala:35) +#03: ShuffledRDD spark.bagel.examples.WikipediaPageRankStandalone$.main(WikipediaPageRankStandalone.scala:35) +#04: FlatMappedValuesRDD spark.bagel.examples.WikipediaPageRankStandalone$.main(WikipediaPageRankStandalone.scala:35) +#05: MappedValuesRDD spark.bagel.examples.WikipediaPageRankStandalone$.pageRank(WikipediaPageRankStandalone.scala:91) +#06: CoGroupedRDD spark.bagel.examples.WikipediaPageRankStandalone$.pageRank(WikipediaPageRankStandalone.scala:92) +[...] +{% endhighlight %} -* Use `r.visualizeRDDs()` to visualize the RDDs as a dependency graph. For example: +Use `r.visualizeRDDs()` to visualize the RDDs as a dependency graph. For example: - scala> r.visualizeRDDs - /tmp/spark-rdds-3758182885839775712.pdf +{% highlight scala %} +scala> r.visualizeRDDs +/tmp/spark-rdds-3758182885839775712.pdf +{% endhighlight %} - ![Example RDD dependency graph](http://www.ankurdave.com/images/rdd-dep-graph.png) +![Example RDD dependency graph](http://www.ankurdave.com/images/rdd-dep-graph.png) -* Iterate over the `RDDCreation` entries in `r.events` (e.g. `for (RDDCreation(rdd, location) <- events)`) to access the RDD creation locations as well as the RDDs themselves. +Iterate over the `RDDCreation` entries in `r.events` (e.g. `for (RDDCreation(rdd, location) <- events)`) to access the RDD creation locations as well as the RDDs themselves. ### Debugging a particular task 1. Find the task you want to debug. If the task threw an exception, the `ExceptionEvent` that was created will have a reference to the task. For example: - - spark> val task = r.events.collect { case e: ExceptionEvent => e }.head.task - + {% highlight scala %} +spark> val task = r.events.collect { case e: ExceptionEvent => e }.head.task +{% endhighlight %} Otherwise, look through the list of all tasks in `r.tasks`, or browse tasks by RDD using <code>r.tasksForRDD(<i>rdd</i>)</code>, which returns a list of tasks whose input is the given RDD. 2. Run the task by calling <code>r.debugTask(<i>taskStageId</i>, <i>taskPartition</i>)</code>. The task should contain these two values; you can extract them as follows: - - val (taskStageId, taskPartition) = task match { - case rt: ResultTask[_, _] => (rt.stageId, rt.partition) - case smt: ShuffleMapTask => (smt.stageId, smt.partition) - case _ => throw new UnsupportedOperationException - }) - - The Spark debugger will launch the task in a separate JVM, but you will see the task's stdout and stderr inline with the Spark shell. If you want to pass custom debugging arguments to the task's JVM (for example, to change the debugging port), set the optional `debugOpts` argument to `r.debugTask`. When `debugOpts` is left unset, it defaults to - - -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000 + {% highlight scala %} +val (taskStageId, taskPartition) = task match { + case rt: ResultTask[_, _] => (rt.stageId, rt.partition) + case smt: ShuffleMapTask => (smt.stageId, smt.partition) + case _ => throw new UnsupportedOperationException +}) +{% endhighlight %} + The Spark debugger will launch the task in a separate JVM, but you will see the task's stdout and stderr inline with the Spark shell. If you want to pass custom debugging arguments to the task's JVM (for example, to change the debugging port), set the optional `debugOpts` argument to `r.debugTask`. When `debugOpts` is left unset, it defaults to: + {% highlight scala %} +-Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000 +{% endhighlight %} 3. In another terminal, attach your favorite conventional debugger to the Spark shell. For example, if you want to use jdb, run `jdb -attach 8000`. 4. Debug the task as you would debug a normal program. For example, to break when an exception is thrown: - - > catch org.xml.sax.SAXParseException + {% highlight scala %} +> catch org.xml.sax.SAXParseException +{% endhighlight %} 5. When the task ends, its JVM will quit and control will return to the main Spark shell. To stop it prematurely, you can kill it from the debugger, or interrupt it from the terminal with Ctrl-C. ### Detecting nondeterminism in your transformations When a task gets run more than once, Arthur is able to compare the checksums of the task's output. If they are different, Arthur will insert a `ChecksumEvent` into `r.checksumMismatches` and print a warning like the following: + {% highlight scala %} +12/04/07 11:42:44 WARN spark.EventLogWriter: Nondeterminism detected in shuffle output on RDD 2, partition 3, output split 0 +{% endhighlight %} - 12/04/07 11:42:44 WARN spark.EventLogWriter: Nondeterminism detected in shuffle output on RDD 2, partition 3, output split 0 |