Apache Kafka - linger.ms and batch.size settings

Vivek Agarwal picture Vivek Agarwal · Jul 25, 2018 · Viewed 13.6k times · Source

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?

Answer

dossani picture dossani · Jul 25, 2018

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

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

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

Hope it helps.

Thanks.