gpt4 book ai didi

apache-spark - 使用 Kafka 进行 Spark 流式传输 - createDirectStream 与 createStream

转载 作者:行者123 更新时间:2023-12-03 20:52:15 27 4
gpt4 key购买 nike

我们一直在使用带有 kafka 的 spark 流,直到现在我们使用的是 createStream来自 KafkaUtils 的方法.

我们刚刚开始探索 createDirectStream喜欢它有两个原因:

1)更好/更简单的“恰好一次”语义

2) kafka topic partition 与 rdd partitions 更好的关联

我确实注意到 createDirectStream被标记为实验性的。我的问题是(对不起,如果这不是很具体):

我们是否应该探索 createDirectStream方法是否恰好一次对我们很重要?如果你们能分享你的经验,那就太棒了。我们是否冒着不得不处理可靠性等其他问题的风险?

最佳答案

直接方法的创建者 (Cody) here 有一篇很棒的、内容丰富的博文.

一般来说,阅读 Kafka 交付语义部分,最后一部分说:

So effectively Kafka guarantees at-least-once delivery by default and allows the user to implement at most once delivery by disabling retries on the producer and committing its offset prior to processing a batch of messages. Exactly-once delivery requires co-operation with the destination storage system but Kafka provides the offset which makes implementing this straight-forward.



这基本上意味着“我们至少给你一次开箱即用,如果你想要一次,那是你的”。此外,博客文章讨论了通过两种方法(直接和基于接收器,强调我的)从 Spark 获得的“恰好一次”语义的保证:

Second, understand that Spark does not guarantee exactly-once semantics for output actions. When the Spark streaming guide talks about exactly-once, it’s only referring to a given item in an RDD being included in a calculated value once, in a purely functional sense. Any side-effecting output operations (i.e. anything you do in foreachRDD to save the result) may be repeated, because any stage of the process might fail and be retried.



此外,这是 Spark 文档中关于基于接收器的处理的内容:

The first approach (Receiver based) uses Kafka’s high level API to store consumed offsets in Zookeeper. This is traditionally the way to consume data from Kafka. While this approach (in combination with write ahead logs) can ensure zero data loss (i.e. at-least once semantics), there is a small chance some records may get consumed twice under some failures.



这基本上意味着,如果您将基于 Receiver 的流与 Spark 一起使用,您可能仍然有重复的数据,以防输出转换失败,它至少是一次。

在我的项目中,我使用直接流方法,其中交付语义取决于您如何处理它们。这意味着,如果您想确保恰好一次语义,您可以将偏移量与数据一起以类似事务的方式存储,如果一个失败,另一个也失败。

我建议阅读博客文章(上面的链接)和 Delivery Semantics in the Kafka documentation page .最后,我绝对建议您研究直接流方法。

关于apache-spark - 使用 Kafka 进行 Spark 流式传输 - createDirectStream 与 createStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38468906/

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