我正在寻找一种方法来打印Spark中Streaming应用程序的执行计划。我知道可以print the plan of a SQL Spark application。但是,我想显示流应用程序的逻辑和物理计划。这是我的应用程序:
package org.sense.spark.app
import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.{HashPartitioner, SparkConf}
object TestStreamCombineByKey {
def main(args: Array[String]): Unit = {
// Create a local StreamingContext with two working thread and batch interval of 1 second.
// The master requires 2 cores to prevent from a starvation scenario.
val conf = new SparkConf().setMaster("local[2]").setAppName("NetworkWordCount")
val ssc = new StreamingContext(conf, Seconds(5))
// Create a DStream that will connect to hostname:port, like localhost:9999
val lines = ssc.socketTextStream("localhost", 9999)
// Split each line into words
val words = lines.flatMap(_.split(" "))
// Count each word in each batch
val pairs = words.map(word => (word, 1))
// val wordCounts = pairs.reduceByKey(_ + _)
val wordCounts = pairs.combineByKey(
(v) => (v, 1), //createCombiner
(acc: (Int, Int), v) => (acc._1 + v, acc._2 + 1), //mergeValue
(acc1: (Int, Int), acc2: (Int, Int)) => (acc1._1 + acc2._1, acc1._2 + acc2._2), // mergeCombiners
new HashPartitioner(3)
)
// Print the first ten elements of each RDD generated in this DStream to the console
wordCounts.print()
ssc.start() // Start the computation
ssc.awaitTermination() // Wait for the computation to terminate
}
}
答案 0 :(得分:1)
使用UI(来自History Server)来获得稍微不同的视角。
无法在此处请求。为什么?您正在使用带有“ RDD”的dStream。逻辑计划和物理计划仅适用于数据框和数据集。
您将需要使用debugToString并使用spark-shell并将其插入正确的代码位置。就是说,dStream需要编译,并且就我所知不能仅在spark-shell中运行,因此我将与此相关的非dStream代码仅粘贴到spark-shell中。
此外,这一切都已弃用,我的建议是投资Spark结构化流媒体。