linger.ms=100. The producer sends messages every 50ms. What is the expected behavior regarding message batching?producer_config = {
'linger.ms': 100
}
# Messages sent every 50ms
# How does linger.ms affect batching here?The linger.ms setting specifies the maximum time to wait before sending a batch. Even if messages arrive earlier, the producer waits up to 100ms to batch more messages. Since messages come every 50ms, they accumulate and are sent every 100ms or when the batch is full.
batch.size=16384 bytes and linger.ms=0. If the producer sends messages smaller than 1KB each rapidly, what is the expected behavior?producer_config = {
'batch.size': 16384, # 16 KB
'linger.ms': 0
}
# Messages are ~1KB each, sent rapidlyWith linger.ms=0, the producer sends messages immediately without waiting to fill the batch. Even if batch.size is large, messages are sent as soon as they are ready.
linger.ms=500 and batch.size=32768. However, messages are delayed longer than 500ms before sending. What is the most likely cause?producer_config = {
'linger.ms': 500,
'batch.size': 32768
}
# Messages are sent slowly, delays > 500ms observedThe producer waits up to linger.ms before sending a batch, but if the batch size is large and messages arrive slowly, the batch may not fill quickly. This can cause delays longer than linger.ms if the producer is configured to wait for batch filling.
batch.size to 32KB and linger.ms to 100ms in Java?In Java Kafka producer configs, keys must be strings. Values can be integers or strings. Option A uses a valid expression for 32KB and correct string keys.
Setting linger.ms to a small positive value allows the producer to wait briefly to batch messages, improving throughput without adding much latency. A moderate batch size complements this by not requiring too many messages to send a batch.