Is there a tool to diagnose slow application startup?

When my application start, it starts a lot of other applications.
Between two of those applications, there is a visible “pause” in the startup (for up to 5 seconds.)

I have no idea which application is causing this hangup.

I tried Adding Logger.debug at the beginning and end of all the entrypoints of the application which have an entrypoint. (Not all of them have, since my app has plenty of dependencies).

My logging level is as low as possible (:debug), so if any application was logging during it startup, I assume I would see it.

How would I diagnose which application is taking the time ?

As I understand it, profilers (like xprof) or tracers (like https://github.com/gabiz/tracer) would not help because the issue occurs during the startup of my application (not during its runtime.) Am I right about this ?

1 Like

Have you also set the compiletime logging purge to a low level?

Do you experience that pause in prof and development or only in one of those?

Have you only altered dependencies under your direct control or foreign/third party ones as well?

Are you able to reproduce it with an empty stub project which forces a start of the deps and then just does nothing? If so, can you share this project or are there private dependencies? If it’s the latter can you reproduce the behaviour in a similar project that is stripped by the private deps? Can you share that one?

If you have such an empty project that does nothing but simulate your applications startup phase you can remove deps one at a time and experiment around in which combination the behaviour occurs, but Id prefer the logging you tried already since it’s usually much easier to debug those.

You could start your system with iex -S mix run --no-start. This will setup all the load paths, but it won’t start the app (nor its dependencies). So at this point you have a shell, and you could try to setup some traces. Then, you can start your app with Application.ensure_all_started(:my_app). If you don’t feel like playing with tracing, you could just try to start each dependency app one at a time (or write a small piece of code which does it), and observe startup times of each dependency.

7 Likes