Hibernate after collecting garbage in `rabbit_mgmt_gc`

The `rabbit_mgmt_gc` gen_server performs garbage collections
periodically. When doing so it can create potentially fairly large
terms, for example by creating a set out of
`rabbit_exchange:list_names/0`. With many exchanges, for example, the
process memory usage can climb steadily especially when the management
agent is mostly idle since `rabbit_mgmt_gc` won't hit enough reductions
to cause a full-sweep GC on itself. Since the process is only active
periodically (once every 2min by default) we can hibernate it to GC the
terms it created.

This can save a medium amount of memory in situations where there are
very many pieces of metadata (exchanges, vhosts, queues, etc.). For
example on an idle single-node broker with 50k exchanges,
`rabbit_mgmt_gc` can hover around 50MB before being naturally GC'd. With
this patch the process memory usage stays consistent between `start_gc`
timer messages at around 1KB.

(cherry picked from commit ce5d42a9d6)
This commit is contained in:
Michael Davis 2025-05-16 13:35:55 -04:00 committed by Mergify
parent 49ec73765e
commit ffda347e87
1 changed files with 1 additions and 1 deletions

View File

@ -36,7 +36,7 @@ handle_info(start_gc, State) ->
gc_queues(),
gc_exchanges(),
gc_nodes(),
{noreply, start_timer(State)}.
{noreply, start_timer(State), hibernate}.
terminate(_Reason, #state{timer = TRef}) ->
_ = erlang:cancel_timer(TRef),