linger.ms is a Kafka producer setting that controls how long the producer waits for additional records before sending a batch. A batch is sent when it becomes full or when the linger time expires. The default is 0 milliseconds, so the producer sends as quickly as possible, although natural batching can still occur when records arrive close together. section 6.2.1 section 8.1.3
Increasing batching for higher-throughput producers
For a producer sending more than 100 messages per second, setting linger.ms to approximately 10 milliseconds can improve throughput and latency by allowing more records to join each batch. For example, configure linger.ms=10 alongside an appropriately sized batch.size. The trade-off is that batching can add waiting time, so immediate delivery may favor the default of 0. section 6.2.1 section 6.5
Tune linger.ms together with the producer's batching and delivery settings:
- Use batch.size to set the maximum batch size in bytes; use linger.ms to set the waiting period in milliseconds. section 6.2.1
- Expect the producer to send as soon as either the batch is full or the linger interval ends. section 6.2.1
- Treat linger.ms as distinct from request.timeout.ms and delivery.timeout.ms: it delays batch formation, while the other settings govern broker responses and eventual failure. section 8.1.3
Figure 6.5 The producer batches messages for each topic and partition. A message is sent as soon as either the batch is full or the linger time is up.
Shows the producer's per-topic, per-partition batching flow and the two conditions that trigger a send. section 6.2.1
