如何增加Spring Kafka Consumer每批消费的消息数?

编程入门 行业动态 更新时间:2024-10-27 10:26:20
本文介绍了如何增加Spring Kafka Consumer每批消费的消息数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在构建一个 Kafka Consumer 应用程序,该应用程序使用来自 Kafka 主题的消息并执行数据库更新任务.消息每天大批量生成一次 - 因此该主题在 10 分钟内加载了大约 100 万条消息.Topic 有 8 个分区.

I am building a Kafka Consumer application that consumes messages from a Kafka Topic and performs a database update task. The messages are produced in a large batch once every day - so the Topic has about 1 million messages loaded in 10 minutes. The Topic has 8 partitions.

Spring Kafka Consumer(使用@KafkaListener 注释并使用 ConcurrentKafkaListenerContainerFactory)在非常短的批次中触发.

The Spring Kafka Consumer (annotated with @KafkaListener and using a ConcurrentKafkaListenerContainerFactory) is triggered in very short batches.

批量大小有时只有 1 或 2 条消息.如果它可以一次消耗大约 1000 条消息并一起处理(例如,我可以在单个更新 SQL 中更新数据库),而不是为每条消息连接到数据库,这将有助于提高性能.

The batch size is sometimes just 1 or 2 messages. It would help performance if it can consume about 1000 messages at once and process it together (for example, I could update the database in a single update SQL), instead of connecting to the database for each message.

我已经尝试降低工厂中的并发性,以避免多个线程消耗较少数量的消息.

I have already tried to decrease the concurrency in the factory to avoid multiple threads consuming smaller number of messages.

我还将 Kafka 的 server.properties 中的 socket.send.buffer.bytes 属性从 102400 增加到 1024000.

I also increased the socket.send.buffer.bytes property in Kafka's server.properties to 1024000, from 102400.

这些步骤没有增加批量大小.

These steps have not increased the batch size.

我可以使用其他任何配置来增加消费者的浴缸尺寸吗?

Is there any other configuration I could use to increase the bath size of the consumer?

推荐答案

查看 kafka 消费者属性 max.poll.recordsfetch.min.bytesfetch.max.wait.msfetch.max.bytesmax.partition.fetch.bytes.

See kafka consumer properties max.poll.records, fetch.min.bytes, fetch.max.wait.ms, fetch.max.bytes, max.partition.fetch.bytes.

很可能 fetch.min.bytesfetch.max.wait.ms 正是您所需要的.

Most likely fetch.min.bytes and fetch.max.wait.ms is what you need.

这篇关于如何增加Spring Kafka Consumer每批消费的消息数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-19 12:39:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/963149.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:消息   Spring   Kafka   Consumer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!