22
22
23
23
-define (QUEUE , lqueue ).
24
24
25
- -define (UNSENT_MESSAGE_LIMIT , 200 ).
25
+ -define (KEY_UNSENT_MESSAGE_LIMIT , classic_queue_consumer_unsent_message_limit ).
26
+ -define (DEFAULT_UNSENT_MESSAGE_LIMIT , 200 ).
26
27
27
28
% % Utilisation average calculations are all in μs.
28
29
-define (USE_AVG_HALF_LIFE , 1000000.0 ).
72
73
73
74
-spec new () -> state ().
74
75
75
- new () -> # state {consumers = priority_queue :new (),
76
- use = {active ,
77
- erlang :monotonic_time (micro_seconds ),
78
- 1.0 }}.
76
+ new () ->
77
+ Val = application :get_env (rabbit ,
78
+ ? KEY_UNSENT_MESSAGE_LIMIT ,
79
+ ? DEFAULT_UNSENT_MESSAGE_LIMIT ),
80
+ persistent_term :put (? KEY_UNSENT_MESSAGE_LIMIT , Val ),
81
+ # state {consumers = priority_queue :new (),
82
+ use = {active ,
83
+ erlang :monotonic_time (microsecond ),
84
+ 1.0 }}.
79
85
80
86
-spec max_active_priority (state ()) -> integer () | 'infinity' | 'empty' .
81
87
@@ -286,7 +292,6 @@ deliver_to_consumer(FetchFun,
286
292
E = {ChPid , Consumer = # consumer {tag = CTag }},
287
293
QName ) ->
288
294
C = # cr {link_states = LinkStates } = lookup_ch (ChPid ),
289
- ChBlocked = is_ch_blocked (C ),
290
295
case LinkStates of
291
296
#{CTag := # link_state {delivery_count = DeliveryCount0 ,
292
297
credit = Credit } = LinkState0 } ->
@@ -308,22 +313,24 @@ deliver_to_consumer(FetchFun,
308
313
block_consumer (C , E ),
309
314
undelivered
310
315
end ;
311
- _ when ChBlocked ->
312
- % % not a link credit consumer, use credit flow
313
- block_consumer (C , E ),
314
- undelivered ;
315
316
_ ->
316
317
% % not a link credit consumer, use credit flow
317
- case rabbit_limiter :can_send (C # cr .limiter ,
318
- Consumer # consumer .ack_required ,
319
- CTag ) of
320
- {suspend , Limiter } ->
321
- block_consumer (C # cr {limiter = Limiter }, E ),
318
+ case is_ch_blocked (C ) of
319
+ true ->
320
+ block_consumer (C , E ),
322
321
undelivered ;
323
- {continue , Limiter } ->
324
- {delivered , deliver_to_consumer (
325
- FetchFun , Consumer ,
326
- C # cr {limiter = Limiter }, QName )}
322
+ false ->
323
+ case rabbit_limiter :can_send (C # cr .limiter ,
324
+ Consumer # consumer .ack_required ,
325
+ CTag ) of
326
+ {suspend , Limiter } ->
327
+ block_consumer (C # cr {limiter = Limiter }, E ),
328
+ undelivered ;
329
+ {continue , Limiter } ->
330
+ {delivered , deliver_to_consumer (
331
+ FetchFun , Consumer ,
332
+ C # cr {limiter = Limiter }, QName )}
333
+ end
327
334
end
328
335
end .
329
336
@@ -653,7 +660,8 @@ block_consumer(C = #cr{blocked_consumers = Blocked}, QEntry) ->
653
660
update_ch_record (C # cr {blocked_consumers = add_consumer (QEntry , Blocked )}).
654
661
655
662
is_ch_blocked (# cr {unsent_message_count = Count , limiter = Limiter }) ->
656
- Count >= ? UNSENT_MESSAGE_LIMIT orelse rabbit_limiter :is_suspended (Limiter ).
663
+ UnsentMessageLimit = persistent_term :get (? KEY_UNSENT_MESSAGE_LIMIT ),
664
+ Count >= UnsentMessageLimit orelse rabbit_limiter :is_suspended (Limiter ).
657
665
658
666
tags (CList ) -> [CTag || {_P , {_ChPid , # consumer {tag = CTag }}} <- CList ].
659
667
0 commit comments