Slow init:stop/0 due to purging modules
Frank Hunleth
fhunleth@REDACTED
Tue Jul 6 16:52:25 CEST 2021
I'm looking into an issue where init:stop/0 is taking a surprisingly
long time (to me at least) on OTP 24. This is on a Raspberry Pi Zero,
so it's not the fastest CPU and no JIT is involved. With a small-ish
release started in embedded mode, it's taking almost 2 minutes to run
init:stop/0. It doesn't take nearly this long to start. I haven't
timed it, but I'd guess that it was closer to 10-20 seconds to load
all modules and start all applications.
Right now, I've narrowed this down to init:do_unload/1:
```
do_unload([M|Mods]) ->
catch erlang:purge_module(M),
catch erlang:delete_module(M),
catch erlang:purge_module(M),
do_unload(Mods);
do_unload([]) ->
ok.
```
I was assuming that I'd find a NIF that was slow to unload, but it
looks like every module takes roughly the same time to purge, delete,
purge. It's just that there are a lot of modules and purge, delete,
purge is slow enough to accumulate to a long time on a Raspberry Pi
Zero.
I'm starting to enter code that I'm much less familiar with, so I was
wondering if anyone could help:
1. Does it make sense for unloading all modules to take longer than
loading them? Just want to sanity check that unloading isn't slow by
design.
2. If the VM is going to exit anyway, is do_unload necessary for
graceful shutdown? Like if I were to implement my own graceful
shutdown that stopped all applications and halted, would that be
shortsighted?
3. Assuming that purge,delete,purge is important, are there particular
places in the code that I should look at to see if I can figure out
why they're slow?
Thanks!
Frank
More information about the erlang-questions
mailing list