如何查看Spark Streaming应用的逻辑和物理计划?
How to view the logical and physical plan of a Spark Streaming application?
我正在寻找一种在 Spark 中打印流式应用程序执行计划的方法。我知道可以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
}
}
使用UI(来自历史服务器)获得稍微不同的视角。
您在这里请求的是不可能的。为什么?您正在使用 "RDDs" 的 dStream。逻辑和物理计划仅适用于数据帧和数据集。
您需要使用 debugToString 并使用 spark-shell 并将其插入正确的代码位置。也就是说,据我所知,dStreams 需要编译并且不能只是 运行 在 spark-shell 中,所以我会将相关的非 dStream 代码粘贴到 spark-shell只有.
此外,这些都已弃用,我的建议是投资 Spark Structured Streaming。
我正在寻找一种在 Spark 中打印流式应用程序执行计划的方法。我知道可以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
}
}
使用UI(来自历史服务器)获得稍微不同的视角。
您在这里请求的是不可能的。为什么?您正在使用 "RDDs" 的 dStream。逻辑和物理计划仅适用于数据帧和数据集。
您需要使用 debugToString 并使用 spark-shell 并将其插入正确的代码位置。也就是说,据我所知,dStreams 需要编译并且不能只是 运行 在 spark-shell 中,所以我会将相关的非 dStream 代码粘贴到 spark-shell只有.
此外,这些都已弃用,我的建议是投资 Spark Structured Streaming。