19
19
-export ([init /1 , handle_call /3 , handle_cast /2 , handle_info /2 , terminate /2 ,
20
20
code_change /3 ]).
21
21
22
+ -define (LARGE_CONSUMER_COUNT , 1000 ).
23
+
22
24
name (EventType ) ->
23
25
list_to_atom ((atom_to_list (EventType ) ++ " _metrics_gc" )).
24
26
@@ -42,7 +44,8 @@ handle_cast({event, #event{type = connection_closed, props = Props}},
42
44
handle_cast ({event , # event {type = channel_closed , props = Props }},
43
45
State = # state {basic_i = BIntervals }) ->
44
46
Pid = pget (pid , Props ),
45
- remove_channel (Pid , BIntervals ),
47
+ CMCount = pget (consumer_count , Props ),
48
+ remove_channel (Pid , CMCount , BIntervals ),
46
49
{noreply , State };
47
50
handle_cast ({event , # event {type = consumer_deleted , props = Props }}, State ) ->
48
51
remove_consumer (Props ),
@@ -82,13 +85,13 @@ remove_connection(Id, BIntervals) ->
82
85
delete_samples (connection_stats_coarse_conn_stats , Id , BIntervals ),
83
86
ok .
84
87
85
- remove_channel (Id , BIntervals ) ->
88
+ remove_channel (Id , CMCount , BIntervals ) ->
86
89
ets :delete (channel_created_stats , Id ),
87
90
ets :delete (channel_stats , Id ),
88
91
delete_samples (channel_process_stats , Id , BIntervals ),
89
92
delete_samples (channel_stats_fine_stats , Id , BIntervals ),
90
93
delete_samples (channel_stats_deliver_stats , Id , BIntervals ),
91
- index_delete (consumer_stats , channel , Id ),
94
+ index_delete (consumer_stats , { channel , CMCount } , Id ),
92
95
index_delete (channel_exchange_stats_fine_stats , channel , Id ),
93
96
index_delete (channel_queue_stats_deliver_stats , channel , Id ),
94
97
ok .
@@ -137,18 +140,23 @@ delete_samples(Table, Id, Intervals) ->
137
140
[ets :delete (Table , {Id , I }) || I <- Intervals ],
138
141
ok .
139
142
140
- index_delete (consumer_stats = Table , channel = Type , Id ) ->
141
- IndexTable = rabbit_mgmt_metrics_collector :index_table (Table , Type ),
142
- MatchPattern = {'_' , Id , '_' },
143
- % % Delete consumer_stats_queue_index
144
- ets :match_delete (consumer_stats_queue_index ,
145
- {'_' , MatchPattern }),
146
- % % Delete consumer_stats
147
- ets :match_delete (consumer_stats ,
148
- {MatchPattern ,'_' }),
149
- % % Delete consumer_stats_channel_index
150
- ets :delete (IndexTable , Id ),
151
- ok ;
143
+ index_delete (consumer_stats = Table , {channel = Type , Count }, Id ) ->
144
+ case Count > ? LARGE_CONSUMER_COUNT of
145
+ true ->
146
+ IndexTable = rabbit_mgmt_metrics_collector :index_table (Table , Type ),
147
+ MatchPattern = {'_' , Id , '_' },
148
+ % % Delete consumer_stats_queue_index
149
+ ets :match_delete (consumer_stats_queue_index ,
150
+ {'_' , MatchPattern }),
151
+ % % Delete consumer_stats
152
+ ets :match_delete (consumer_stats ,
153
+ {MatchPattern ,'_' }),
154
+ % % Delete consumer_stats_channel_index
155
+ ets :delete (IndexTable , Id ),
156
+ ok ;
157
+ false ->
158
+ index_delete (Table , Type , Id )
159
+ end ;
152
160
index_delete (Table , Type , Id ) ->
153
161
IndexTable = rabbit_mgmt_metrics_collector :index_table (Table , Type ),
154
162
Keys = ets :lookup (IndexTable , Id ),
0 commit comments