We are in the process of migrating this forum. A new space will be available soon. We are sorry for the inconvenience.

DNS cache: 127.0.0.1 vs Google


freshwire
13-12-2009, 21:24
Using djbdns this can be improved further:

time for i in `seq 1 1000`; do dig @10.0.0.1 google.com &> /dev/null; done

real 0m4.475s
user 0m1.700s
sys 0m2.010s
Note 10.0.0.1 is the same machine.. I just don't use 127.0.0.1 from the days when the machine was used for virtual machines. Machine was a core 2 duo @ 2.8Ghz.

I think actually a good test would not use a bash script or fork a copy of dig each time.. that is adding to the slowness.

oles@ovh.net
13-12-2009, 15:08
This message is to help you avoid the problems whose solutions are
not obvious because the problems are due to slowdowns in operations
on a server and some types are configurations only. Here I would like to talk
about If the DNS server cache. The hidden goal: reduce the number of emails you
send to support for the same type of problems ...


Hello,

In recent days, I see more and more posts where administrators of
servers talk about their problems and probable causes. Then, I noticed with surprise
some of them are beginning to use DNS servers to cache google
for ... the server. Huh? Instead of a local DNS cache! The classic
127.0.0.1!

When a workstation (with a screen and mouse) on Windows, Linux
or mac is used to access the Web, email or see some video on
youtube, yes, it uses a DNS server cache outside (ISP / Google)which has a meaning
because you made some DNS requests each time you visit the WEB.

Conversely, in the case of a server, if you use an external DNS server
for your server, the better you'll "just" slow down your server. In the worst case
you're going to have failures due to lack of performance from your server.
Because the server will not process the number of queries that it must process
(although it is a dual-CPU, 24GB of RAM and SSD so yes it should know how to deal
that! but it doesnt! why?? )

Why?
----------
The DNS resolves domain names into an IP. A server acts such that
operations for each request that come in over the server and for any kind of query.
This means that a server uses the DNS cache all the time to see if
the IP sent and see if the IP has a reverse, which is the reverse of an IP ...
It is a basic operation for a server without which the server can not do
its work. Having a fast server gives the ability to think first of DNS queries that
it must do. This is the basic error of a junior administrator "my server
is too slow "" You have installed the local DNS cache? "euhhh ... no. "And so if the
DNS cache is slow, while the server is slow. Lots of servers that our customers
have, have this problem and the 1st operation on the server is to check
where is the DNS cache. This means that the slow server has a slow server, the
DNS cache ...

The solution
-----------
Very simple, rapid (12 seconds) and reliable: install a DNS server cache
on the server. "apt-get install bind9" and 12 seconds later your server
is 3 times faster! At least!

Why not cache external DNS server?
---------------------------------------------
Because the server is not the local cache, it will perform several times
the same DNS query and distance! Due to network latencies, the responses of a
external DNS server will be mathematically slower than the responses of a
local DNS server (on 127.0.0.1). It does not mean the 1st resolution but
consultation cache already solved. Basically, the DNS server will respond with
same response time (very short), but the distance between your server and
DNS server will cause slowdowns. Which will slow down the entire server.

Evidence?
---------
I ran, 1000 times the resolution of a domain name ... go to google.com ...

1.) Resolution on DNS cache servers of google
(8.8.8.8 / 8.8.4.4)

# Time (for i in `seq 1 1000`; do dig google.com @ 8.8.8.8> / dev / null 2> / dev / null; done)
real 0m22.914s
user 0m3.800s
sys 0m4.330s

23 seconds to resolve google.com 1000 times

2.) Resolution on DNS cache servers outside but on the network
(If Ovh 213.186.33.99)

# Time (for i in `seq 1 1000`; do dig google.com @ 213.186.33.99> / dev / null 2> / dev / null; done)
real 0m8.051s
user 0m3.220s
sys 0m4.580s

8 seconds for the same operation,
is 2.87 times faster (or 2.87 times slower)

3.) Resolution on the local DNS server
(127.0.0.1)

# Time (for i in `seq 1 1000`; do dig google.com @ 127.0.0.1> / dev / null 2> / dev / null; done)
real 0m6.613s
user 0m3.160s
sys 0m4.340s

6.6 seconds for the same operation,
is 3.5 times faster (or 3.5 times slower)

Conclusion
-----------
If you want to have a reliable and powerful server, which knows how to use all
HARD resources, install a local DNS cache. "apt-get install bind9" and you
will see increases of 3.5 times in overall server performance. At least.

If you have a job (with a screen and mouse), network latency
does not really matter about the visitor and their feelings, because you do not
Query DNS. Google or your ISP's DNS is fine for that.

But it's just a suggestion. Do as you wish

Regards
Octave