本文介绍了Apache Kafka - linger.ms 和 batch.size 设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 kafka 生产者设置中,如果您将 linger.ms 设置为 0 和一个非零的 batch.size,预期的行为是什么?生产者在发送消息之前等待达到 batch.size 需要多长时间?它会一直等待直到消息的大小小于指定的批处理大小或由于 linger.ms 为零,它不会进行任何批处理而只发送每个请求?

In kafka producer settings, what is the expected behavior if you have linger.ms set to 0 and a non zero batch.size? How long will the producer wait for batch.size to be reached before sending the messages?Will it wait forever till the size of messages is less than specified batch size OR since linger.ms is zero, it will not do any batching and just send every request?

推荐答案

不,这并不意味着生产者会等待批次变得饱满.生产商将发送半满批次,甚至只发送一个批次在他们的消息.

No, this does not mean that the producer will wait for the batch tobecome full. The producer will send half-full batches and even batches with just a singlemessage in them.

因此,将batch size设置的过大不会造成延迟在发送消息时;它只会为批次使用更多内存.设置批次尺寸太小会增加一些开销,因为生产者需要发送消息更频繁.

Therefore, setting the batch size too large will not cause delaysin sending messages; it will just use more memory for the batches. Setting the batchsize too small will add some overhead because the producer will need to send messagesmore frequently.

默认情况下(linger.ms=0),生产者将只要有可用的发件人线程发送消息,即使批处理中只有一条消息.

By default (linger.ms=0), the producer willsend messages as soon as there is a sender thread available to send them, even ifthere’s just one message in the batch.

希望有帮助.

谢谢.

这篇关于Apache Kafka - linger.ms 和 batch.size 设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 01:08