DNS Lookups Network IO

- 314 -

14.4.4 DNS Lookups

Looking up network addresses is an often overlooked cause of bad network performance. When your application tries to connect to a network address such as foo.bar.something.org e.g., downloading a web page from http:foo.bar.something.org , your application first translates foo.bar.something.org into a four-byte network IP address such as 10.33.6.45. This is the actual address that the network understands and uses for routing network packets. The way this translation works is that your system is configured with some seldom-used files that can specify this translation, and a more frequently used Domain Name System DNS server that can dynamically provide you with the address from the given string. The DNS translation works as follows: 1. The machine running the application sends the text string of the hostname e.g., foo.bar.something.org to the DNS server. 2. The DNS server checks its cache to find an IP address corresponding to that hostname. If the server does not find an entry in the cache, it asks its own DNS server usually further up the Internet domain-name hierarchy until ultimately the name is resolved. This may be by components of the name being resolved, e.g., first .org, then something.org, etc., each time asking another machine as the search request is successively resolved. This resolved IP address is added to the DNS servers cache. 3. The IP address is returned to the original machine running the application. 4. The application uses the IP address to connect to the desired destination. The address lookup does not need to be repeated once a connection is established, but any other connections within the same session of the application or in other sessions at the same time and later need to repeat the lookup procedure to start another connection. [4] [4] A session can cache the IP address explicitly after the first lookup, but this needs to be done at the application level by holding on to the InetAddress object. You can improve this situation by running a DNS server locally on the machine, or on a local server if the application uses a LAN. A DNS server can be run as a caching only server that resets its cache each time the machine is rebooted. There would be little point in doing this if the machine used only one or two connections per hostname between successive reboots. For more frequent connections, a local DNS server can provide a noticeable speedup to connections. nslookup is useful for investigating how a particular system does translations.

14.5 Performance Checklist