diff options
| author | Matthias Radestock <matthias@lshift.net> | 2008-12-23 10:26:23 +0000 |
|---|---|---|
| committer | Matthias Radestock <matthias@lshift.net> | 2008-12-23 10:26:23 +0000 |
| commit | 683e77b06c313bec5eaa236a277951801aab77c3 (patch) | |
| tree | dffc64b939b8247d42d586c5ae8c9ea17a4abc06 | |
| parent | 7782a2074de06a6024373f86c505e61aebc4d08e (diff) | |
| download | rabbitmq-server-git-683e77b06c313bec5eaa236a277951801aab77c3.tar.gz | |
ensure fairness
| -rw-r--r-- | src/rabbit_limiter.erl | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/rabbit_limiter.erl b/src/rabbit_limiter.erl index 257950b32d..7ca9772bec 100644 --- a/src/rabbit_limiter.erl +++ b/src/rabbit_limiter.erl @@ -129,8 +129,17 @@ remember_queue(QPid, State = #lim{queues = Queues}) -> end. forget_queues(State = #lim{ch_pid = ChPid, queues = Queues}) -> - ok = dict:fold(fun(Q, Ref, ok) -> - true = erlang:demonitor(Ref), - rabbit_amqqueue:unblock(Q, ChPid) - end, ok, Queues), + QList = dict:to_list(Queues), + case length(QList) of + 0 -> ok; + L -> + %% We randomly vary the position in which each queue + %% appears in the list, thus ensuring that each queue has + %% an equal chance of being notified first. + {L1, L2} = lists:split(random:uniform(L), QList), + [begin + true = erlang:demonitor(Ref), + ok = rabbit_amqqueue:unblock(Q, ChPid) + end || {Q, Ref} <- L2 ++ L1] + end, State#lim{queues = dict:new()}. |
