You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于Kafka linger.ms设为0的文档内容及性能影响的澄清请求

Understanding Kafka's linger.ms Configuration (0.10.2.1)

Let me break down how this setting works and clarify the official docs for you—since it’s easy to get confused by the "immediate send" wording at first glance.

What linger.ms=0 Actually Does

默认情况下,即使缓冲区还有剩余空间也可立即发送;若要减少请求数量,可将linger.ms设置为大于0的值。

The key here is that "immediate send" doesn’t mean sending every single record synchronously one-by-one to the broker. Kafka’s producer relies on an internal buffer (controlled by batch.size) to group records destined for the same partition. When linger.ms=0, the producer will dispatch the batch as soon as it has any records ready—but there’s a crucial detail:

  • If multiple records arrive at the producer extremely close in time (even microseconds apart), they’ll get bundled into the same batch before being sent. This is exactly what the docs mean by "time-wise close records are usually batched even with linger.ms=0".
  • Under high load, records pour in so quickly that the buffer fills up fast. Batches form automatically regardless of linger.ms—the producer doesn’t have time to wait, it just sends the full batch the moment it’s ready.

Why linger.ms=0 Isn’t the Same as Synchronous Sending

Synchronous sending (like calling send().get() for every single record) forces the producer to wait for a broker acknowledgment before handling the next record. With linger.ms=0, the producer still uses asynchronous batching under the hood:

  • It adds records to the buffer and triggers a send as soon as possible, but doesn’t block on each individual record.
  • Even if only one record is in the buffer, it will send it immediately—but this is still an asynchronous request (unless you explicitly block on the future). The performance hit here is way smaller than full synchronous sending because the producer isn’t waiting for a round-trip to the broker before processing the next record.

When to Use linger.ms > 0

仅在非满负载时将其设为大于0,可减少请求数、提升效率,但会增加少量延迟。

When your producer isn’t under heavy load, records might arrive sporadically. Setting linger.ms to a small value (like 5-10ms) tells the producer to wait a tiny bit longer to see if more records come in for the same partition. This lets it send multiple records in one batch instead of dozens of tiny requests, cutting down on network overhead and boosting throughput—all for a usually negligible amount of added delay per batch.

Performance Impact: linger.ms=0 vs. linger.ms > 0

  • With linger.ms=0, you might end up sending more small batches, which increases the total number of network requests. Each request has fixed overhead (TCP handshake, broker processing, etc.), so this can reduce throughput compared to using a small linger.ms value.
  • But it’s still far better than synchronous sending because the asynchronous model lets the producer keep adding records to the buffer while previous batches are being sent to the broker.

To wrap it up: linger.ms=0 doesn’t disable batching entirely—it just stops the producer from waiting on purpose to fill batches. Batching still happens naturally when records arrive close together or under high load, which is why its performance impact is much milder than full synchronous sending.

内容的提问来源于stack exchange,提问作者Aditya Vivek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:10:03