[erlang-questions] Erlang proccess memory usage

Chris Hicks <>
Tue May 10 06:38:13 CEST 2011


Bless hotmail for sending an e-mail on an attempted paste of text...as I was saying
With that information in mind this is what you are really looking at for 1M processes: 
233 words1 word = 4 bytes on 32 bit system1 word = 8 bytes on 64 bit system
233 * 4 = 932 bytes on 32 bit system233 * 8 = 1864 bytes on 64 bit system
1M procs * 932 bytes = 932,000,000 / 1000 / 1000 / 1000 = .932 GB on 32 bit system1M procs * 1864 bytes = 1,864,000,000 / 1000 / 1000 / 1000 = 1.864 GB on 64 bit system
The thing that is a bit confusing is that memory() displays the amount used in bytes, whereas any process info appears to return the amount of memory used in words. That still doesn't get you to your 2.7 gigs used, but it should help explain a decent chunk of where that memory went.
Chris Hicks.From: 
To: 
Date: Mon, 9 May 2011 21:29:12 -0700
Subject: Re: [erlang-questions] Erlang proccess memory usage








The first problem you are running into is that you are mistaking "words" for "bytes" see: http://www.erlang.org/doc/efficiency_guide/advanced.html

With that information in mind this is what you are really looking at for 1M processes:

From: 
Date: Tue, 10 May 2011 11:55:04 +0800
To: 
Subject: Re: [erlang-questions] Erlang proccess memory usage

Also I tried to use proc_lib:hibernate/3 with no difference.

On Tue, May 10, 2011 at 11:50 AM, Wenqiang Song <> wrote:


Hi, 

I'm experimenting with Erlang process and found something that not expected. 
What I do is creating 1M Erlang processes and measure memory usage. Code is as follow:


-module(generator).-export([start/0, generator/2, loop/0]).
start() ->    Pid = self(),    spawn( fun()->generator(19,Pid) end ),    count (1).



count (Num) ->    receive	add ->%	    io:format("Oopss, ~n"),


	    if 		0 =:= ( Num rem 10000 ) -> io:format("Count ~p~n", [Num]);
		true -> Q = 3	    end,	    count (Num + 1);
	_ ->	    io:format("haha, ~n")    after 30000 ->
	    io:format("Count ~p~n", [Num]),	    count (Num)    end.
loop() ->    receive	_ ->	    io:format("Oops ~n"),
%	    proc_lib:hibernate(?MODULE, loop(), [])	    loop()    end.
generator( 0, Pid ) ->    Pid ! add,%    proc_lib:hibernate(?MODULE, loop(), []);    loop();generator( Depth, Pid ) ->    spawn( fun()->generator(Depth - 1, Pid) end),


    spawn( fun()->generator(Depth - 1, Pid) end),    Pid ! add,%    io:format("Depth: ~p, pid: ~p~n", [Depth, Pid]),%    proc_lib:hibernate(?MODULE, loop(), []).


    loop().===============End of Code=============2> i(0,58,0).[{current_function,{generator,loop,0}}, {initial_call,{erlang,apply,2}}, {status,waiting},


 {message_queue_len,0}, {messages,[]}, {links,[]}, {dictionary,[]}, {trap_exit,false}, {error_handler,error_handler}, {priority,normal}, {group_leader,<0.25.0>},


 {total_heap_size,233}, {heap_size,233}, {stack_size,1}, {reductions,9}, {garbage_collection,[{min_bin_vheap_size,46368},                      {min_heap_size,233},


                      {fullsweep_after,65535},                      {minor_gcs,0}]}, {suspending,[]}]
3> memory().[{total,2759895784},


 {processes,2751081712}, {processes_used,2751067504}, {system,8814072}, {atom,615121}, {atom_used,589205}, {binary,8608}, {code,5845747}, {ets,270928}]



Total memory usage is about 2.7G. While when I use i() and i(pid) I saw that each process only uses about 233 bytes. I can't find where the memory is used. Any idea?



ThanksAndy


-- 
有志者,事竟成,破釜沉舟,百二秦关终属楚
苦心人,天不负,卧薪尝胆,三千越甲可吞吴


_______________________________________________
erlang-questions mailing list

http://erlang.org/mailman/listinfo/erlang-questions 		 	   		  

_______________________________________________
erlang-questions mailing list

http://erlang.org/mailman/listinfo/erlang-questions 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110509/357e433f/attachment.htm>


More information about the erlang-questions mailing list