# Elixir memory usage

**URL:** <https://forum.elixirforum.com/t/elixir-memory-usage/21444>\
**Category:** Questions\
**Tags:** beam, memory\
**Created:** [April 5, 2019, 7:41pm UTC](https://forum.elixirforum.com/t/elixir-memory-usage/21444 "2019-04-05T19:41:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefanchrobot](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stefanchrobot/32/7657_2.png) [@stefanchrobot](https://forum.elixirforum.com/u/stefanchrobot)\
**Post date:** [April 5, 2019, 7:41pm UTC](https://forum.elixirforum.com/t/elixir-memory-usage/21444/1 "2019-04-05T19:41:36Z")

</div>

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:

 ![32](https://forum.elixirforum.com/uploads/default/original/2X/0/0b88bb3eef43b56f50f54f4bdd555826ab726c20.jpeg)

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?

---

<div class="post-metadata">

**Author:** ![jeremyjh](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jeremyjh/32/5995_2.png) [@jeremyjh](https://forum.elixirforum.com/u/jeremyjh)\
**Post date:** [April 5, 2019, 9:45pm UTC](https://forum.elixirforum.com/t/elixir-memory-usage/21444/2 "2019-04-05T21:45:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sribe](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@sribe](https://forum.elixirforum.com/u/sribe)\
**Post date:** [April 6, 2019, 1:46am UTC](https://forum.elixirforum.com/t/elixir-memory-usage/21444/3 "2019-04-06T01:46:56Z")

</div>

I seem to recall a minimal web/proxy thing I wrote taking about 24MB used… There is an awful lot of runtime data available in the BEAM. You can easily find out what processes have the largest heaps etc. I’ve used the base Erlang system info calls, but I bet somebody here can guide you to easier-to-use tools that will allow you to drill down and find out where the big uses are.

---

<div class="post-metadata">

**Author:** ![jeramyRR](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jeramyrr/32/722_2.png) [@jeramyRR](https://forum.elixirforum.com/u/jeramyRR)\
**Post date:** [April 6, 2019, 3:27am UTC](https://forum.elixirforum.com/t/elixir-memory-usage/21444/4 "2019-04-06T03:27:49Z")

</div>

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

The image below shows a basic Phoenix app.

 ![image](https://forum.elixirforum.com/uploads/default/original/2X/3/3dbd0d867272486549f27f0cbb09b90227197fbc.png)

---

<div class="post-metadata">

**Author:** ![stefanchrobot](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stefanchrobot/32/7657_2.png) [@stefanchrobot](https://forum.elixirforum.com/u/stefanchrobot)\
**Post date:** [April 6, 2019, 6:49am UTC](https://forum.elixirforum.com/t/elixir-memory-usage/21444/5 "2019-04-06T06:49:16Z")

</div>

> [@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.

👍 makes sense!

Here’s my app:

```elixir
$ 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`?

---

<div class="post-metadata">

**Author:** ![jola](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jola/32/18010_2.png) [@jola](https://forum.elixirforum.com/u/jola)\
**Post date:** [April 6, 2019, 9:59am UTC](https://forum.elixirforum.com/t/elixir-memory-usage/21444/6 "2019-04-06T09:59:28Z")

</div>

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`? - #2 by michalmuskala](https://forum.elixirforum.com/t/why-do-releases-use-so-much-more-memory-than-mix-run/21450/2)

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.
