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 .
@@ -136,18 +139,23 @@ delete_samples(Table, Id, Intervals) ->
136
139
[ets :delete (Table , {Id , I }) || I <- Intervals ],
137
140
ok .
138
141
139
- index_delete (consumer_stats = Table , channel = Type , Id ) ->
140
- IndexTable = rabbit_mgmt_metrics_collector :index_table (Table , Type ),
141
- MatchPattern = {'_' , Id , '_' },
142
- % % Delete consumer_stats_queue_index
143
- ets :match_delete (consumer_stats_queue_index ,
144
- {'_' , MatchPattern }),
145
- % % Delete consumer_stats
146
- ets :match_delete (consumer_stats ,
147
- {MatchPattern ,'_' }),
148
- % % Delete consumer_stats_channel_index
149
- ets :delete (IndexTable , Id ),
150
- ok ;
142
+ index_delete (consumer_stats = Table , {channel = Type , Count }, Id ) ->
143
+ case Count > ? LARGE_CONSUMER_COUNT of
144
+ true ->
145
+ IndexTable = rabbit_mgmt_metrics_collector :index_table (Table , Type ),
146
+ MatchPattern = {'_' , Id , '_' },
147
+ % % Delete consumer_stats_queue_index
148
+ ets :match_delete (consumer_stats_queue_index ,
149
+ {'_' , MatchPattern }),
150
+ % % Delete consumer_stats
151
+ ets :match_delete (consumer_stats ,
152
+ {MatchPattern ,'_' }),
153
+ % % Delete consumer_stats_channel_index
154
+ ets :delete (IndexTable , Id ),
155
+ ok ;
156
+ false ->
157
+ index_delete (Table , Type , Id )
158
+ end ;
151
159
index_delete (Table , Type , Id ) ->
152
160
IndexTable = rabbit_mgmt_metrics_collector :index_table (Table , Type ),
153
161
Keys = ets :lookup (IndexTable , Id ),
0 commit comments