fix(emx_slow_updates): fix the error of topk update (#6312)

This commit is contained in:
lafirest 2021-11-26 14:57:25 +08:00 committed by GitHub
parent fef3fc27cb
commit 8dd4d88d5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -106,8 +106,10 @@ on_stats_update(#{clientid := ClientId,
%% check whether the client is in the table
case ets:lookup(?TOPK_TAB, LastIndex) of
[#top_k{index = Index}] ->
%% if last value == the new value, return
true;
%% if last value == the new value, update the type and last_update_time
%% 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, maybe it can replace the minimum value

View File

@ -95,11 +95,12 @@ call_hook(_, _, _, Latency, #{threshold := Threshold} = S)
S;
call_hook(ClientId, Now, Type, Latency, #{last_insert_value := LIV} = Stats) ->
ToInsert = erlang:floor(Latency),
Arg = #{clientid => ClientId,
latency => erlang:floor(Latency),
latency => ToInsert,
type => Type,
last_insert_value => LIV,
update_time => Now},
emqx:run_hook('message.slow_subs_stats', [Arg]),
Stats#{last_insert_value := Latency,
Stats#{last_insert_value := ToInsert,
last_access_time := Now}.