summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-02-17 09:14:10 +0100
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2023-02-17 08:15:00 +0000
commit6e749929b532c932b9fdd53a4ea17c12a2465b2e (patch)
treec745bb1dd6985df07a641f700491ac1361706ecd
parent91dda6ffea99d62736f6050a048802320fedabab (diff)
downloadrabbitmq-server-git-mergify/bp/v3.11.x/pr-7347.tar.gz
Faster node startup with many classic queues (#7326) (#7347)mergify/bp/v3.11.x/pr-7347
* Faster node startup with many classic queues On my machines, in a test with 100k queues, node startup goes down from 4-5 minutes to roughly 1 minute. The difference will be even larger with more queues as `lists:member` gets very expensive with a long list. (cherry picked from commit 6f16e8f492d4f50b1b550fe07f353f261ad0e2f3)
-rw-r--r--deps/rabbit/src/rabbit_classic_queue.erl23
1 files changed, 19 insertions, 4 deletions
diff --git a/deps/rabbit/src/rabbit_classic_queue.erl b/deps/rabbit/src/rabbit_classic_queue.erl
index 53d2cca38b..fe93b3bb4a 100644
--- a/deps/rabbit/src/rabbit_classic_queue.erl
+++ b/deps/rabbit/src/rabbit_classic_queue.erl
@@ -136,15 +136,30 @@ recover(VHost, Queues) ->
{ok, _} ->
RecoveredQs = recover_durable_queues(lists:zip(Queues,
OrderedRecoveryTerms)),
- RecoveredNames = [amqqueue:get_name(Q) || Q <- RecoveredQs],
- FailedQueues = [Q || Q <- Queues,
- not lists:member(amqqueue:get_name(Q), RecoveredNames)],
- {RecoveredQs, FailedQueues};
+ FailedQs = find_missing_queues(Queues,RecoveredQs),
+ {RecoveredQs, FailedQs};
{error, Reason} ->
rabbit_log:error("Failed to start queue supervisor for vhost '~ts': ~s", [VHost, Reason]),
throw({error, Reason})
end.
+find_missing_queues(Q1s, Q2s) when length(Q1s) == length(Q2s)->
+ [];
+find_missing_queues(Q1s, Q2s) ->
+ find_missing_queues(lists:sort(Q1s), lists:sort(Q2s), []).
+
+find_missing_queues([], _, Acc) ->
+ Acc;
+find_missing_queues(Q1s, [], Acc) ->
+ Q1s ++ Acc;
+find_missing_queues([Q1|Rem1], [Q2|Rem2] = Q2s, Acc) ->
+ case amqqueue:get_name(Q1) == amqqueue:get_name(Q2) of
+ true ->
+ find_missing_queues(Rem1, Rem2, Acc);
+ false ->
+ find_missing_queues(Rem1, Q2s, [Q1|Acc])
+ end.
+
-spec policy_changed(amqqueue:amqqueue()) -> ok.
policy_changed(Q) ->
QPid = amqqueue:get_pid(Q),