Skip to content

Commit f5e42cd

Browse files
SimonUngemichaelklishin
authored andcommitted
Better variable names, and comments
1 parent 15f1da0 commit f5e42cd

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
@@ -824,10 +824,9 @@ terminate(_Reason,
824824
rabbit_global_counters:consumer_deleted(amqp091)
825825
end, CM),
826826
rabbit_core_metrics:channel_closed(self()),
827-
CMSize = maps:size(CM),
828827
rabbit_event:notify(channel_closed, [{pid, self()},
829828
{user_who_performed_action, Username},
830-
{consumer_count, CMSize}]),
829+
{consumer_count, maps:size(CM)}]),
831830
case rabbit_confirms:size(State#ch.unconfirmed) of
832831
0 -> ok;
833832
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.
@@ -140,8 +140,12 @@ delete_samples(Table, Id, Intervals) ->
140140
[ets:delete(Table, {Id, I}) || I <- Intervals],
141141
ok.
142142

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

0 commit comments

Comments
 (0)