aiidateam / aiida-core

The official repository for the AiiDA code
https://aiida-core.readthedocs.io
Other
413 stars 185 forks source link

`verdi daemon stop` takes twice as long when the daemon is not running #6373

Closed danielhollas closed 2 months ago

danielhollas commented 2 months ago

I noticed something very strange when looking at the performance of verdi daemon command. On my machine, stoping a daemon with 1 worker takes about 1.5 second

time verdi daemon stop
Profile: default
Stopping the daemon... OK

real    0m1.612s
user    0m2.581s
sys 0m0.085s

However, repeating the same command, it suddenly takes twice as long!

Profile: default
Stopping the daemon... OK

real    0m3.437s
user    0m2.573s
sys 0m0.123s
danielhollas commented 2 months ago

Oh, I guess there is a timeout somewhere, where verdi tries to communicate with the daemon.

sphuber commented 2 months ago

Oh, I guess there is a timeout somewhere, where verdi tries to communicate with the daemon.

That is exactly it. The daemon commands will always try to reach the circus process. If it is not actually running, the command will just hit the timeout at some point. At some point we had a different approach where the command would first check for the PID file that is written when the daemon is started. However, this approach was not always reliable and so we opted to not rely on its existence to decide whether the daemon should be running or not.

danielhollas commented 2 months ago

Thanks, makes sense. This came up when thinking about speeding up the AiiDAlab container startup, where we stop and later start the Daemon so that we can automatically run verdi storage migrate. I guess we could reduce the timeout using the -t but that seems dangerous and would not by us that much.