odarriba

odarriba

Hello,

We are working in a pretty big Elixir application (at the moment of writing, 1 minute of compilation in an i5 processor and ~930 modules) and we have recently moved from Distillery to new Mix releases.

The issue we are having is that we are experiencing a 300% extra boot time in the application, which is causing some problems on our deployments (but we can fix that, the deployment is not the issue).

We have made a comparision of booting times with a release made by Distillery and a release made by new Mix release command, and we are seeing:

  • Distillery: ~2 seconds until Phoenix is up, inluding checking for pending migrations
  • Mix: ~9 seconds until Phoenix is up, without any migration-related process.

both measurements are on the same machine (which is the same I have made the build, so no cross-platform issue)

I have tries removing all runtime configurations, which make irt a bit better (1 or 2 seconds less) but not even near Distillery times.

Also, I noticed that during Mix release boot there is only one BEAM process taking 150% of CPU for that ~9 seconds, when with Distillery one dont get to that usage (or it goes so faster that top doesn’t measure it).

Our mix.exs release config:

  def project do
    [
      ...
      releases: [
        my_release: [
          include_executables_for: [:unix],
          path: "rel/build/my_release"
        ]
      ],
      default_release: :my_release,
      ...
    ]
  end

vm.args.eex is like the default one and the env.sh.eex just set the distribution to name and sets the node name according to the pod IP when deployed on kubernetes (that was also made on Distillery releases).

Note that we are doing all this benchmarks on local, not even deploying to Kubernetes (which quotas configuratiuons can also affect).

Any idea what is happening?

Showing Posts 1 to 10

Fl4m3Ph03n1x

Fl4m3Ph03n1x

I don’t exactly know what is happening, but I do remember that the latest OTP / Erlang releases compiled around 30% faster (can’t remember if the came in version 21 or 22).

Which OTP/Erlang version are you compiling against? have you tried the newest ones?

odarriba

odarriba OP

Yep, we are using Erlang 22 with Elixir 1.9.0 (we also tried 1.9.1)

In development we are using:

elixir 1.9.0-otp-22
erlang 22.0.5

and in production we build using official elixir image.

However, the compilation times are the expected ones (more or less, it takes time but it’s due to cross dependencies between modules), the issue is when we start the release itself, that produces a CPU spike and a quite long time until the first request is served, which doesn’t happen with Distillery.

tcoopman

tcoopman

I have the idea that I’m running into the same issue with one of my applications.

I’m using elixir 1.9.1-otp-21.
At the startup of the compiled release (with bin/my_app start) I see a spike in CPU usage and it takes at least 5 seconds before any application code is executed. Running env MIX_ENV=prod mix phx.server starts immediately.

Has anyone else seen this?

jola

jola

Releases should start slower than mix phx.server because they preload modules. Mix will load modules lazily, so it starts instantly but you get a slower application until all modules have been loaded instead. Because releases preload modules they start slower but are then “warm”. Releases also start twice, once to load runtime configuration and the second time for real.

It’s hard to know in your case if mix releases are slower than distillery, unless you have a comparison?

tcoopman

tcoopman

Ok, so I’ve created a bunch of test cases and measured the time to entry in Application.start:

## Distillery (elixir 1.8.2-otp-21)
- date && _build/prod/rel/app/bin/app foreground: < 3 seconds
- date && _build/prod/rel/app/bin/app console: < 3 seconds

## Distillery (elixir 1.9.1-otp-21)
- date && _build/prod/rel/app/bin/app foreground: < 3 seconds
- date && _build/prod/rel/app/bin/app console: < 3 seconds

## Elixir releases (elixir 1.9.1-otp-21)
- date && _build/prod/rel/app/bin/app start: 10 seconds
- date && _build/prod/rel/app/bin/app start_iex: 10 seconds

## env MIX_ENV=prod mix phx.server --preload-modules (elixir 1.9.1-otp-21)
- date && env MIX_ENV=prod mix phx.server --preload-modules: < 3 seconds

## Experiment: Elixir releases without runtime configuration (elixir 1.9.1-otp-21)
- date && _build/prod/rel/app/bin/app start: < 3 seconds

As you can see, the Elixir releases with runtime configuration are way slower than distillery (which has the same runtime configuration). By accident I tried releases without runtime configuration and noticed this was much faster (in the same range as distellery - my feeling says it’s still a bit slower, but hard to measure/benchmark correctly so don’t trust me on this)
(Just as confirmation, my runtime configuration does nothing special, only reading environment variables and parsing a 4 values to Integer. It’s the same configuration that I use in distillery as well)

I’ve also tried: env MIX_ENV=prod mix phx.server --preload-modules which should preload and the startup speed is in the same ballpark as distillery, releases without runtime configuration.

So my conclusion is that there is something wrong with elixir releases with runtime configuration.
Maybe that’s easier to confirm for someone else?

jola

jola

Best thing would be to set up a repo that reproduces it. The core team would probably be happy to look at it.

I hope you find an answer :slight_smile:

tcoopman

tcoopman

Yeah, I would love to do that, but unfortunately the code is private.
I’m posting here, because it seems that I’m not the first one running into this, so hopefully someone else noticed this too and can post their code.

odarriba

odarriba OP

This happens to me also, it’s a private project with a high number of modules, and cannot publish it open source.

However I see the same issue you are having, but in a different scale (because of the number of modules, which is totally understandable).

As @jola said, it is expected that Releases take longer than mix phx.server, the real issue is that mix releases are taking 3x time the start time of a distillery release in some scenarios (we have 4 elixir projects in prod, and only this one is suffering this issue).

In our particular case, we tried removing some aspects like external libraries (AppSignal for example) in case it was causing some trouble starting the agent… but no luck. We end up rolling back to distillery until this gets solved or we have more time to investigate more to fill a proper issue in the core.

if someone thinks about anything we can look at, I will be pleased to try things.

tcoopman

tcoopman

@odarriba were you using releases.exs for runtime configuration? If you were, could you maybe test without that and see if it is faster?

odarriba

odarriba OP

We tried, and it reduced some of the overhead time, but it was also 2-3 times more time than with Distillery

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews