Skip to content

Commit b3cb024

Browse files
committed
fix: do not linger unless writing to disk
1 parent f361949 commit b3cb024

4 files changed

Lines changed: 25 additions & 11 deletions

File tree

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* 4.1.1
2+
- Do not linger before enqueue when queue is not on disk.
3+
Since 4.0.0, the linger is moved from after the queue to before the queue to optimize IOPS in disk mode.
4+
This however added unnecessary delay for memory (or offload mode before disk).
5+
Now linger happens only when wirting to disk.
6+
17
* 4.1.0
28
- Fix 'failed' telemetry counter double-increment due to race condition. [#102](https://github.com/kafka4beam/wolff/pull/102)
39
- Added producer process label `{wolff_producer, KafkaClientId, Topic, Partition}` [#102](https://github.com/kafka4beam/wolff/pull/102)

rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{deps, [ {kafka_protocol, "4.3.0"}
2-
, {replayq, "0.4.1"}
2+
, {replayq, "0.5.0"}
33
, {lc, "0.3.5"}
44
, {telemetry, "1.1.0"}
55
]}.

src/wolff_producer.erl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -920,13 +920,20 @@ ensure_linger_expire_timer_cancel(#{?linger_expire_timer := LTimer} = St) ->
920920
St#{?linger_expire_timer => false}.
921921

922922
%% check if the call collection should continue to linger before enqueue
923-
is_linger_continue(#{calls := Calls, config := Config}) ->
924-
#{max_linger_ms := MaxLingerMs, max_linger_bytes := MaxLingerBytes} = Config,
925-
#{ts := Ts, bytes := Bytes} = Calls,
926-
case Bytes < MaxLingerBytes of
923+
is_linger_continue(#{config := #{max_linger_ms := 0}}) ->
924+
false;
925+
is_linger_continue(#{calls := Calls, config := Config, replayq := Q}) ->
926+
case replayq:is_writing_to_disk(Q) of
927927
true ->
928-
TimeLeft = MaxLingerMs - (now_ts() - Ts),
929-
(TimeLeft > 0) andalso {true, TimeLeft};
928+
#{max_linger_ms := MaxLingerMs, max_linger_bytes := MaxLingerBytes} = Config,
929+
#{ts := Ts, bytes := Bytes} = Calls,
930+
case Bytes < MaxLingerBytes of
931+
true ->
932+
TimeLeft = MaxLingerMs - (now_ts() - Ts),
933+
(TimeLeft > 0) andalso {true, TimeLeft};
934+
false ->
935+
false
936+
end;
930937
false ->
931938
false
932939
end.

test/wolff_tests.erl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ replayq_overflow_test() ->
512512
replayq_max_total_bytes => BatchSize,
513513
required_acks => all_isr,
514514
max_linger_ms => LingerMs, %% delay enqueue
515-
max_linger_bytes => BatchSize + 1 %% delay enqueue
515+
max_linger_bytes => BatchSize + 1, %% delay enqueue
516+
replayq_dir => "test-data/overlow"
516517
},
517518
{ok, Producers} = wolff:start_producers(Client, <<"test-topic">>, ProducerCfg),
518519
Pid = wolff_producers:lookup_producer(Producers, 0),
@@ -577,7 +578,6 @@ replayq_highmem_overflow_test() ->
577578
ProducerCfg = #{max_batch_bytes => 1, %% make sure not collecting calls into one batch
578579
replayq_max_total_bytes => BatchSize*1000,
579580
required_acks => all_isr,
580-
max_linger_ms => 1000, %% do not send to kafka immediately
581581
drop_if_highmem => true
582582
},
583583
{ok, Producers} = wolff:start_producers(Client, <<"test-topic">>, ProducerCfg),
@@ -664,7 +664,7 @@ mem_only_replayq_test() ->
664664
recover_from_replayq_test() ->
665665
ClientCfg = client_config(),
666666
{ok, Client} = start_client(<<"client-2">>, ?HOSTS, ClientCfg),
667-
ProducerCfg = #{replayq_dir => "test-data-2"},
667+
ProducerCfg = #{replayq_dir => "test-data/recover"},
668668
{ok, Producers} = wolff:start_producers(Client, <<"test-topic">>, ProducerCfg),
669669
Msg = #{key => ?KEY, value => <<"value">>},
670670
{0, BaseOffset} = wolff:send_sync(Producers, [Msg], 3000),
@@ -858,7 +858,8 @@ test_batch_split_then_drop(Topic, MaxMessageBytes) ->
858858
%% ensure batching by delay enqueue by 100 seconds
859859
max_linger_ms => 100,
860860
%% ensure linger is not expired by reaching size
861-
max_linger_bytes => MaxMessageBytes * 100
861+
max_linger_bytes => MaxMessageBytes * 100,
862+
replayq_dir => "test-data/batch-split"
862863
},
863864
{ok, Producers} = wolff:start_producers(Client, TopicBin, ProducerCfg),
864865
MaxBytesCompensateOverhead = MaxMessageBytes - ?BATCHING_OVERHEAD - 7,

0 commit comments

Comments
 (0)