Elixir app eats up a lot of memory - Optimization help?

My app is at almost 400MB of memory usage despite running very few processes, none of which are memory heavy. The only thing I can think of that might be a bit heavy are dependencies (elixir + npm) but I don’t see how they would be that heavy…

What are ways I can investigate why it eats up that much memory? Any known ways to optimize?

Thanks :slight_smile:

There is some clue on this thread.

We also have this tutorial onto how to connect observer on fly apps

1 Like

A stock firecracker VM running a stock phoenix app will use around 180MB. Lubien’s recommendations will give you the most information, so I would recommend that route. You could also expose the LiveDashboard to prod and redeploy. If you want a super quick glance at things, you can fly ssh console, then /app/bin/my_app remote and run :erlang.memory() which will let you know what the breakdown of memory usage is going:

iex(myapp@host)> :erlang.memory()
[
  total: 76412184,
  processes: 15743144,
  processes_used: 15742920,
  system: 60669040,
  atom: 1376577,
  atom_used: 1356274,
  binary: 2179000,
  code: 41267406,
  ets: 2367968
]

Thank you all for your help!

Looking at the data, my total Erlang memory usage is at ~140MB (see below).

If I understand correctly, my total usage is thus ~180MB (firecracker VM running a stock phoenix app) + ~141MB (total Erlang memory) = ~321MB ?
There is still about 80MB not accounted for but it is a good start.

My code memory usage is at ~57MB. The doc reads that it is “The total amount of memory currently allocated for Erlang code”. That is actually not clear to me, what do we call “Erlang code”? Is it the actual code I wrote + deps? 57MB seems high!

iex(myapp@host)> :erlang.memory()
[
  total: 141605360, (141MB)
  processes: 49036760 (49MB),
  processes_used: 49036536,
  system: 92568600 (92MB),
  atom: 1515865 (1MB),
  atom_used: 1512265,
  binary: 8457224 (8MB),
  code: 56992902 (57MB),
  ets: 9914712 (10MB)
]