SpringBoot 批量监听模式 vs 非批量监听模式 [英] SpringBoot batch listener mode vs non-batch listener mode
问题描述
我只是好奇 Spring Kafka 中的批处理侦听器模式是否比非批处理侦听器模式提供更好的性能?如果我们正在处理异常,那么我们仍然需要在 Batch-listener 模式下处理每条记录.非批处理似乎不易出错、稳定且可定制.
I am just curious does batch listener mode in Spring Kafka gives better performance than non-batch listener mode? If we are handling exceptions then we still need to process each record in Batch-listener mode. Non-batch seems less error prone, stable and customizable .
请分享您对此的看法,因为我没有找到任何好的比较.
Please share your views on this as I didn't find any good comparison.
推荐答案
这完全取决于你的听众对数据做了什么.
It completely depends on what your listener is doing with the data.
如果它循环处理每条记录,则没有任何好处;您也可以让容器遍历集合并一次向侦听器发送一条记录.
If it processes each record in a loop then there is no benefit; you might as well just let the container iterate over the collection and send the listener one record at-a-time.
如果您将批处理作为一个整体进行处理,批处理模式将提高性能 - 例如在单个事务中使用 JDBC 批量插入.
Batch mode will improve performance if you are processing the batch as a whole - e.g. a batch insert using JDBC in a single transaction.
这通常比一次存储一条记录(为每条记录使用一个新事务)运行得更快,因为它需要更少的往返数据库服务器.
This will often run much faster than storing one record at-a-time (using a new transaction for each record) because it requires fewer round trips to the DB server.
这篇关于SpringBoot 批量监听模式 vs 非批量监听模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!