简体   繁体   English

同一 Kafka 主题的多个 Flink 管道

[英]Multiple Flink pipelines for the same Kafka topic

Background背景

We have a Kafka topic with a steady stream of data.我们有一个具有稳定 stream 数据的 Kafka 主题。 To process it we have a stateless Flink pipeline that consumes that topic and writes to another topic.为了处理它,我们有一个无状态的 Flink 管道,它使用该主题并写入另一个主题。

From time to time we have bursts of information that our Flink is not configured to handle.有时我们会收到大量信息,我们的 Flink 未配置为处理这些信息。 We don't want to configure our Flink pipeline and cluster to always support the maximum load we can have, we want to dynamically scale according to the load.我们不想将 Flink 管道和集群配置为始终支持我们可以拥有的最大负载,我们希望根据负载动态扩展。 (budget reasons $$$) (预算原因 $$$)

Solutions we thought of我们想到的解决方案

One way to do so is to add/remove nodes to the Flink cluster and change the parallelism of the Flink pipeline operators.一种方法是向 Flink 集群添加/删除节点并更改 Flink 管道操作符的并行度。 This will require stopping the Flink job with a snapshot, reconfiguring the parallelism and restarting with new parallelism.这将需要使用快照停止 Flink 作业,重新配置并行度并使用新的并行度重新启动。

This would be great but we cannot allow ourselves the downtime it produces.这会很棒,但我们不能允许自己出现它产生的停机时间。 We have to scale up/down without downtime.我们必须在不停机的情况下扩大/缩小规模。

If we would use regular Kafka consumers it would be as simple as adding a consumer (assuming we have enough Kafka partitions) and Kafka would redistribute the topic partitions between all the consumers.如果我们使用常规的 Kafka 消费者,那么就像添加消费者一样简单(假设我们有足够的 Kafka 分区),并且 Kafka 会在所有消费者之间重新分配主题分区。

The Flink Kafka consumer manages the partition assignment and the offset on its own which allows exactly-once semantics (we don't need it). Flink Kafka 消费者自己管理分区分配和偏移量,这允许精确一次语义(我们不需要它)。 The drawback is that a single Flink job always uses all the topic partitions.缺点是单个 Flink 作业总是使用所有主题分区。

We thought we could create another instance of Flink that would subscribe to the same topic with the same group and let Kafka distribute the partitions between them.我们认为我们可以创建另一个 Flink 实例,该实例将订阅同一组的同一主题,并让 Kafka 在它们之间分配分区。 But for that we would need the Kafka Flink consumer to let Kafka manage which partitions are assigned to which consumer.但是为此,我们需要 Kafka Flink 消费者来让 Kafka 管理哪些分区分配给哪个消费者。

What are we looking for我们在找什么

We couldn't find a library that contains such a consumer or a configuration in the existing consumer.我们在现有消费者中找不到包含此类消费者或配置的库。 We could write it on our own (not so difficult) but if there is an existing solution we'd rather use it.我们可以自己编写它(不是那么难),但如果有现有的解决方案,我们宁愿使用它。

Are we missing something?我们错过了什么吗? Are we misunderstanding something?我们是不是误会了什么? Is there a better solution?有更好的解决方案吗?

Thanks!谢谢!

The most straightforward approach, since you said that at worst you'll need double the capacity, would be to modify your topology to be able to write Kafka messages you can't process quickly enough to a second overflow Kafka topic.最直接的方法,因为您说最坏的情况下您需要双倍的容量,因此修改您的拓扑以能够将您无法快速处理的 Kafka 消息写入第二个溢出的 Kafka 主题。 Both input and output Kafka topic names would be configurable.输入和 output Kafka 主题名称都是可配置的。 Maybe you would have a threshold backlog delay that automatically triggers this writing or maybe you would have a flag in the topology that you can externally set while the topology is running.也许您会有一个阈值积压延迟来自动触发此写入,或者您可能会在拓扑中拥有一个标志,您可以在拓扑运行时从外部设置该标志。 That's a design detail you can work through that has operational implications.这是一个您可以解决的设计细节,它具有运营意义。

This gives you a Flink topology that can handle some maximum number of messages in a timely fashion while writing the rest of the messages that can't be handled to a second Kafka topic.这为您提供了一个 Flink 拓扑,可以及时处理最大数量的消息,同时将无法处理的消息的 rest 写入第二个 Kafka 主题。 You can then run a second instance of the same Flink topology that reads from that secondary topic and writes, if necessary to a third topic.然后,您可以运行相同 Flink 拓扑的第二个实例,该实例从该次要主题读取并在必要时写入第三个主题。 If the writing to the overflow topic happens very early in the topology processing, you could chain several of these instances together via Kafka with minimal latency and without having to reconfigure and restart any topologies.如果溢出主题的写入发生在拓扑处理的早期,您可以通过 Kafka 以最小的延迟将这些实例中的几个链接在一起,而无需重新配置和重新启动任何拓扑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM