Browse Source

Merge pull request #4197 from zmstone/improve-shared-sup-random-start-point-for-roundrobin

improve(shared-sub): Randomise the startpoint for round-robin
Zaiming Shi 5 years atrás
parent
commit
d2bd9b4078
1 changed files with 1 additions and 1 deletions
  1. 1 1
      src/emqx_shared_sub.erl

+ 1 - 1
src/emqx_shared_sub.erl

@@ -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),