gpt4 book ai didi

scala - 在 Spark Streaming 中,有没有办法检测批处理何时完成?

转载 作者:行者123 更新时间:2023-12-02 09:21:53 25 4
gpt4 key购买 nike

我使用 Spark 1.6.0 和 Cloudera 5.8.3。
我有一个 DStream对象和在其上定义的大量转换,

val stream = KafkaUtils.createDirectStream[...](...)
val mappedStream = stream.transform { ... }.map { ... }
mappedStream.foreachRDD { ... }
mappedStream.foreachRDD { ... }
mappedStream.map { ... }.foreachRDD { ... }

有没有办法注册最后一个 foreachRDD保证最后执行且仅当上述 foreachRDD s 执行完毕?
换句话说,当 Spark UI 显示作业已完成时 - 那就是我想要执行轻量级功能的时候。

API 中有什么东西可以让我实现这一点吗?

谢谢

最佳答案

使用流式监听器应该可以为您解决问题:

(对不起,这是一个java示例)

ssc.addStreamingListener(new JobListener());

// ...

class JobListener implements StreamingListener {

@Override
public void onBatchCompleted(StreamingListenerBatchCompleted batchCompleted) {

System.out.println("Batch completed, Total delay :" + batchCompleted.batchInfo().totalDelay().get().toString() + " ms");

}

/*

snipped other methods

*/


}

https://gist.github.com/akhld/b10dc491aad1a2007183

https://jaceklaskowski.gitbooks.io/mastering-apache-spark/content/spark-streaming/spark-streaming-streaminglisteners.html

http://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.streaming.scheduler.StreamingListener

关于scala - 在 Spark Streaming 中,有没有办法检测批处理何时完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41980447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com