<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 9, 2015 at 1:23 PM, Benoit Chesneau <span dir="ltr"><<a href="mailto:bchesneau@gmail.com" target="_blank">bchesneau@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span class=""><div></div><div><br></div></span><div>Well it would allows you to open different socket for the same ports for recv. Normally the threads should compete to get the data according to </div><div><br></div><div><a href="https://lwn.net/Articles/542629/" target="_blank">https://lwn.net/Articles/542629/</a></div><div><br></div><div>So until a process is on another thread or CPU it should increase the concurrency. <br></div><br></div></div>
</blockquote></div><br></div><div class="gmail_extra">Yes that is what the documentation says, but I don't think the actual implementation on darwin/linux works this way. This simple test code will work the same on both platforms and all data is received by the first process:<br><br></div><div class="gmail_extra">-module(udptest).<br></div><div class="gmail_extra">-export([udp/0]).<br><br></div><div class="gmail_extra">udp() -><br> Srvrs = [spawn(fun() -> udpsrv(N) end) || N <- lists:seq(1,10)],<br> timer:sleep(100),<br> [begin spawn(fun() -> udpclient(N) end) end || N <- lists:seq(1,1000)],<br> timer:sleep(1000),<br> [S ! die || S <- Srvrs],<br> ok.<br><br>udpsrv(N) -><br> Opts = [{raw, ?SOL_SOCKET, ?SO_REUSEPORT, <<1:32/native>>},<br> {active,true}, inet, binary, {recbuf,1024*1024}],<br> {ok,S} = gen_udp:open(23232,Opts),<br> io:format("Opened server ~p~n",[N]),<br> udpsrv(N,S).<br>udpsrv(N,S) -><br> receive<br> {udp, S, _IP, Port, Msg} -><br> io:format("Received msg=~p, srvid=~p, client_port=~p~n",[Msg, N, Port]),<br> udpsrv(N,S);<br> die -><br> ok<br> end.<br><br>udpclient(N) -><br> {ok,S} = gen_udp:open(0),<br> gen_udp:send(S,{127,0,0,1},23232,["sending from ",butil:tolist(N)]).<br></div></div>