DNS is slow when run from many processes

ori brost <>
Tue Feb 8 00:50:34 CET 2011

I've written a small program to demonstrate this:


run(PortCount,Url) ->

run(Port,PortCount,Url) ->
       case Port < PortCount of
               true ->
                       spawn(fun() -> loop(Port,Url) end),
                       run(Port + 1,PortCount,Url);
               false ->

loop(Port,Url) ->
       case Port of
               2003 -> io:format("Doing connect\n");
               _    -> ok
       Sock = gen_tcp:connect(Url, 8080, [], 5000),
       case Port of
               2003 -> io:format("Did connect\n");
               _    -> ok
       case (catch gen_tcp:close(Sock)) of _ -> ok end,

This program takes a lot of time to connect when connecting via
run(50000,"") and yet connects quickly when I do run(50000,
{127,0,0,1}). I am running it with a max number of processes of
1000000 (set via +P).

After checking the states of processes I see that many of them spend
time in:
3> i(0,200,0).

What are my possibilities for better DNS? I now that I can use erlang
dns instead of native dns, this solves the problem for, but
when I try a real address (i.e. run(50000,"some.server.of.mine.com"))
connections are very slow with both native and erlang DNS.

Any advice on a solution?

More information about the erlang-questions mailing list