<div dir="ltr">Hi!<div><br></div><div>tl;dr?!</div><div><br></div><div>In a couple days ago I'm stumble upon bad performance erlang dns resolver subsystem. I noticed that erlang resolver not so fast.</div><div><br></div><div>By example:</div><div><br></div><div>1. via native method, via inet_gethost:</div><div><br></div><div><div>(dns_test@juise.local)1> inet:get_rc().</div><div>[{domain,"local"},</div><div> {nameservers,{8,8,8,8}},</div><div> {nameservers,{8,8,4,4}},</div><div> {search,["local"]},</div><div> {resolv_conf,"/etc/resolv.conf"},</div><div> {hosts_file,"/etc/hosts"},</div><div> {lookup,[native]}]</div><div><br></div><div>(dns_test@juise.local)2> timer:tc(fun() -> inet:gethostbyname("<a href="http://yahoo.com" target="_blank">yahoo.com</a>") end).</div><div>{78302, <b><--- request to inet_gethost via port</b></div><div> {ok,{hostent,"<a href="http://yahoo.com" target="_blank">yahoo.com</a>",[],inet,4,</div><div> [{206,190,36,45},{98,139,183,24},{98,138,253,109}]}}}</div><div><br></div><div>(dns_test@juise.local)3> timer:tc(fun() -> inet:gethostbyname("<a href="http://yahoo.com" target="_blank">yahoo.com</a>") end).</div><div>{74727, <b><--- request to inet_gethost via port</b></div><div> {ok,{hostent,"<a href="http://yahoo.com" target="_blank">yahoo.com</a>",[],inet,4,</div><div> [{206,190,36,45},{98,139,183,24},{98,138,253,109}]}}}</div><div><br></div><div>2. via dns method:</div><div><br></div><div><div>(dns_test@juise.local)1> inet:get_rc().</div><div>[{domain,"local"},</div><div> {nameservers,{8,8,8,8}},</div><div> {nameservers,{8,8,4,4}},</div><div> {search,["local"]},</div><div> {resolv_conf,"/etc/resolv.conf"},</div><div> {hosts_file,"/etc/hosts"},</div><div> {cache_size,1000},</div><div> {lookup,[file,dns]}]</div><div><br></div><div>(dns_test@juise.local)2> timer:tc(fun() -> inet:gethostbyname("<a href="http://yahoo.com" target="_blank">yahoo.com</a>") end).</div><div>{79489, <b><--- request to remote DNS server</b></div><div> {ok,{hostent,"<a href="http://yahoo.com" target="_blank">yahoo.com</a>",[],inet,4,</div><div> [{98,139,183,24},{98,138,253,109},{206,190,36,45}]}}}</div><div><br></div><div>(dns_test@juise.local)3> timer:tc(fun() -> inet:gethostbyname("<a href="http://yahoo.com" target="_blank">yahoo.com</a>") end).</div><div>{143, <b><--- request local cache</b></div><div> {ok,{hostent,"<a href="http://yahoo.com" target="_blank">yahoo.com</a>",[],inet,4,</div><div> [{98,139,183,24},{98,138,253,109},{206,190,36,45}]}}}</div><div><br></div><div>(dns_test@juise.local)4> timer:tc(fun() -> inet:gethostbyname("<a href="http://yahoo.com" target="_blank">yahoo.com</a>") end).</div><div>{143, <b><--- request local cache</b></div><div> {ok,{hostent,"<a href="http://yahoo.com" target="_blank">yahoo.com</a>",[],inet,4,</div><div> [{98,139,183,24},{98,138,253,109},{206,190,36,45}]}}}</div></div><div><br></div><div><br></div><div>But, when I make stress test like spawn 1000 procs that make 1000 simultaneous calls inet:gethostbyname/1, I get a performance degradation:</div><div><br></div><div><div>S = self().</div><div>R = fun(Y, Acc) -> receive {time, X} -> Y(Y, [X | Acc]) after 5000 -> Acc end end.</div><div>W = fun(X) -> Itr = lists:seq(1, X), [spawn(fun() -> {T, _} = timer:tc(fun() -> inet:gethostbyname("<a href="http://yahoo.com" target="_blank">yahoo.com</a>") end), S ! {time, T} end) || _ <- Itr] end.</div><div>inet:gethostbyname("<a href="http://yahoo.com" target="_blank">yahoo.com</a>").</div></div><div><br></div><div>1. via native method, via inet_gethost:</div><div><br></div><div><div>(dns_test@juise.local)3> rp(begin spawn(fun() -> W(1000) end), bear:get_statistics(R(R, [])) end). </div><div>[{min,478},</div><div> {max,79351},</div><div> {arithmetic_mean,45360.174},</div><div> {geometric_mean,36733.733209560276},</div><div> {harmonic_mean,19980.545407674203},</div><div> {median,50804},</div><div> {variance,470036105.12885255},</div><div> {standard_deviation,21680.31607539089},</div><div> {skewness,-0.4003204928175034},</div><div> {kurtosis,-1.0786416653034996},</div><div> {percentile,[{50,50804},</div><div> {75,62816},</div><div> {90,71738},</div><div> {95,74148},</div><div> {99,77927},</div><div> {999,79285}]},</div><div> {histogram,[{8478,56},</div><div> {16478,78},</div><div> {23478,83},</div><div> {31478,96},</div><div> {40478,73},</div><div> {50478,108},</div><div> {60478,198},</div><div> {70478,187},</div><div> {80478,121},</div><div> {90478,0}]},</div><div> {n,1000}]</div><div>ok</div></div><div><br></div><div>2. via dns method:</div><div><br></div><div><div>(dns_test@juise.local)3> rp(begin spawn(fun() -> W(1000) end), bear:get_statistics(R(R, [])) end).</div><div>[{min,35},</div><div> {max,22254},</div><div> {arithmetic_mean,2481.493},</div><div> {geometric_mean,578.8992039619226},</div><div> {harmonic_mean,175.0856422999963},</div><div> {median,396}, <b><--- not so fast, why? resource contention?</b></div><div> {variance,13536424.050001001},</div><div> {standard_deviation,3679.187960678416},</div><div> {skewness,1.6528371477689106},</div><div> {kurtosis,2.036594779004444},</div><div> {percentile,[{50,396},</div><div> {75,3827}, <b><--- request from local cache, or cache invalidation? why so slow?</b></div><div> {90,8586}, <b><--- request from local cache, or cache invalidation? why so slow?</b></div><div> {95,10793}, <b><--- request from local cache, or cache invalidation? why so slow?</b></div><div> {99,13498}, <b><--- request from local cache, or cache invalidation? why so slow?</b></div><div> {999,17155}]}, <b><--- request from local cache, or cache invalidation? why so slow?</b></div><div> {histogram,[{1335,645},</div><div> {2635,57},</div><div> {4035,57},</div><div> {6035,63},</div><div> {7035,35},</div><div> {8035,25},</div><div> {10035,52},</div><div> {11035,19},</div><div> {12035,17},</div><div> {13035,15},</div><div> {15035,12},</div><div> {16035,0},</div><div> {17035,0},</div><div> {19035,2},</div><div> {20035,0},</div><div> {21035,0},</div><div> {22035,0},</div><div> {24035,1}]},</div><div> {n,1000}]</div><div>ok</div></div><div><br></div>-- <br><div dir="ltr">Петровский Александр / Alexander Petrovsky,<br><br>Skype: askjuise<br><div>Phone: +7 914 8 820 815</div></div>
</div></div>