From 930c78795cdbfa0dc84f4bbab2655b024743a594 Mon Sep 17 00:00:00 2001 From: dcorbacho Date: Wed, 24 Feb 2021 16:20:52 +0100 Subject: [PATCH] Rename consumer_utilisation to consumer_capacity Capacity is 100% when there are online consumers and no messages --- deps/rabbit/src/rabbit_amqqueue_process.erl | 12 +++++++----- deps/rabbit/src/rabbit_fifo.erl | 18 ++++++++++-------- deps/rabbit/src/rabbit_queue_consumers.erl | 9 ++++++--- deps/rabbit/src/rabbit_quorum_queue.erl | 1 + deps/rabbitmq_management/priv/www/js/global.js | 4 ++-- .../priv/www/js/tmpl/queue.ejs | 4 ++-- .../priv/www/js/tmpl/queues.ejs | 8 ++++---- .../test/rabbit_mgmt_http_SUITE.erl | 3 ++- 8 files changed, 34 insertions(+), 25 deletions(-) diff --git a/deps/rabbit/src/rabbit_amqqueue_process.erl b/deps/rabbit/src/rabbit_amqqueue_process.erl index 727c41542f..6f21eb1be1 100644 --- a/deps/rabbit/src/rabbit_amqqueue_process.erl +++ b/deps/rabbit/src/rabbit_amqqueue_process.erl @@ -110,6 +110,7 @@ single_active_consumer_tag, consumers, consumer_utilisation, + consumer_capacity, memory, slave_pids, synchronised_slave_pids, @@ -1118,10 +1119,12 @@ i(messages, State) -> messages_unacknowledged]]); i(consumers, _) -> rabbit_queue_consumers:count(); -i(consumer_utilisation, #q{consumers = Consumers}) -> +i(consumer_utilisation, State) -> + i(consumer_capacity, State); +i(consumer_capacity, #q{consumers = Consumers}) -> case rabbit_queue_consumers:count() of - 0 -> ''; - _ -> rabbit_queue_consumers:utilisation(Consumers) + 0 -> 0; + _ -> rabbit_queue_consumers:capacity(Consumers) end; i(memory, _) -> {memory, M} = process_info(self(), memory), @@ -1750,8 +1753,7 @@ handle_pre_hibernate(State = #q{backing_queue = BQ, State, #q.stats_timer, fun () -> emit_stats(State, [{idle_since, - os:system_time(milli_seconds)}, - {consumer_utilisation, ''}]) + os:system_time(milli_seconds)}]) end), State1 = rabbit_event:stop_stats_timer(State#q{backing_queue_state = BQS3}, #q.stats_timer), diff --git a/deps/rabbit/src/rabbit_fifo.erl b/deps/rabbit/src/rabbit_fifo.erl index 3b5b9f5e40..e2f69d047b 100644 --- a/deps/rabbit/src/rabbit_fifo.erl +++ b/deps/rabbit/src/rabbit_fifo.erl @@ -759,7 +759,7 @@ which_module(1) -> ?MODULE. -record(aux_gc, {last_raft_idx = 0 :: ra:index()}). -record(aux, {name :: atom(), - utilisation :: term(), + capacity :: term(), gc = #aux_gc{} :: #aux_gc{}}). init_aux(Name) when is_atom(Name) -> @@ -769,7 +769,7 @@ init_aux(Name) when is_atom(Name) -> {write_concurrency, true}]), Now = erlang:monotonic_time(micro_seconds), #aux{name = Name, - utilisation = {inactive, Now, 1, 1.0}}. + capacity = {inactive, Now, 1, 1.0}}. handle_aux(leader, _, garbage_collection, State, Log, _MacState) -> ra_log_wal:force_roll_over(ra_log_wal), @@ -779,15 +779,15 @@ handle_aux(follower, _, garbage_collection, State, Log, MacState) -> {no_reply, force_eval_gc(Log, MacState, State), Log}; handle_aux(_RaState, cast, eval, Aux0, Log, _MacState) -> {no_reply, Aux0, Log}; -handle_aux(_RaState, cast, Cmd, #aux{utilisation = Use0} = Aux0, +handle_aux(_RaState, cast, Cmd, #aux{capacity = Use0} = Aux0, Log, _MacState) when Cmd == active orelse Cmd == inactive -> - {no_reply, Aux0#aux{utilisation = update_use(Use0, Cmd)}, Log}; + {no_reply, Aux0#aux{capacity = update_use(Use0, Cmd)}, Log}; handle_aux(_RaState, cast, tick, #aux{name = Name, - utilisation = Use0} = State0, + capacity = Use0} = State0, Log, MacState) -> true = ets:insert(rabbit_fifo_usage, - {Name, utilisation(Use0)}), + {Name, capacity(Use0)}), Aux = eval_gc(Log, MacState, State0), {no_reply, Aux, Log}; handle_aux(_RaState, {call, _From}, {peek, Pos}, Aux0, @@ -991,9 +991,11 @@ update_use({inactive, Since, Active, Avg}, active) -> Now = erlang:monotonic_time(micro_seconds), {active, Now, use_avg(Active, Now - Since, Avg)}. -utilisation({active, Since, Avg}) -> +capacity({active, Since, Avg}) -> use_avg(erlang:monotonic_time(micro_seconds) - Since, 0, Avg); -utilisation({inactive, Since, Active, Avg}) -> +capacity({inactive, _, 1, 1.0}) -> + 1.0; +capacity({inactive, Since, Active, Avg}) -> use_avg(Active, erlang:monotonic_time(micro_seconds) - Since, Avg). use_avg(0, 0, Avg) -> diff --git a/deps/rabbit/src/rabbit_queue_consumers.erl b/deps/rabbit/src/rabbit_queue_consumers.erl index 5046aea42c..c5a62ea677 100644 --- a/deps/rabbit/src/rabbit_queue_consumers.erl +++ b/deps/rabbit/src/rabbit_queue_consumers.erl @@ -12,7 +12,7 @@ send_drained/0, deliver/5, record_ack/3, subtract_acks/3, possibly_unblock/3, resume_fun/0, notify_sent_fun/1, activate_limit_fun/0, - credit/6, utilisation/1, is_same/3, get_consumer/1, get/3, + credit/6, utilisation/1, capacity/1, is_same/3, get_consumer/1, get/3, consumer_tag/1, get_infos/1]). %%---------------------------------------------------------------------------- @@ -409,10 +409,13 @@ drain_mode(true) -> drain; drain_mode(false) -> manual. -spec utilisation(state()) -> ratio(). +utilisation(State) -> + capacity(State). -utilisation(#state{use = {active, Since, Avg}}) -> +-spec capacity(state()) -> ratio(). +capacity(#state{use = {active, Since, Avg}}) -> use_avg(erlang:monotonic_time(micro_seconds) - Since, 0, Avg); -utilisation(#state{use = {inactive, Since, Active, Avg}}) -> +capacity(#state{use = {inactive, Since, Active, Avg}}) -> use_avg(Active, erlang:monotonic_time(micro_seconds) - Since, Avg). is_same(ChPid, ConsumerTag, {ChPid, #consumer{tag = ConsumerTag}}) -> diff --git a/deps/rabbit/src/rabbit_quorum_queue.erl b/deps/rabbit/src/rabbit_quorum_queue.erl index 3fb3e026d4..52b9930ab6 100644 --- a/deps/rabbit/src/rabbit_quorum_queue.erl +++ b/deps/rabbit/src/rabbit_quorum_queue.erl @@ -383,6 +383,7 @@ handle_tick(QName, _ -> rabbit_fifo:usage(Name) end, Infos = [{consumers, C}, + {consumer_capacity, Util}, {consumer_utilisation, Util}, {message_bytes_ready, MsgBytesReady}, {message_bytes_unacknowledged, MsgBytesUnack}, diff --git a/deps/rabbitmq_management/priv/www/js/global.js b/deps/rabbitmq_management/priv/www/js/global.js index fbd1b5e33c..9f48189672 100644 --- a/deps/rabbitmq_management/priv/www/js/global.js +++ b/deps/rabbitmq_management/priv/www/js/global.js @@ -71,7 +71,7 @@ var ALL_COLUMNS = ['features_no_policy', 'Features (no policy)', false], ['policy', 'Policy', false], ['consumers', 'Consumer count', false], - ['consumer_utilisation', 'Consumer utilisation', false], + ['consumer_capacity', 'Consumer capacity', false], ['state', 'State', true]], 'Messages': [['msgs-ready', 'Ready', true], ['msgs-unacked', 'Unacknowledged', true], @@ -251,7 +251,7 @@ var HELP = { 'queue-process-memory': 'Total memory used by this queue process. This does not include in-memory message bodies (which may be shared between queues and will appear in the global "binaries" memory) but does include everything else.', - 'queue-consumer-utilisation': + 'queue-consumer-capacity': 'Fraction of the time that the queue is able to immediately deliver messages to consumers. If this number is less than 100% you may be able to deliver messages faster if: \