fix(emx_slow_updates): fix the error of topk update (#6312)
This commit is contained in:
parent
fef3fc27cb
commit
8dd4d88d5b
|
@ -106,8 +106,10 @@ on_stats_update(#{clientid := ClientId,
|
||||||
%% check whether the client is in the table
|
%% check whether the client is in the table
|
||||||
case ets:lookup(?TOPK_TAB, LastIndex) of
|
case ets:lookup(?TOPK_TAB, LastIndex) of
|
||||||
[#top_k{index = Index}] ->
|
[#top_k{index = Index}] ->
|
||||||
%% if last value == the new value, return
|
%% if last value == the new value, update the type and last_update_time
|
||||||
true;
|
%% XXX for clients whose latency are stable for a long time, is it possible to reduce updates?
|
||||||
|
ets:insert(?TOPK_TAB,
|
||||||
|
#top_k{index = Index, type = Type, last_update_time = Ts});
|
||||||
[_] ->
|
[_] ->
|
||||||
%% if Latency > minimum value, we should update it
|
%% if Latency > minimum value, we should update it
|
||||||
%% if Latency < minimum value, maybe it can replace the minimum value
|
%% if Latency < minimum value, maybe it can replace the minimum value
|
||||||
|
|
|
@ -95,11 +95,12 @@ call_hook(_, _, _, Latency, #{threshold := Threshold} = S)
|
||||||
S;
|
S;
|
||||||
|
|
||||||
call_hook(ClientId, Now, Type, Latency, #{last_insert_value := LIV} = Stats) ->
|
call_hook(ClientId, Now, Type, Latency, #{last_insert_value := LIV} = Stats) ->
|
||||||
|
ToInsert = erlang:floor(Latency),
|
||||||
Arg = #{clientid => ClientId,
|
Arg = #{clientid => ClientId,
|
||||||
latency => erlang:floor(Latency),
|
latency => ToInsert,
|
||||||
type => Type,
|
type => Type,
|
||||||
last_insert_value => LIV,
|
last_insert_value => LIV,
|
||||||
update_time => Now},
|
update_time => Now},
|
||||||
emqx:run_hook('message.slow_subs_stats', [Arg]),
|
emqx:run_hook('message.slow_subs_stats', [Arg]),
|
||||||
Stats#{last_insert_value := Latency,
|
Stats#{last_insert_value := ToInsert,
|
||||||
last_access_time := Now}.
|
last_access_time := Now}.
|
||||||
|
|
Loading…
Reference in New Issue