Skip to content

Commit 1c2c38d

Browse files
authored
If a queue process is hibernated, consider it up (#7825)
`rabbit_core_metrics_gc` checks the status of all queues (and other things) every two minutes. With many queues, this can get pretty expensive. Systems with lots of queues will often have many of them idle and hibernated. Before this change `rabbit_core_metrics_gc` would wake up all of them, causing a memory spike, just to check if their state isn't `down`. With this change, a hibernated queue will be considered up.
1 parent d27537b commit 1c2c38d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

deps/rabbit/src/rabbit_amqqueue.erl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,14 +1077,17 @@ list_local_names_down() ->
10771077
is_down(Q)].
10781078

10791079
is_down(Q) ->
1080-
try
1081-
info(Q, [state]) == [{state, down}]
1082-
catch
1083-
_:_ ->
1084-
true
1080+
case rabbit_process:is_process_hibernated(amqqueue:get_pid(Q)) of
1081+
true -> false;
1082+
false ->
1083+
try
1084+
info(Q, [state]) == [{state, down}]
1085+
catch
1086+
_:_ ->
1087+
true
1088+
end
10851089
end.
10861090

1087-
10881091
-spec sample_local_queues() -> [amqqueue:amqqueue()].
10891092
sample_local_queues() -> sample_n_by_name(list_local_names(), 300).
10901093

deps/rabbit/src/rabbit_process.erl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
-export([on_running_node/1,
1111
is_process_alive/1,
12+
is_process_hibernated/1,
1213
is_registered_process_alive/1]).
1314

1415
-spec on_running_node(Pid) -> OnRunningNode when
@@ -75,3 +76,15 @@ is_process_alive({Name, Node}) when is_atom(Name) andalso is_atom(Node) ->
7576

7677
is_registered_process_alive(Name) ->
7778
is_pid(whereis(Name)).
79+
80+
-spec is_process_hibernated(Pid) -> IsHibernated when
81+
Pid :: pid(),
82+
IsHibernated :: boolean().
83+
%% @doc Indicates if the specified process is hibernated.
84+
%%
85+
%% @param Pid the PID or name of the process to check
86+
%% @returns true if the process is hibernated on one of the cluster members,
87+
%% false otherwise.
88+
89+
is_process_hibernated(Pid) when is_pid(Pid) ->
90+
{current_function,{erlang,hibernate,3}} == erlang:process_info(Pid, current_function).

0 commit comments

Comments
 (0)