stefanchrobot

stefanchrobot

Elixir memory usage

I’ve been looking at my application in terms of resource usage. It’s a simple SQS consumer that calls some APIs and is under a very small load. BEAM constantly reports usage of around 70MB of memory:

I’m not sure what to think about it. Honestly, I expected a smaller footprint. I’m running with the default settings and simple MIX_ENV=prod mix run.

Is there an easy way to shave off some memory? Also, I’m wondering - why so many atoms are used?

Most Liked

jeremyjh

jeremyjh

Each module, and every function in every module is an atom. If you are loading a few libraries hitting 22K isn’t too hard. I’m not sure what to think of the memory. Its not so bad compared to other high-level language VMs though is it? I’m sure Go or Rust would be a lot smaller but a better comparison is Ruby, Python or Java.

jeramyRR

jeramyRR

70 MBs seems a bit high for a small app. What all libs are you loading?

The image below shows a basic Phoenix app.

jola

jola

If you do try building a release, I’m curious to see what the memory usage turns out to be. I made a quick comparison in a project of my own and also just a plain new phoenix project, in both cases memory use was much higher in the release. Why do releases use so much more memory than `mix run`?

As I point out though, my comparison may be unfair, as not all code is necessarily loaded in the mix version when I checked memory use, while releases preload all modules. But you should be able to get an accurate comparison.

stefanchrobot

stefanchrobot

:+1: makes sense!

Here’s my app:

$ mix deps.tree
app
├── statix ~> 1.1 (Hex package)
├── gen_stage ~> 0.14.0 (Hex package)
├── jason ~> 1.1 (Hex package)
├── poison ~> 4.0 (Hex package)
├── junit_formatter ~> 3.0 (Hex package)
├── dialyxir ~> 0.4 (Hex package)
├── hackney ~> 1.9 (Hex package)
│   ├── certifi 2.5.1 (Hex package)
│   │   └── parse_trans ~>3.3 (Hex package)
│   ├── idna 6.0.0 (Hex package)
│   │   └── unicode_util_compat 0.4.1 (Hex package)
│   ├── metrics 1.0.1 (Hex package)
│   ├── mimerl ~>1.1 (Hex package)
│   └── ssl_verify_fun 1.1.4 (Hex package)
├── sweet_xml ~> 0.6 (Hex package)
├── ex_aws ~> 2.0 (Hex package)
│   ├── hackney 1.6.3 or 1.6.5 or 1.7.1 or 1.8.6 or ~> 1.9 (Hex package)
│   ├── poison >= 1.2.0 (Hex package)
│   └── sweet_xml ~> 0.6 (Hex package)
├── ex_aws_sqs ~> 2.0 (Hex package)
│   └── ex_aws ~> 2.0.0 (Hex package)
├── credo ~> 1.0 (Hex package)
│   ├── bunt ~> 0.2.0 (Hex package)
│   └── jason ~> 1.0 (Hex package)
└── tesla ~> 1.2.1 (Hex package)
    ├── hackney ~> 1.6 (Hex package)
    ├── jason >= 1.0.0 (Hex package)
    ├── mime ~> 1.0 (Hex package)
    └── poison >= 1.0.0 (Hex package)

credo, dialyxir and junit_formatter are :dev or :test only.

Would the size of the loaded code change if I built a release instead of running plain mix run?

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement