简体   繁体   English

Kafka 1.1 多消费者群体滞后

[英]Kafka 1.1 Multiple Consumer Groups Lag

Our broker is receiving a large number of messages (about 15-30 MB/sec), and we would like to ingest these messages in real time and do some processing.我们的代理正在接收大量消息(大约 15-30 MB/秒),我们希望实时摄取这些消息并进行一些处理。 Each message is a few hundreds kB.每条消息有几百 kB。

Our processing pipelines use pools of threads, so we would like the records being ingested from a single poll to contain a large batch of messages such that our thread pools do not have to deal with processing small batches frequently and run the risk of running out of threads.我们的处理管道使用线程池,因此我们希望从单个轮询中提取的记录包含大量消息,这样我们的线程池就不必经常处理小批量处理并冒用完的风险线程。 Currently, we are controlling this by modifying fetch.min.bytes , receive.buffer.bytes , and max.partition.fetch.bytes configurations of our Kafka Consumer.目前,我们正在通过修改 Kafka Consumer 的fetch.min.bytesreceive.buffer.bytesmax.partition.fetch.bytes配置来控制这一点。

We currently do not have the capability of having a single consumer which can demux the messages to different pipelines.我们目前没有能够将消息多路分解到不同管道的单个消费者。 As such, we assign a single consumer to a pipeline and each consumer is assigned to its own group.因此,我们将单个消费者分配给管道,每个消费者都被分配到自己的组。

The problem we are having is that once we start ingesting for multiple pipelines, each having its own consumer in its own group, our ingestion rate starts to lag behind the producer.我们遇到的问题是,一旦我们开始摄取多个管道,每个管道在自己的组中都有自己的消费者,我们的摄取率就会开始落后于生产者。 What's interesting is, when we have a single pipeline running, we do not have the lag issue.有趣的是,当我们运行单个管道时,我们没有滞后问题。 Our application is for real-time or near real-time analysis, so ultimately, we would like the lag to be 0 or as close to 0 as possible.我们的应用程序用于实时或接近实时的分析,因此最终,我们希望滞后为 0 或尽可能接近于 0。

What would be the best way of configuring the consumers such that when they run in different group simultaneously, we can minimize the lags as much as possible?配置消费者的最佳方式是什么,以便当他们同时在不同的组中运行时,我们可以尽可能地减少延迟?

This probably points to a configuration issue.这可能指向配置问题。 Kafka is designed to blast data down to consumers as fast as possible, assuming the messages being consumed are still in page cache .假设被消费的消息仍在页面缓存中,Kafka 旨在尽可能快地将数据发送给消费者。 If they are not in page cache anymore, it means the messages were produced some time ago, and they now only exist on disk logs and not in page cache, then you'll definitely see a slowdown, because Kafka has to go and read the logs from disk, which is thousands of times slower than reading from memory.如果它们不再在页面缓存中,这意味着消息是前一段时间产生的,它们现在只存在于磁盘日志中而不存在于页面缓存中,那么你肯定会看到速度变慢,因为 Kafka 必须去读取从磁盘读取日志,这比从内存读取慢数千倍。

If you don't want to deal with small batches, on top of the properties you mention that you have tuned, you should also pay attention to how long your consumer polls are.如果你不想处理小批量,除了你提到的你已经调优的属性之外,你还应该注意你的消费者投票时间有多长。 Anything at 50ms or higher should be plenty. 50ms 或更高的任何东西都应该足够了。 However, I've seen clients using 1ms as the poll interval, which effectively slows down the consuming, since it doesn't allow the consumer enough time to get as much data as it could.然而,我已经看到客户端使用 1ms 作为轮询间隔,这有效地减慢了消耗,因为它不允许消费者有足够的时间来获取尽可能多的数据。

One final recommendation.最后的建议之一。 Do not execute data processing/validation on the same thread that the kafka consumer is consuming on.不要在 kafka 消费者正在消费的同一线程上执行数据处理/验证。 Sometimes, people do expensive processing on the same consumer thread, and without realizing it, slow down the consumption.有时,人们在同一个消费者线程上进行昂贵的处理,并且不知不觉地减慢了消费。 That consumer thread should simply grab the messages from Kafka, ideally not even deserialize them, just grab the bytes (or String, or whatever your serialized format is), and dump it on a thread-safe queue where it can be deserialized and processsed off-thread.该消费者线程应该简单地从 Kafka 获取消息,理想情况下甚至不反序列化它们,只需获取字节(或字符串,或任何序列化格式),并将其转储到线程安全队列中,在那里可以反序列化和处理掉-线。 That will ensure the consuming thread can poll as fast as possible, only limited by the available CPU.这将确保消费线程可以尽快轮询,仅受可用 CPU 的限制。

Finally, there's a lot of great recommendations and tips on the official Javadoc for KafkaConsumer here: https://kafka.apache.org/20/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html最后,这里有很多关于KafkaConsumer官方 Javadoc 的很好的建议和技巧: https : KafkaConsumer

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

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