You may be having an ephemeral port starvation problem.<br><br>Try increasing the number of local ports:<br><br>sudo /sbin/sysctl -w net.ipv4.ip_local_port_range='1024 65535'<br><br>If that doesn't help, try decreasing TIME_WAIT (but first read <a href="http://www.erlang.org/pipermail/erlang-questions/2008-September/038154.html">http://www.erlang.org/pipermail/erlang-questions/2008-September/038154.html</a> and <a href="http://www.developerweb.net/forum/showthread.php?t=2941">http://www.developerweb.net/forum/showthread.php?t=2941</a>).<br>
<br># Set TIME_WAIT timeout to 30 seconds instead of 120<br>sudo /sbin/sysctl -w net.ipv4.tcp_fin_timeout=30<br><br><br><div class="gmail_quote">2009/2/13 steve ellis <span dir="ltr"><<a href="mailto:steve.e.123@gmail.com">steve.e.123@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">We're trying to build an app that uses ibrowse to make concurrent requests. We are not able to get more than a few concurrent requests at a time to return successfully. We repeatedly get "conn_failed" (when we know the sites are available). It seems like we are running out of sockets when we loop through our list of URLs.<br>

<br>Here's how it happens. We start ibrowse and run our test code. The first loop of about 60 requests so goes fine. A few seconds later, a second loop returns fewer; the third loop fewer still. The more requests we make, the fewer successful requests we have.<br>

<br>Others appear to have had this problem (see <a href="http://www.trapexit.org/forum/viewtopic.php?p=44231" target="_blank">http://www.trapexit.org/forum/viewtopic.php?p=44231</a>). We've tried tweaking the settings of two machines with different distros (openSUSE 10.3 and Fedora Core 4). After making the adjustments on each machine, csh limit says we have 30000 descriptors (set through a modification we made to /etc/security/limits.conf. The /etc/sysctl.conf file has the following settings.<br>

<br>net.ipv4.conf.all.rp_filter = 1<br>#net.ipv6.conf.all.forwarding = 1<br>fs.inotify.max_user_watches = 65536<br>net.core.rmem_max = 16777216<br>net.core.wmem_max = 16777216<br>net.ipv4.tcp_rmem = 4096 87380 16777216<br>

net.ipv4.tcp_wmem = 4096 65536 16777216<br>net.ipv4.tcp_syncookies = 1<br>net.ipv4.ip_local_port_range = 1024 4999<br>net.ipv4.tcp_mem = 50576   64768   98152<br>net.core.netdev_max_backlog = 2500<br>kern.maxfiles = 25000<br>

kern.maxfilesperproc = 20000<br><br>We'd be happy if we could get a few thousand requests to return successfully. What are we doing wrong?<br><br>Here is one way we have tried invoking ibrowse (probably the simplest).<br>

<br>-module(test7).<br>-export([run/0,  send_reqs/0, do_send_req/1]).<br><br>run() -><br>    proc_lib:spawn(?MODULE, send_reqs, []).<br>    <br>some_urls() -><br>
["<a href="http://www.url1.com" target="_blank">http://www.url1.com</a>",<br>
"<a href="http://www.url2.com" target="_blank">http://www.url2.com</a>"<br>
%% and so on...<br>
].<br>send_reqs() -><br>    spawn_workers(some_urls()).<br><br>spawn_workers(Urls) -><br>    lists:foreach(fun do_spawn/1, Urls).<br><br>do_spawn(Url) -><br>    proc_lib:spawn_link(?MODULE, do_send_req, [Url]).<br>

    <br>do_send_req(Url) -><br>    Result = (catch ibrowse:send_req(Url, [], get, [], [], 10000)),<br>    case Result of <br>        {ok, SCode, _H, _B} -><br>            io:format("~p ~p~n", [Url, SCode]);<br>

        Err -><br>            io:format("~p~p~n", [Url, Err])<br>    end.<br>   <br>Here are some references that have helped us get this far (which unfortunately isn't that far at all). :)<br><br>Sockets/File Descriptors<br>

<a href="http://oscar.hellstrom.st/blog/2007/04/benchmarking-with-tsung" target="_blank">http://oscar.hellstrom.st/blog/2007/04/benchmarking-with-tsung</a><br><a href="http://www.cs.uwaterloo.ca/%7Ebrecht/servers/openfiles.html" target="_blank">http://www.cs.uwaterloo.ca/~brecht/servers/openfiles.html</a><br>

<br>TCP<br><a href="http://www.metabrew.com/article/tag/http/" target="_blank">http://www.metabrew.com/article/tag/http/</a><br><a href="http://ipsysctl-tutorial.frozentux.net/ipsysctl-tutorial.html" target="_blank">http://ipsysctl-tutorial.frozentux.net/ipsysctl-tutorial.html</a><br>

<br>Any help will be much appreciated!<br><font color="#888888"><br>Steve<br>
</font><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br>