Merge pull request #4197 from zmstone/improve-shared-sup-random-start-point-for-roundrobin
improve(shared-sub): Randomise the startpoint for round-robin
This commit is contained in:
commit
d2bd9b4078
|
@ -282,7 +282,7 @@ do_pick_subscriber(_Group, _Topic, hash_topic, _ClientId, SourceTopic, Count) ->
|
||||||
1 + erlang:phash2(SourceTopic) rem Count;
|
1 + erlang:phash2(SourceTopic) rem Count;
|
||||||
do_pick_subscriber(Group, Topic, round_robin, _ClientId, _SourceTopic, Count) ->
|
do_pick_subscriber(Group, Topic, round_robin, _ClientId, _SourceTopic, Count) ->
|
||||||
Rem = case erlang:get({shared_sub_round_robin, Group, Topic}) of
|
Rem = case erlang:get({shared_sub_round_robin, Group, Topic}) of
|
||||||
undefined -> 0;
|
undefined -> rand:uniform(Count) - 1;
|
||||||
N -> (N + 1) rem Count
|
N -> (N + 1) rem Count
|
||||||
end,
|
end,
|
||||||
_ = erlang:put({shared_sub_round_robin, Group, Topic}, Rem),
|
_ = erlang:put({shared_sub_round_robin, Group, Topic}, Rem),
|
||||||
|
|
Loading…
Reference in New Issue