fix(buffer_worker): avoid setting flush timer when inflight is full

Fixes https://emqx.atlassian.net/browse/EMQX-9902

When the buffer worker inflight window is full, we don’t need to set a
timer to flush the messages again because there’s no more room, and
one of the inflight windows will flush the buffer worker by calling
`flush_worker`.

Currently, we do set the timer on such situation, and this fact
combined with the default batch time of 0 yields a busy loop situation
where the CPU spins a lot while inflight messages do not return.
This commit is contained in:
Thales Macedo Garitezi 2023-05-16 09:45:54 -03:00
parent f876bcb97f
commit 657df05ad9
3 changed files with 3 additions and 3 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{application, emqx_resource, [ {application, emqx_resource, [
{description, "Manager for all external resources"}, {description, "Manager for all external resources"},
{vsn, "0.1.15"}, {vsn, "0.1.16"},
{registered, []}, {registered, []},
{mod, {emqx_resource_app, []}}, {mod, {emqx_resource_app, []}},
{applications, [ {applications, [

View File

@ -495,8 +495,7 @@ flush(Data0) ->
{keep_state, Data1}; {keep_state, Data1};
{_, true} -> {_, true} ->
?tp(buffer_worker_flush_but_inflight_full, #{}), ?tp(buffer_worker_flush_but_inflight_full, #{}),
Data2 = ensure_flush_timer(Data1), {keep_state, Data1};
{keep_state, Data2};
{_, false} -> {_, false} ->
?tp(buffer_worker_flush_before_pop, #{}), ?tp(buffer_worker_flush_before_pop, #{}),
{Q1, QAckRef, Batch} = replayq:pop(Q0, #{count_limit => BatchSize}), {Q1, QAckRef, Batch} = replayq:pop(Q0, #{count_limit => BatchSize}),

View File

@ -0,0 +1 @@
Fixed an issue where the buffering layer processes could use a lot of CPU when inflight window is full.