Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the size of an Erlang process in memory?

Tags:

process

erlang

I have a 'worker' process which I am going to assign to a job. Before I spawn hundreds of processes of this type I would like to know the memory consumption figures for it.

I know that I should sum all the elements which are stored in the process' loop data (all tuples, atoms, lists, etc) and the actual process memory footprint.

As I understand, before doing that I have to know the actual size of a {tuple|atom|list|process} itself.

Given a certain data structure which is stored in the process' memory how can I calculate the overall size of the process in memory?

like image 418
skanatek Avatar asked Sep 23 '11 11:09

skanatek


2 Answers

erlang:process_info/2 will give you the amount of memory, in bytes, that a process occupies. For example:

1> erlang:process_info(whereis(code_server), memory).
{memory,284208}

Note that binaries are not included since they are not located in the process heap. Those you have to count the size of manually.

like image 73
Adam Lindberg Avatar answered Oct 26 '22 09:10

Adam Lindberg


Did you read the Erlang Efficiency Guide on Memory?

like image 23
Matthijs Bierman Avatar answered Oct 26 '22 09:10

Matthijs Bierman