简体   繁体   English

创建数千个 Kafka 主题不会出错

[英]Creating thousands of Kafka topics stops without error

I've recently written an application that connects to running Kafka instance and creates multiple topics on-demand via rest endpoint in the loop.我最近编写了一个应用程序,它连接到正在运行的 Kafka 实例,并通过循环中的 rest 端点按需创建多个主题。 I'm logging every 'create topic' call, and it tends to be extremely fast (like 100 ms to delegate creation of 10k topics).我正在记录每个“创建主题”调用,它往往非常快(比如 100 毫秒来委派创建 10k 个主题)。 Then processing on Kafka's side starts, lasts for several dozen seconds, and suddenly stops without any error.然后Kafka这边的处理开始,持续了几十秒,然后突然停止,没有任何错误。 Listing data directory shows that Kafka created like 2.5k directories, while the delegation was for 10k.列出数据目录显示 Kafka 创建了 2.5k 目录,而委托是 10k。 The following endpoint call also makes a similar number of topics.以下端点调用也产生了类似数量的主题。

An increasing number of Kafka instances doesn't change results (also, switching to Kafka without a zookeeper gives the same results).越来越多的 Kafka 实例不会改变结果(同样,在没有 zookeeper 的情况下切换到 Kafka 会产生相同的结果)。 What am I doing wrong?我究竟做错了什么? Is that an OS limitation with creating directories (syslog empty)?这是创建目录的操作系统限制(系统日志为空)吗?

Yeah, I know that Kafka is not created for handling many topics, but as far as I know, it should handle at least 100k~ (and more than a few million using zookeeper-less KRaft).是的,我知道 Kafka 不是为处理许多主题而创建的,但据我所知,它应该至少可以处理 100k 〜(使用 zookeeper-less 的 KRaft 超过几百万)。

My setup:我的设置:

  • kafka-clients 3.0.0 embedded in springboot app, execution via AdminClient.createTopics嵌入springboot应用程序的kafka-clients 3.0.0,通过AdminClient.createTopics执行
  • docker-compose with Kafka and Zookeeper: docker-compose 与 Kafka 和 Zookeeper:
version: '3.5'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka-1:
    image: wurstmeister/kafka
    ports:
      - "9092:9092"
    environment:
      DOCKER_API_VERSION: 1.22
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

I'm doing this kinda stupid:我这样做有点愚蠢:

for (int i = 0; i < 10_000; i++) {
   adminClient.createTopics(List.of(new NewTopic(UUID.randomUUID().toString(), 1, (short) 1)));
}

When I make a collection first, and then delegate creation, it succeeds, but still - what if I would do it record by record, endpoint by endpoint?当我先创建一个集合,然后委托创建时,它会成功,但仍然 - 如果我要逐个记录、逐个端点地进行记录呢?

Well, there are limitations depending on your setup-- a number of brokers/zookeepers, configuration, hardware, and operating system.嗯,有一些限制取决于您的设置——许多代理/动物园管理员、配置、硬件和操作系统。 For OS limitation, see https://kafka.apache.org/documentation/#os .有关操作系统限制,请参阅https://kafka.apache.org/documentation/#os

You could see from this apache-kafka-supports-200k-partitions-per-cluster blog post how they set up a cluster to support that 200k topic partitions.您可以从这篇apache-kafka-supports-200k-partitions-per-cluster博客文章中看到他们如何设置集群以支持 200k 主题分区。

At that time(Kafka 1.1.0), here is what they recommended当时(Kafka 1.1.0),这是他们推荐的

we recommend each broker to have up to 4,000 partitions and each cluster to have up to 200,000 partitions.我们建议每个代理最多有 4,000 个分区,每个集群最多有 200,000 个分区。

But for Kafka 2.8.0, from the the Kafka The Definitive Guide 2nd Edition但对于 Kafka 2.8.0,来自Kafka The Definitive Guide 2nd Edition

Currently, in a well-configured environment, it is recommended to not have more than 14,000 partitions per broker and 1 million replicas per cluster.目前,在配置良好的环境中,建议每个代理不超过 14,000 个分区,每个集群不超过 100 万个副本。

Though, from your comment虽然,从你的评论

I'm logging every 'create topic' call, and it tends to be extremely fast (like 100 ms to delegate creation of 10k topics).我正在记录每个“创建主题”调用,它往往非常快(比如 100 毫秒来委派创建 10k 个主题)。

I don't think that Kafka actually creates 10k topics within 100ms.我不认为 Kafka 实际上会在 100 毫秒内创建 10k 个主题。 From what I found from my experiment(of course, I'm trying to set up a cluster to handle more than 100k partitions), I create my own producer client in C++ using librdkafka.从我的实验中发现(当然,我正在尝试建立一个集群来处理超过 10 万个分区),我使用 librdkafka 在 C++ 中创建了自己的生产者客户端。 The producer is asynchronous based.生产者是基于异步的。 I could easily submit a message to not yet existing 10K topics to enforce topic creation.我可以轻松地向尚不存在的 10K 主题提交消息以强制创建主题。 But It would take some time to actually get a successful ACK from the broker.但是实际上从代理那里获得成功的 ACK 需要一些时间。 And the more online partitions in the cluster, the more time you may have to wait for the successful ACK.并且集群中的在线分区越多,您等待成功 ACK 的时间可能就越多。

I would recommend you equip your Kafka cluster with a monitoring tool so you could see the health of your setup in real time (if your cluster is not too busy).我建议您为您的 Kafka 集群配备一个监控工具,以便您可以实时查看设置的运行状况(如果您的集群不太忙)。

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

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