Skip to content

Commit

Permalink
fix: fix that the publish rate does not respect the setting
Browse files Browse the repository at this point in the history
  • Loading branch information
lafirest committed Jul 5, 2022
1 parent 5a43f75 commit 95b308e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/emqtt_bench.erl
Original file line number Diff line number Diff line change
Expand Up @@ -645,18 +645,25 @@ loop(Parent, N, Client, PubSub, Opts) ->
end.

put_publish_begin_time() ->
NowT = erlang:monotonic_time(millisecond),
put(last_publish_ts, NowT),
case get(last_publish_ts) of
undefined ->
NowT = erlang:monotonic_time(millisecond),
put(last_publish_ts, NowT);
_ ->
ok
end,
ok.

next_publish(Opts) ->
inc_counter(pub),
BeginTime = get(last_publish_ts),
PubCnt = get_counter(pub),
Interval = proplists:get_value(interval_of_msg, Opts),
LastT = get(last_publish_ts),
NextTime = BeginTime + PubCnt * Interval,
NowT = erlang:monotonic_time(millisecond),
Spent = NowT - LastT,
Remain = Interval - Spent,
Remain = NextTime - NowT,
Interval > 0 andalso Remain < 0 andalso inc_counter(pub_overrun),
inc_counter(pub),

case Remain > 0 of
true -> _ = erlang:send_after(Remain, self(), publish);
false -> self() ! publish
Expand Down

0 comments on commit 95b308e

Please sign in to comment.