Skip to content

Commit

Permalink
Use sets v2 for better performance
Browse files Browse the repository at this point in the history
This doubles the publish rate using the repro steps from
#5312
and somewhat reduces the memory usage.

```
rabbitmqctl -n rabbit-0 set_policy --apply-to queues ha "cmq.*" '{"ha-mode":"exactly", "ha-params": 3, "ha-sync-mode": "automatic"}'

$ perf-test -ad false -f persistent -qa x-dead-letter-exchange=,x-dead-letter-routing-key=cmq-dlq,x-queue-master-locator=client-local,x-queue-version=1 -x 4 -y 0 -s 1000 -C 250000 -u cmq-input-v1
BEFORE: id: test-164723-973, sending rate avg: 6156 msg/s
AFTER: id: test-165708-401, sending rate avg: 11572 msg/s

$ perf-test -ad false -f persistent -qa x-dead-letter-exchange=,x-dead-letter-routing-key=cmq-dlq,x-queue-master-locator=client-local,x-queue-version=1,x-queue-mode=lazy -x 4 -y 0 -s 1000 -C 250000 -u cmq-input-v1lazy
BEFORE: id: test-165020-228, sending rate avg: 6239 msg/s
AFTER: id: test-165848-489, sending rate avg: 11758 msg/s

$ perf-test -ad false -f persistent -qa x-dead-letter-exchange=,x-dead-letter-routing-key=cmq-dlq,x-queue-master-locator=client-local,x-queue-version=2 -x 4 -y 0 -s 1000 -C 250000 -u cmq-input-v2
BEFORE: id: test-165314-597, sending rate avg: 6818 msg/s
AFTER: id: test-170027-308, sending rate avg: 13891 msg/s
```
  • Loading branch information
mkuratczyk committed Nov 24, 2022
1 parent 33e2555 commit b5226c1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deps/rabbit/src/rabbit_dead_letter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ group_by_queue_and_reason(Tables) ->
ensure_xdeath_event_count(Augmented, N),
Key, SeenKeys, Acc),
{sets:add_element(Key, SeenKeys), Acc1}
end, {sets:new(), []}, Tables),
end, {sets:new([{version, 2}]), []}, Tables),
Grouped.

update_x_death_header(Info, undefined) ->
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit/src/rabbit_mirror_queue_master.erl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ init_with_existing_bq(Q0, BQ, BQS) when ?is_amqqueue(Q0) ->
backing_queue_state = BQS,
seen_status = #{},
confirmed = [],
known_senders = sets:new(),
known_senders = sets:new([{version, 2}]),
wait_timeout = rabbit_misc:get_env(rabbit, slave_wait_timeout, 15000)};
{error, Reason} ->
%% The GM can shutdown before the coordinator has started up
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit/src/rabbit_mirror_queue_slave.erl
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ maybe_enqueue_message(

get_sender_queue(ChPid, SQ) ->
case maps:find(ChPid, SQ) of
error -> {queue:new(), sets:new(), running};
error -> {queue:new(), sets:new([{version, 2}]), running};
{ok, Val} -> Val
end.

Expand Down

0 comments on commit b5226c1

Please sign in to comment.