varsill

varsill

Membrane Core Team

Comparing memory consumption of programs run on BEAM

Hello,

I have a question concerning the comparison of memory consumption of programs run on BEAM.

Suppose that I have two versions of a program performing some computation, and I want to know which is consuming less memory. I want to have an automated testing system that runs two versions of the program multiple times in some isolated environment, measures their memory consumption during the run, and tells me which statistically uses less memory.

How should I perform the memory measurements? In particular:

  1. What method should I use to fetch the current memory usage? Would :erlang.memory(:total) be enough, or should I subtract some constant “initial” value (e.g., the amount of memory used by the BEAM before running the program)? Or perhaps it would be better, to sum up the memory used by the particular processes building my program?
  2. How often should I perform the measurement?
  3. How should I deal with the randomness of GC invocations? The results of the tests seem to be susceptible to the moment when the GC is run.
  4. How could a final metric (based on the memory measurements) look to give me a view on which version is, in fact, “better”?

I know that my question is really general, and answering it precisely requires some more specific definition of what it means that a particular program uses less memory than the other (do we take under consideration the maximum peak memory usage, or an average usage of memory, which type of memory are we interested in measuring, etc.), but I would appreciate some general tips on how such tests should be performed.

Best wishes,
Łukasz

Most Liked

LostKobrakai

LostKobrakai

Not necessarily an answer to your questions, but Benchee can perform memory usage based benchmarks.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
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

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

We're in Beta

About us Mission Statement