<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
<font class="Apple-style-span" face="Tahoma" size="2">Bless hotmail for sending an e-mail on an attempted paste of text...as I was saying</font><div style="font-family: Tahoma; font-size: 10pt; "><br></div><div><font class="Apple-style-span" face="Tahoma" size="2">With that information in mind this is what you are really looking at for 1M processes: </font><br><div><font class="Apple-style-span" face="Tahoma" size="2">233 words</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">1 word = 4 bytes on 32 bit system</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">1 word = 8 bytes on 64 bit system</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">233 * 4 = 932 bytes on 32 bit system</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">233 * 8 = 1864 bytes on 64 bit system</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">1M procs * 932 bytes = 932,000,000 / 1000 / 1000 / 1000 = .932 GB on 32 bit system</font></div><div><font class="Apple-style-span" face="Tahoma" size="2">1M procs * 1864 bytes = 1,864,000,000 / 1000 / 1000 / 1000 = 1.864 GB on 64 bit system</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">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.</font></div><div><font class="Apple-style-span" face="Tahoma" size="2"><br></font></div><div><font class="Apple-style-span" face="Tahoma" size="2">Chris Hicks.</font></div><div id="SkyDrivePlaceholder" style="font-family: Tahoma; font-size: 10pt; "></div><hr id="stopSpelling" style="font-family: Tahoma; font-size: 10pt; "><font class="Apple-style-span" face="Tahoma" size="2">From: silent_vendetta@hotmail.com</font><br><font class="Apple-style-span" face="Tahoma" size="2">To: erlang-questions@erlang.org</font><br><font class="Apple-style-span" face="Tahoma" size="2">Date: Mon, 9 May 2011 21:29:12 -0700</font><br><font class="Apple-style-span" face="Tahoma" size="2">Subject: Re: [erlang-questions] Erlang proccess memory usage</font><br><br>

<meta http-equiv="Content-Type" content="text/html; charset=unicode">
<meta name="Generator" content="Microsoft SafeHTML">
<style>
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Tahoma;}

</style><font class="Apple-style-span" face="Tahoma" size="2">


The first problem you are running into is that you are mistaking "words" for "bytes" see: </font><a href="http://www.erlang.org/doc/efficiency_guide/advanced.html" target="_blank" style="font-family: Tahoma; font-size: 10pt; ">http://www.erlang.org/doc/efficiency_guide/advanced.html</a><br><br><div style="font-family: Tahoma; font-size: 10pt; ">With that information in mind this is what you are really looking at for 1M processes:</div><div style="font-family: Tahoma; font-size: 10pt; "><br></div><div style="font-family: Tahoma; font-size: 10pt; "><br><hr id="ecxstopSpelling">From: wsong.cn@gmail.com<br>Date: Tue, 10 May 2011 11:55:04 +0800<br>To: erlang-questions@erlang.org<br>Subject: Re: [erlang-questions] Erlang proccess memory usage<br><br>Also I tried to use proc_lib:hibernate/3 with no difference.<br><br><div class="ecxgmail_quote">On Tue, May 10, 2011 at 11:50 AM, Wenqiang Song <span dir="ltr"><<a href="http://wsong.cn" target="_blank">wsong.cn</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>></span> wrote:<br>

<blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex">Hi, 
<div><br></div><div>I'm experimenting with Erlang process and found something that not expected. </div><div><br></div><div>What I do is creating 1M Erlang processes and measure memory usage. Code is as follow:</div><div>


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


<div><br></div><div>count (Num) -></div><div>    receive</div><div><span style="white-space:pre-wrap">     </span>add -></div><div>%<span style="white-space:pre-wrap">       </span>    io:format("Oopss, ~n"),</div>


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


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


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


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


<div> {total_heap_size,233},</div><div> {heap_size,233},</div><div> {stack_size,1},</div><div> {reductions,9},</div><div> {garbage_collection,[{min_bin_vheap_size,46368},</div><div>                      {min_heap_size,233},</div>


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


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


</div><div><br></div><div>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?</div><div><br></div><div>


Thanks</div><div>Andy</div>
</blockquote></div><br><br clear="all"><br>-- <br>有志者,事竟成,破釜沉舟,百二秦关终属楚<br>苦心人,天不负,卧薪尝胆,三千越甲可吞吴<br>
<br>_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions</div>                                           
<br><font class="Apple-style-span" face="Tahoma" size="2">_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions</font></div>                                      </body>
</html>