Improve memory use of rabbit_mgmt_gc
#13898
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The main change here is to hibernate the
rabbit_mgmt_gc
gen_server after it completes its GC run. It's an ideal process for hibernation since it wakes up periodically (every 2min by default) to do some work and is then completely idle.Especially if the broker is mostly idle this server may not perform enough work to be GC'd naturally so its process memory use can grow steadily over time. It can get up to fairly high amounts (tens of MB) because of the work it does during each GC run: it creates a set out of metadata entities like vhosts, queues and exchanges. On an idle single-node broker with 50k exchanges for example,
rabbit_mgmt_gc
can creep up to around 50MB. With the hibernate change it stays at around 1KB between GC runs.I've also updated the sets usage here from
gb_sets
tosets
v2 as it's faster and more memory efficient.tprof
comparison of sets...On
main
you can monitorrabbit_mgmt_gc
withobserver_cli
orrecon
and create or import 50K exchanges. It will eventually creep up in MB of memory usage. Decrease the default time between wake-ups (rabbit_mgmt_gc.erl:23
) to see it happen faster.