Skip to content

fix: do not linger unless writing to disk - #106

Merged
zmstone merged 1 commit into
kafka4beam:mainfrom
zmstone:251103-do-not-linger-when-replayq-in-memory-mode
Nov 3, 2025
Merged

fix: do not linger unless writing to disk#106
zmstone merged 1 commit into
kafka4beam:mainfrom
zmstone:251103-do-not-linger-when-replayq-in-memory-mode

Conversation

@zmstone

@zmstone zmstone commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@zmstone
zmstone merged commit fbfb068 into kafka4beam:main Nov 3, 2025
4 checks passed
@zmstone
zmstone deleted the 251103-do-not-linger-when-replayq-in-memory-mode branch November 3, 2025 21:02
Comment thread src/wolff_producer.erl
case Bytes < MaxLingerBytes of
is_linger_continue(#{config := #{max_linger_ms := 0}}) ->
false;
is_linger_continue(#{calls := Calls, config := Config, replayq := Q}) ->

@kiliangrashoff kiliangrashoff Nov 7, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zmstone thanks for implementing this, I think it will help us to get faster PUBACKs when using the EMQX Cloud Kafka integration with hybrid buffer mode and max_linger_ms set to a non-0 value.

I see that is_writing_to_disk will return true when the tail segments are written to disk in offload mode. I am afraid that this will cause PUBACK latency to increase due to linger before append when Kafka is unavailable. Would it be possible to also skip linger before append when replayq offloads to disk? I think should not be necessary to linger when offload mode writes to disk: append should still write to memory, but tail elements are written to disk, which should allow batching disk writes.

An additional question: we need our messages to Kafka to be batched to avoid increasing load on our Kafka cluster. Will all messages that are queued during a timeframe of max_linger_ms still be batched into a single message at the popping end of the queue, or does this change cause the producer to send messages to Kafka more frequently? The desired behavior for us is that in hybrid mode the producer still lingers, but after enqueueing the messages, decoupling PUBACK latency from kafka message batching.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kiliangrashoff

For EMQX, PUBACK latency increase to cause back-pressure towards MQTT client, otherwise the memory part will eventually overflow.

For Kafka load:
There are other ways to throttle requests towards Kafka.
The most effective is to lower the send-ahead counter.
EMQX has this config named "Max Inflight" from the UI and max_inflight in config file.
The default value is 10, if you lower to 1, there is only going to be 1 request sent to Kafka before Kafka acknowledges. Hence the pending ones will effectively linger (and form a larger batch).

The unconditional linger will add unnecessary latency even when Kafka and Kafka clients are both idling.

It's like the 40m delay of TCP stack without NO_DELAY flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants