linger.ms — Kafka Producer Configuration
The producer groups together any records that arrive in between request transmissions into a single batched request. Normally this occurs only under load when records arrive faster than they can be sent out.
Description
The producer groups together any records that arrive in between request transmissions into a single batched request. Normally this occurs only under load when records arrive faster than they can be sent out. However in some circumstances the client may want to reduce the number of requests even under moderate load. This setting accomplishes this by adding a small amount of artificial delay—that is, rather than immediately sending out a record, the producer will wait for up to the given delay to allow other records to be sent so that the sends can be batched together. This can be thought of as analogous to Nagle's algorithm in TCP. This setting gives the upper bound on the delay for batching: once we get batch.size worth of records for a partition it will be sent immediately regardless of this setting, however if we have fewer than this many bytes accumulated for this partition we will 'linger' for the specified time waiting for more records to show up. This setting defaults to 0 (i.e. no delay). Setting linger.ms=5, for example, would have the effect of reducing the number of requests sent but would add up to 5ms of latency to records sent in the absence of load.
Default Values by Kafka Version
| Kafka Version | Default Value |
|---|---|
| 0.8.1 | 0 |
| 0.8.2 | 0 |
| 0.9.0 | 0 |
| 0.10.0 | 0 |
| 0.10.1 | 0 |
| 0.10.2 | 0 |
| 0.11.0 | 0 |
| 1.0 | 0 |
| 1.1 | 0 |
| 2.0 | 0 |
| 2.1 | 0 |
| 2.2 | 0 |
| 2.3 | 0 |
| 2.4 | 0 |
| 2.5 | 0 |
| 2.6 | 0 |
| 2.7 | 0 |
| 2.8 | 0 |
| 3.0 | 0 |
| 3.1 | 0 |
| 3.2 | 0 |
| 3.3 | 0 |
| 3.4 | 0 |
| 3.5 | 0 |
| 3.6 | 0 |
| 3.7 | 0 |
| 3.8 | 0 |
| 3.9 | 0 |
| 4.0 | 5 |
| 4.1 | 5 |
| 4.2 | 5 |
Tuning Recommendation
| Profile | Recommended | Why |
|---|---|---|
| producer / throughput | 20 | Allows the accumulator to wait 20ms for more records before sending, enabling batch.size to be reached and reducing the number of ProduceRequests by up to 10x under moderate load. |
| producer / latency | 0 | Setting linger.ms=0 disables accumulation wait entirely: the sender thread dispatches a ProduceRequest as soon as a record is appended to the batch, eliminating up to 5ms of forced batching delay introduced by the default since Kafka 4.0. |
Related Configs
batch.size · buffer.memory · request.timeout.ms · delivery.timeout.ms · compression.type