Fl4m3Ph03n1x

Fl4m3Ph03n1x

:memsup and BEAM memory consumption

Background

I am testing an application where I perform some actions depending on the amount of memory the machine has free. To supervise the machine’s memory I am using :memsup.get_memory_data/0 but I am getting some really weird results.

Problem

I am have a machine with 8GB of RAM, which should be more than enough for opening iex and doing some tests. However, :memsup always returns absurd results like the following:

iex(9)> {total, allocated, _worse} = :memsup.get_memory_data()
{8235098112, 7862636544, {#PID<0.118.0>, 372944}}
iex(10)> (allocated / total) * 100                             
95.47714474151489

No matter what I do, I always have :memsup report BEAM is using up to 95% of my machine’s memory. All I have open is a single session of iex that I am using as a playground.

What’s even more weird is that htop returns me a completely different value of memory usage, stating I am using 6.22GB out of 7.67GB, which still doesn’t hold up to 95% usage…

(6.22 / 7.67) * 100
81.09517601043025

Questions

So now I have some questions:

  1. Does :memsup even work?
  2. Why are the values :memsup gives me so different?
  3. Why is BEAM using over 90% of the total memory if all I have is a simple iex shell session open?
  4. Is there a reliable way to know if my machine is struggling with memory?

Marked As Solved

peerreynders

peerreynders

I wonder if the numbers seem off because total reports physical memory while allocated includes(?) cached memory.

memsup seems to be designed to pinpoint individual processes that are heavy memory users - the rest of the functionality seems to just report information reported by the OS.


You may want to look into recon (possibly via one of the Elixir wrappers) - see page 41 of Erlang in Anger

Also Liked

spencerdcarlson

spencerdcarlson

To piggy back off of this, it looks like recon_alloc:memory/1 has the answers.

:recon_alloc.memory(:usage)

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New

We're in Beta

About us Mission Statement