Apache spark 如何检查结构化流媒体中的StreamingQuery性能指标?
我想从流式查询中获取诸如触发执行、inputRowsPerSecond、numInputRows、processedRowsPerSecond等信息 我正在使用Apache spark 如何检查结构化流媒体中的StreamingQuery性能指标?,apache-spark,spark-streaming,spark-structured-streaming,Apache Spark,Spark Streaming,Spark Structured Streaming,我想从流式查询中获取诸如触发执行、inputRowsPerSecond、numInputRows、processedRowsPerSecond等信息 我正在使用rate格式每秒生成10行,并使用queryprogressent获取所有指标 然而,在控制台中,当打印queryprogressent.inputRowsPerSecond时,我得到了不正确的值,如:625.0666.66 有人能解释为什么它会产生这样的价值吗 代码和示例输出如下: spark.streams.addListener(
rate
格式每秒生成10行
,并使用queryprogressent
获取所有指标
然而,在控制台中,当打印queryprogressent.inputRowsPerSecond
时,我得到了不正确的值,如:625.0
666.66
有人能解释为什么它会产生这样的价值吗
代码和示例输出如下:
spark.streams.addListener(new EventMetric())
val df = spark.readStream
.format("rate")
.option("rowsPerSecond",10)
.option("numPartitions",1)
.load()
.select($"value",$"timestamp")
df.writeStream
.outputMode("append")
.option("checkpointLocation", "/testjob")
.foreachBatch((batchDf: DataFrame, batchId: Long) =>{
println("rowcount value >>>> " + rowCountAcc.value)
val outputDf = batchDf
outputDf.write
.format("console")
.mode("append")
.save()
})
.start()
.awaitTermination()
StreamingQueryListener:
class EventMetric extends StreamingQueryListener{
override def onQueryStarted(event: QueryStartedEvent): Unit = {
}
override def onQueryProgress(event: QueryProgressEvent): Unit = {
val p = event.progress
// println("id : " + p.id)
println("runId : " + p.runId)
// println("name : " + p.name)
println("batchid : " + p.batchId)
println("timestamp : " + p.timestamp)
println("triggerExecution" + p.durationMs.get("triggerExecution"))
println(p.eventTime)
println("inputRowsPerSecond : " + p.inputRowsPerSecond)
println("numInputRows : " + p.numInputRows)
println("processedRowsPerSecond : " + p.processedRowsPerSecond)
println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
}
override def onQueryTerminated(event: QueryTerminatedEvent): Unit = {
}
}
产出1:
runId : bc7f97c1-687f-4125-806a-dc573e006dcd
batchid : 164
timestamp : 2020-12-12T12:31:14.323Z
triggerExecution453
{}
inputRowsPerSecond : 625.0
numInputRows : 10
processedRowsPerSecond : 22.075055187637968
产出2:
runId : bc7f97c1-687f-4125-806a-dc573e006dcd
batchid : 168
timestamp : 2020-12-12T12:31:18.326Z
triggerExecution453
{}
inputRowsPerSecond : 666.6666666666667
numInputRows : 10
processedRowsPerSecond : 22.075055187637968
编辑:
另外,如果625是输入速率,那么为什么processedRowsPerSecond对于这个实际上没有进行转换的作业来说如此之低
UPDATE::使用漂亮的JSON输出: 第1批:
runId : 16c82066-dea0-4e0d-8a1e-ad1df55ad516
batchid : 198
timestamp : 2020-12-13T16:23:14.331Z
triggerExecution422
{}
inputRowsPerSecond : 666.6666666666667
numInputRows : 10
processedRowsPerSecond : 23.696682464454977
json : {
"id" : "f8af5400-533c-4f7f-8b01-b365dc736735",
"runId" : "16c82066-dea0-4e0d-8a1e-ad1df55ad516",
"name" : null,
"timestamp" : "2020-12-13T16:23:14.331Z",
"batchId" : 198,
"numInputRows" : 10,
"inputRowsPerSecond" : 666.6666666666667,
"processedRowsPerSecond" : 23.696682464454977,
"durationMs" : {
"addBatch" : 47,
"getBatch" : 0,
"getEndOffset" : 0,
"queryPlanning" : 0,
"setOffsetRange" : 0,
"triggerExecution" : 422,
"walCommit" : 234
},
"stateOperators" : [ ],
"sources" : [ {
"description" : "RateStreamV2[rowsPerSecond=10, rampUpTimeSeconds=0, numPartitions=1",
"startOffset" : 212599,
"endOffset" : 212600,
"numInputRows" : 10,
"inputRowsPerSecond" : 666.6666666666667,
"processedRowsPerSecond" : 23.696682464454977
} ],
"sink" : {
"description" : "ForeachBatchSink"
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
第2批:
runId : 16c82066-dea0-4e0d-8a1e-ad1df55ad516
batchid : 191
timestamp : 2020-12-13T16:23:07.328Z
triggerExecution421
{}
inputRowsPerSecond : 625.0
numInputRows : 10
processedRowsPerSecond : 23.752969121140143
json : {
"id" : "f8af5400-533c-4f7f-8b01-b365dc736735",
"runId" : "16c82066-dea0-4e0d-8a1e-ad1df55ad516",
"name" : null,
"timestamp" : "2020-12-13T16:23:07.328Z",
"batchId" : 191,
"numInputRows" : 10,
"inputRowsPerSecond" : 625.0,
"processedRowsPerSecond" : 23.752969121140143,
"durationMs" : {
"addBatch" : 62,
"getBatch" : 0,
"getEndOffset" : 0,
"queryPlanning" : 16,
"setOffsetRange" : 0,
"triggerExecution" : 421,
"walCommit" : 187
},
"stateOperators" : [ ],
"sources" : [ {
"description" : "RateStreamV2[rowsPerSecond=10, rampUpTimeSeconds=0, numPartitions=1",
"startOffset" : 212592,
"endOffset" : 212593,
"numInputRows" : 10,
"inputRowsPerSecond" : 625.0,
"processedRowsPerSecond" : 23.752969121140143
} ],
"sink" : {
"description" : "ForeachBatchSink"
}
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
请记住,每秒生成10行并不能说明整个流式查询中的输入速率
在writeStream
调用中,您没有设置Trigger
,这意味着流式查询在完成且新数据可用时被触发
现在,流式查询显然不需要整秒钟来读取这10秒钟,而是需要一小部分时间。“inputRowsPerSecond”更像是对读取输入数据速度的测量。由于四舍五入,您可以在不同批次中看到不同的值。检查输出中的“timestamp”字段,它不完全是1秒,但通常是+-几毫秒
作业读取数据只需要几毫秒的时间,不同批次的数据略有不同。在第164批中,作业需要16毫秒,在第168批中,读取10条消息需要15毫秒
Batch 164 => 10 / 0,016sec = 625 messages per second
Batch 168 => 10 / 0,015ses = 666.6667 messages per second
processedRowsPerSecond
是基于triggerExecution
1000 / triggerExecution x 10msg = 1000 / 421 x 10msg = 23.752969
解释得太多了。您还可以解释一下我在上面编辑的问题中的查询吗?我需要查看其他基于时间的度量。但我假设这个指标更多的是对实际吞吐量的衡量。由于只生成了10条消息,这个数字相当低。我不知道计算这个值的精确分母是什么。进度。eventTime映射打印为空。您还需要指定什么其他基于时间的指标?如果您打印出类似
p.json.pretty
(可能没有pretty)或event.json
,我将得到该输出。我用JSON编辑了这篇文章。请查收。