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 class="st"><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 class="st"><em>erlang</em>:<em>garbage_collect</em>(self())? I have not seen </span><span class="st"><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>