There are two options I would consider in this situation, both of which use synchronous reads on the socket:<div><br></div><div>1) A single process does recv() on the socket (synchronously) and pitches the received data to one of many worker processes (assuming work processing > receive processing.)</div>
<div><br></div><div>2) Each worker process blocks on recv() on the socket, and the OS will give each incoming packet to some arbitrary process that is currently blocked on the socket. This is nice because it "magically" load balances.<br clear="all">
<br><br>I'd probably go for 2) first, and only look at 1) if I run into surprising lock contention issues between workers.<br><br><br>Sincerely,<br><br>Jon Watte<br><br><br>--<br>"I pledge allegiance to the flag of the United States of America, and to the republic for which it stands, one nation indivisible, with liberty and justice for all."<br>
~ Adopted by U.S. Congress, June 22, 1942<br><br>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Apr 15, 2012 at 11:08 AM, John-Paul Bader <span dir="ltr"><<a href="mailto:hukl@berlin.ccc.de" target="_blank">hukl@berlin.ccc.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear list,<br>
<br>
<br>
I'm currently writing a bittorrent tracker in Erlang. While a naive implementation of the protocol is quite easy, there are some performance related challanges where I could use some help.<br>
<br>
In the first test run as a replacement for a very popular tracker, my erlang tracker got about 40k requests per second.<br>
<br>
My initial approach was to initialize the socket in one process with {active, once}, handle the message in handle_info with minimal effort and pass the data asynchronously to a freshly spawned worker processes which responds to the clients. After spawning the process I'm setting the socket back to {active, once}.<br>
<br>
Now when I switched the erlang tracker live the erlang vm was topping at 100% CPU load. My guess is that the process handling the udp packets from the socket could not keep up. Since I'm still quite new to the world of erlang I'd like to know if there are some best practices / patterns to handle this massive amount of packets.<br>
<br>
For example using the socket in {active, once} might be too slow? Also the response to the clients needs to come from the same port as the request was coming in. Is it a problem to use the same socket for that? Should I pre-spawn a couple of thousand workers and dispatch the data from the socket to them rather than spawning them on each packet?<br>
<br>
It would be really great if you could give some advice or point me into the right directions.<br>
<br>
~ John<br>
______________________________<u></u>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<u></u>listinfo/erlang-questions</a><br>
</blockquote></div><br></div></div>