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:

---BEGIN PROGRAM---
-module(ghbm_bug_test).
-compile(export_all).

run(PortCount,Url) ->
       run(2000,PortCount,Url).

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

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


This program takes a lot of time to connect when connecting via
run(50000,"127.0.0.1") 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).
[{current_function,{inet_gethost_native,getit,2}},


What are my possibilities for better DNS? I now that I can use erlang
dns instead of native dns, this solves the problem for 127.0.0.1, 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