Skip to content

Commit 7c2d29d

Browse files
Merge pull request #11513 from rabbitmq/loic-remove-ram-durations
CQ: Remove rabbit_memory_monitor and RAM durations
2 parents f515282 + 1ca46f1 commit 7c2d29d

12 files changed

+48
-453
lines changed

deps/rabbit/app.bzl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ def all_beam_files(name = "all_beam_files"):
164164
"src/rabbit_logger_exchange_h.erl",
165165
"src/rabbit_looking_glass.erl",
166166
"src/rabbit_maintenance.erl",
167-
"src/rabbit_memory_monitor.erl",
168167
"src/rabbit_message_interceptor.erl",
169168
"src/rabbit_metrics.erl",
170169
"src/rabbit_mirror_queue_misc.erl",
@@ -424,7 +423,6 @@ def all_test_beam_files(name = "all_test_beam_files"):
424423
"src/rabbit_logger_exchange_h.erl",
425424
"src/rabbit_looking_glass.erl",
426425
"src/rabbit_maintenance.erl",
427-
"src/rabbit_memory_monitor.erl",
428426
"src/rabbit_message_interceptor.erl",
429427
"src/rabbit_metrics.erl",
430428
"src/rabbit_mirror_queue_misc.erl",
@@ -703,7 +701,6 @@ def all_srcs(name = "all_srcs"):
703701
"src/rabbit_logger_exchange_h.erl",
704702
"src/rabbit_looking_glass.erl",
705703
"src/rabbit_maintenance.erl",
706-
"src/rabbit_memory_monitor.erl",
707704
"src/rabbit_message_interceptor.erl",
708705
"src/rabbit_metrics.erl",
709706
"src/rabbit_mirror_queue_misc.erl",

deps/rabbit/src/rabbit.erl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,6 @@
148148
[{description, "kernel ready"},
149149
{requires, external_infrastructure}]}).
150150

151-
-rabbit_boot_step({rabbit_memory_monitor,
152-
[{description, "memory monitor"},
153-
{mfa, {rabbit_sup, start_restartable_child,
154-
[rabbit_memory_monitor]}},
155-
{requires, rabbit_alarm},
156-
{enables, core_initialized}]}).
157-
158151
-rabbit_boot_step({guid_generator,
159152
[{description, "guid generator"},
160153
{mfa, {rabbit_sup, start_restartable_child,

deps/rabbit/src/rabbit_amqqueue.erl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
%% internal
7676
-export([internal_declare/2, internal_delete/2, run_backing_queue/3,
77-
set_ram_duration_target/2, set_maximum_since_use/2,
77+
set_maximum_since_use/2,
7878
emit_consumers_local/3, internal_delete/3]).
7979

8080
-include_lib("rabbit_common/include/rabbit.hrl").
@@ -1790,11 +1790,6 @@ forget_node_for_queue(Q) ->
17901790
run_backing_queue(QPid, Mod, Fun) ->
17911791
gen_server2:cast(QPid, {run_backing_queue, Mod, Fun}).
17921792

1793-
-spec set_ram_duration_target(pid(), number() | 'infinity') -> 'ok'.
1794-
1795-
set_ram_duration_target(QPid, Duration) ->
1796-
gen_server2:cast(QPid, {set_ram_duration_target, Duration}).
1797-
17981793
-spec set_maximum_since_use(pid(), non_neg_integer()) -> 'ok'.
17991794

18001795
set_maximum_since_use(QPid, Age) ->

deps/rabbit/src/rabbit_amqqueue_process.erl

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
-behaviour(gen_server2).
1313

14-
-define(SYNC_INTERVAL, 200). %% milliseconds
15-
-define(RAM_DURATION_UPDATE_INTERVAL, 5000).
16-
-define(CONSUMER_BIAS_RATIO, 2.0). %% i.e. consume 100% faster
14+
-define(SYNC_INTERVAL, 200). %% milliseconds
15+
-define(UPDATE_RATES_INTERVAL, 5000).
16+
-define(CONSUMER_BIAS_RATIO, 2.0). %% i.e. consume 100% faster
1717

1818
-export([info_keys/0]).
1919

@@ -48,7 +48,7 @@
4848
expires,
4949
%% timer used to periodically sync (flush) queue index
5050
sync_timer_ref,
51-
%% timer used to update ingress/egress rates and queue RAM duration target
51+
%% timer used to update ingress/egress rates
5252
rate_timer_ref,
5353
%% timer used to clean up this queue due to TTL (on when unused)
5454
expiry_timer_ref,
@@ -212,9 +212,6 @@ init_it2(Recover, From, State = #q{q = Q,
212212
true ->
213213
ok = file_handle_cache:register_callback(
214214
rabbit_amqqueue, set_maximum_since_use, [self()]),
215-
ok = rabbit_memory_monitor:register(
216-
self(), {rabbit_amqqueue,
217-
set_ram_duration_target, [self()]}),
218215
BQ = backing_queue_module(),
219216
BQS = bq_init(BQ, Q, TermsOrNew),
220217
send_reply(From, {new, Q}),
@@ -364,8 +361,7 @@ terminate_shutdown(Fun, #q{status = Status} = State) ->
364361
fun stop_ttl_timer/1]),
365362
case BQS of
366363
undefined -> State1;
367-
_ -> ok = rabbit_memory_monitor:deregister(self()),
368-
QName = qname(State),
364+
_ -> QName = qname(State),
369365
notify_decorators(shutdown, State),
370366
[emit_consumer_deleted(Ch, CTag, QName, ActingUser) ||
371367
{Ch, CTag, _, _, _, _, _, _} <-
@@ -529,8 +525,8 @@ stop_sync_timer(State) -> rabbit_misc:stop_timer(State, #q.sync_timer_ref).
529525

530526
ensure_rate_timer(State) ->
531527
rabbit_misc:ensure_timer(State, #q.rate_timer_ref,
532-
?RAM_DURATION_UPDATE_INTERVAL,
533-
update_ram_duration).
528+
?UPDATE_RATES_INTERVAL,
529+
update_rates).
534530

535531
stop_rate_timer(State) -> rabbit_misc:stop_timer(State, #q.rate_timer_ref).
536532

@@ -1193,7 +1189,6 @@ prioritise_cast(Msg, _Len, State) ->
11931189
case Msg of
11941190
delete_immediately -> 8;
11951191
{delete_exclusive, _Pid} -> 8;
1196-
{set_ram_duration_target, _Duration} -> 8;
11971192
{set_maximum_since_use, _Age} -> 8;
11981193
{run_backing_queue, _Mod, _Fun} -> 6;
11991194
{ack, _AckTags, _ChPid} -> 4; %% [1]
@@ -1221,13 +1216,12 @@ consumer_bias(#q{backing_queue = BQ, backing_queue_state = BQS}, Low, High) ->
12211216
prioritise_info(Msg, _Len, #q{q = Q}) ->
12221217
DownPid = amqqueue:get_exclusive_owner(Q),
12231218
case Msg of
1224-
{'DOWN', _, process, DownPid, _} -> 8;
1225-
update_ram_duration -> 8;
1226-
{maybe_expire, _Version} -> 8;
1227-
{drop_expired, _Version} -> 8;
1228-
emit_stats -> 7;
1229-
sync_timeout -> 6;
1230-
_ -> 0
1219+
{'DOWN', _, process, DownPid, _} -> 8;
1220+
{maybe_expire, _Version} -> 8;
1221+
{drop_expired, _Version} -> 8;
1222+
emit_stats -> 7;
1223+
sync_timeout -> 6;
1224+
_ -> 0
12311225
end.
12321226

12331227
handle_call({init, Recover}, From, State) ->
@@ -1505,11 +1499,6 @@ handle_cast({deactivate_limit, ChPid}, State) ->
15051499
noreply(possibly_unblock(rabbit_queue_consumers:deactivate_limit_fun(),
15061500
ChPid, State));
15071501

1508-
handle_cast({set_ram_duration_target, Duration},
1509-
State = #q{backing_queue = BQ, backing_queue_state = BQS}) ->
1510-
BQS1 = BQ:set_ram_duration_target(Duration, BQS),
1511-
noreply(State#q{backing_queue_state = BQS1});
1512-
15131502
handle_cast({set_maximum_since_use, Age}, State) ->
15141503
ok = file_handle_cache:set_maximum_since_use(Age),
15151504
noreply(State);
@@ -1659,15 +1648,12 @@ handle_info({'DOWN', _MonitorRef, process, DownPid, _Reason}, State) ->
16591648
{stop, State1} -> stop(State1)
16601649
end;
16611650

1662-
handle_info(update_ram_duration, State = #q{backing_queue = BQ,
1663-
backing_queue_state = BQS}) ->
1664-
{RamDuration, BQS1} = BQ:ram_duration(BQS),
1665-
DesiredDuration =
1666-
rabbit_memory_monitor:report_ram_duration(self(), RamDuration),
1667-
BQS2 = BQ:set_ram_duration_target(DesiredDuration, BQS1),
1651+
handle_info(update_rates, State = #q{backing_queue = BQ,
1652+
backing_queue_state = BQS}) ->
1653+
BQS1 = BQ:update_rates(BQS),
16681654
%% Don't call noreply/1, we don't want to set timers
16691655
{State1, Timeout} = next_state(State#q{rate_timer_ref = undefined,
1670-
backing_queue_state = BQS2}),
1656+
backing_queue_state = BQS1}),
16711657
{noreply, State1, Timeout};
16721658

16731659
handle_info(sync_timeout, State) ->
@@ -1697,11 +1683,8 @@ handle_pre_hibernate(State = #q{backing_queue_state = undefined}) ->
16971683
{hibernate, State};
16981684
handle_pre_hibernate(State = #q{backing_queue = BQ,
16991685
backing_queue_state = BQS}) ->
1700-
{RamDuration, BQS1} = BQ:ram_duration(BQS),
1701-
DesiredDuration =
1702-
rabbit_memory_monitor:report_ram_duration(self(), RamDuration),
1703-
BQS2 = BQ:set_ram_duration_target(DesiredDuration, BQS1),
1704-
BQS3 = BQ:handle_pre_hibernate(BQS2),
1686+
BQS1 = BQ:update_rates(BQS),
1687+
BQS3 = BQ:handle_pre_hibernate(BQS1),
17051688
rabbit_event:if_enabled(
17061689
State, #q.stats_timer,
17071690
fun () -> emit_stats(State,

deps/rabbit/src/rabbit_backing_queue.erl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
-type purged_msg_count() :: non_neg_integer().
3434
-type async_callback() ::
3535
fun ((atom(), fun ((atom(), state()) -> state())) -> 'ok').
36-
-type duration() :: ('undefined' | 'infinity' | number()).
3736

3837
-type msg_fun(A) :: fun ((mc:state(), ack(), A) -> A).
3938
-type msg_pred() :: fun ((rabbit_types:message_properties()) -> boolean()).
@@ -190,21 +189,8 @@
190189
%% What's the queue depth, where depth = length + number of pending acks
191190
-callback depth(state()) -> non_neg_integer().
192191

193-
%% For the next three functions, the assumption is that you're
194-
%% monitoring something like the ingress and egress rates of the
195-
%% queue. The RAM duration is thus the length of time represented by
196-
%% the messages held in RAM given the current rates. If you want to
197-
%% ignore all of this stuff, then do so, and return 0 in
198-
%% ram_duration/1.
199-
200-
%% The target is to have no more messages in RAM than indicated by the
201-
%% duration and the current queue rates.
202-
-callback set_ram_duration_target(duration(), state()) -> state().
203-
204-
%% Optionally recalculate the duration internally (likely to be just
205-
%% update your internal rates), and report how many seconds the
206-
%% messages in RAM represent given the current rates of the queue.
207-
-callback ram_duration(state()) -> {duration(), state()}.
192+
%% Update the internal message rates.
193+
-callback update_rates(state()) -> state().
208194

209195
%% Should 'timeout' be called as soon as the queue process can manage
210196
%% (either on an empty mailbox, or when a timer fires)?

0 commit comments

Comments
 (0)