4.x: speed up node startup by avoid loading all modules during boot #10989
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.
A fairly large chunk of boot time is spent trying to look up modules that have certain attributes via
Module:module_info(attributes)
. Executing the builtinmodule_info/1
function is very very fast but only after the module is initially loaded. For any unloaded module, attempting to execute the function loads the module. Code loading can be fairly slow with some modules taking around a millisecond individually, and all code loading is currently done in serial by the code server.We use this for
rabbit_boot_step
andrabbit_feature_flag
attributes for example and we can't avoid scanning many modules without much larger breaking changes. When we read those attributes though we only lookup modules from applications that depend on therabbit
app. This saves quite a lot of work because we avoid most dependencies and builtin modules from Erlang/OTP that we would never load anyways, for example thewx
modules.We can re-use that function in the management plugin to avoid scanning most available modules for the
rabbit_mgmt_extension
behaviour. We also need to stop theprometheus
dependency from scanning for its interceptor and collector behaviours on boot. We can do this by setting explicit empty values for the application environment variablesprometheus
uses as defaults. This is a safe change because we don't use interceptors and we register all collectors explicitly.There is a functional change to the management plugin to be aware of: any plugins that use the
rabbit_mgmt_extension
behaviour must declare a dependency on therabbit
application. This is true for all tier-1 plugins but should be kept in mind for community plugins.For me locally this reduces single node boot (
bazel run broker
) time from ~6100ms to ~4300ms.