improve(shared-sub): Randomise the startpoint for round-robin

This commit is contained in:
Zaiming Shi 2021-02-17 19:10:37 +01:00
parent db5ec5bbb7
commit db461179c5
1 changed files with 1 additions and 1 deletions

View File

@ -282,7 +282,7 @@ do_pick_subscriber(_Group, _Topic, hash_topic, _ClientId, SourceTopic, Count) ->
1 + erlang:phash2(SourceTopic) rem Count;
do_pick_subscriber(Group, Topic, round_robin, _ClientId, _SourceTopic, Count) ->
Rem = case erlang:get({shared_sub_round_robin, Group, Topic}) of
undefined -> 0;
undefined -> rand:uniform(Count) - 1;
N -> (N + 1) rem Count
end,
_ = erlang:put({shared_sub_round_robin, Group, Topic}, Rem),