未使用的 Kafka 的成本 topic/partition

Cost of an unused Kafka topic/partition

在设计流处理管道时,如果我有许多主题,这些主题至少有一个分区但可能没有数据进入其中,可能会产生什么成本?

例如,对于一个消费者,我可以选择一个 "mega topic" 包含所有数据和许多分区,或者我可以选择拆分该数据(按租户、帐户或用户等) .) 进入许多主题,默认情况下,一个分区。我担心第二种情况是会有很多 topics/partitions 看不到数据。那么,这个未使用的分区是否会产生任何成本,或者未使用的主题是否会产生任何成本。

假设提到的主题没有被压缩,保留任何最初产生的数据的初始开销,但之后,一个空主题只是

  1. zookeeper 中的元数据
  2. 任何消费者组协调器中的元数据,以及任何活动消费者线程浪费的处理
  3. 磁盘上的空目录

对于前两个,拥有大量主题可能会增加请求延迟,从而导致集群不健康。

首先,一个fat topic和很多partitions和一个多topic包含几个partitions没有区别。主题只是为了事件之间的逻辑区分。 Kafka 只关心分区数。

其次,有很多分区会导致一些问题:

  • 打开的文件太多:

Each partition maps to a directory in the file system in the broker. Within that log directory, there will be two files (one for the index and another for the actual data) per log segment.

  • 更多的分区需要更多的代理和消费者内存 双方:

Brokers allocate a buffer the size of replica.fetch.max.bytes for each partition they replicate. If replica.fetch.max.bytes is set to 1 MiB, and you have 1000 partitions, about 1 GiB of RAM is required.

  • 更多分区可能会增加不可用性:

如果作为控制器的代理发生故障,则zookeeper会选择另一个代理作为控制器。届时新选出的代理应在初始化期间从 Zookeeper 读取每个分区的元数据。

For example, if there are 10,000 partitions in the Kafka cluster and initializing the metadata from ZooKeeper takes 2 ms per partition, this can add 20 more seconds to the unavailability window.

您可以从这些链接获得更多信息:
https://www.confluent.io/blog/how-choose-number-topics-partitions-kafka-cluster/ https://docs.cloudera.com/documentation/kafka/latest/topics/kafka_performance.html