<div dir="ltr">An alternative to manual garbage collecting is to do all of the parsing of this ephemeral data in a separate process that dies when it's no longer needed. This is probably the best solution, and you could even tune its min_heap_size when you spawn it such that no GC (or fewer GCs) will be necessary.<div style>
<br>Some other tuning options available are the spawn_opt (some of these can be set globally too) fullsweep_after, min_heap_size, and min_bin_vheap_size. <a href="http://www.erlang.org/doc/man/erlang.html">http://www.erlang.org/doc/man/erlang.html</a></div>
<div style><br></div><div style>Here's some other resources with good information about the GC with varying levels of detail:</div><div style><a href="http://www.erlang.org/faq/academic.html#id55803">http://www.erlang.org/faq/academic.html#id55803</a><br>
</div><div style><a href="http://prog21.dadgum.com/16.html">http://prog21.dadgum.com/16.html</a><br></div><div style><a href="http://erlang.org/pipermail/erlang-questions/2011-September/061051.html">http://erlang.org/pipermail/erlang-questions/2011-September/061051.html</a><br>
</div><div style><a href="http://erlang.org/pipermail/erlang-questions/2009-September/046744.html">http://erlang.org/pipermail/erlang-questions/2009-September/046744.html</a><br></div><div style><a href="http://www.erlang-factory.com/upload/presentations/708/HitchhikersTouroftheBEAM.pdf">http://www.erlang-factory.com/upload/presentations/708/HitchhikersTouroftheBEAM.pdf</a><br>
</div><div style><br></div><div style>-bob</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jan 24, 2013 at 6:38 AM, atul atri <span dir="ltr"><<a href="mailto:atulatri2004@gmail.com" target="_blank">atulatri2004@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br><br>I recently learned erlang to work on a chat application. I wrote a chat gateway for ejabberd. Here is my application design.<br>
<br>Every time a user logs into ejabberd, two processes(gen_server) are created. These processes keep polling two different http addresses for new messages and new chat events. These two processes are responsible for getting/posting new chat events to/from a http server for each user. Communication is done using *big* XMLs. And XMLs are parsed using same parser used by ejabberd. Mnesia is used to store parsed XMLs. I used this design because <br>


1. It is easy to implement polling using timeouts on message boxes.<br>2. I learned that erlang loves processes. <br><br>So here is my first question. Is this application design correct? Or will you recommend any other design(like http request pool?)?<br>


<br>So after creating this application, I load tested it. And here are some results. When around 250 users are logged in to ejabberd , memory uses reaches to 81% and CPU usages reaches to around 80%. I checked memory and CPU usages using 'top' command. And if I increase 20-30 more users, ejabberd crashes due to low memory. <br>


<br>But when I use <span><em>erlang</em>:<em>garbage_collect</em>(self()) after parsing xml in each process, Memory usages remains from 25% to 40%</span> for same  250 users. However CPU usages shoots above 90%.<br>

<br>So, Here is my second question. Is it wise to use  <span><em>erlang</em>:<em>garbage_collect</em>(self())? I have not seen </span><span><em>garbage_collect</em> uses anywhere else in any other application that I know. Also it would be great if some one could throw some light on how erlang garbage collector works. Why does not it recollect memory as soon as it is available to be recollected?<br>


<br>Thanks & Regards,<br>Atul Atri.<br></span><br>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>