Skip to content

Commit a64f393

Browse files
SimonUngemergify[bot]
authored andcommitted
Better variable names, and comments
(cherry picked from commit 3044201)
1 parent fa21f28 commit a64f393

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

deps/rabbit/src/rabbit_channel.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,10 +831,9 @@ terminate(_Reason,
831831
rabbit_global_counters:consumer_deleted(amqp091)
832832
end, CM),
833833
rabbit_core_metrics:channel_closed(self()),
834-
CMSize = maps:size(CM),
835834
rabbit_event:notify(channel_closed, [{pid, self()},
836835
{user_who_performed_action, Username},
837-
{consumer_count, CMSize}]),
836+
{consumer_count, maps:size(CM)}]),
838837
case rabbit_confirms:size(State#ch.unconfirmed) of
839838
0 -> ok;
840839
NumConfirms ->

deps/rabbitmq_management_agent/src/rabbit_mgmt_metrics_gc.erl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ handle_cast({event, #event{type = connection_closed, props = Props}},
4444
handle_cast({event, #event{type = channel_closed, props = Props}},
4545
State = #state{basic_i = BIntervals}) ->
4646
Pid = pget(pid, Props),
47-
CMCount = pget(consumer_count, Props),
48-
remove_channel(Pid, CMCount, BIntervals),
47+
ConsumerCount = pget(consumer_count, Props),
48+
remove_channel(Pid, ConsumerCount, BIntervals),
4949
{noreply, State};
5050
handle_cast({event, #event{type = consumer_deleted, props = Props}}, State) ->
5151
remove_consumer(Props),
@@ -85,13 +85,13 @@ remove_connection(Id, BIntervals) ->
8585
delete_samples(connection_stats_coarse_conn_stats, Id, BIntervals),
8686
ok.
8787

88-
remove_channel(Id, CMCount, BIntervals) ->
88+
remove_channel(Id, ConsumerCount, BIntervals) ->
8989
ets:delete(channel_created_stats, Id),
9090
ets:delete(channel_stats, Id),
9191
delete_samples(channel_process_stats, Id, BIntervals),
9292
delete_samples(channel_stats_fine_stats, Id, BIntervals),
9393
delete_samples(channel_stats_deliver_stats, Id, BIntervals),
94-
index_delete(consumer_stats, {channel, CMCount}, Id),
94+
index_delete(consumer_stats, {channel, ConsumerCount}, Id),
9595
index_delete(channel_exchange_stats_fine_stats, channel, Id),
9696
index_delete(channel_queue_stats_deliver_stats, channel, Id),
9797
ok.
@@ -139,8 +139,12 @@ delete_samples(Table, Id, Intervals) ->
139139
[ets:delete(Table, {Id, I}) || I <- Intervals],
140140
ok.
141141

142-
index_delete(consumer_stats = Table, {channel = Type, Count}, Id) ->
143-
case Count > ?LARGE_CONSUMER_COUNT of
142+
index_delete(consumer_stats = Table, {channel = Type, ConsumerCount}, Id) ->
143+
%% In case of very large amount of consumers on a single channel,
144+
%% we use the more memoroy costly bulk operation `ets:match_delete` to reduce
145+
%% CPU load. For the more common case, few consumers per channel, we loop
146+
%% through the consumers and remove them one by one
147+
case ConsumerCount > ?LARGE_CONSUMER_COUNT of
144148
true ->
145149
IndexTable = rabbit_mgmt_metrics_collector:index_table(Table, Type),
146150
MatchPattern = {'_', Id, '_'},

0 commit comments

Comments
 (0)