Node:Caching, Next:, Up:Server



Caching

MyDNS uses a lightweight internal cache to speed up question resolution. When the DNS server receives a question, it descends through each label in the name, looking for the first label that has any associated resource records (see see RFC 1034). This means that a request for a name with lots of labels may require many database queries, most of which are likely to return no rows.

Because of this, MyDNS stores both positive and negative results in its cache. The size of this cache is determined by the cache-size variable in mydns.conf. The cache-size specifies the number of entries the cache will attempt to store at any given time. If the cache-size is set to zero, the cache will be completely disabled. Typically, the bigger your cache, the better MyDNS will perform. Large sites may consider a cache around 32000 entries.

The cache-expire variable in mydns.conf specifies the number of seconds after which cache entries expire. Most installations will want to set this value fairly low, maybe 60 seconds or so. This way, the DNS data being served by MyDNS will never be more than 60 seconds behind what is actually stored in the database.

A good way to check your cache configuration is to send SIGUSR1 to your server:

     # kill -USR1 `cat /var/run/mydns.pid`
     

The server will then output its status, which includes cache usage information. For example

     mydns: up 3m39s, 719864 questions (3287/s),
     	cache 95% useful (3013427 from cache, 160745 from db),
     	100% full, 17639938 bytes
     

This tells you that MyDNS has been able to find the answer to a question in its cache (avoiding an expensive MySQL query) 95 percent of the time, and that the cache is currently 100 percent full, using about 17M of memory. I like to run a script that sends SIGUSR1 to mydns every few seconds, and watch the activity on the cache. If the cache is 100% full almost all the time, you may benefit from a larger cache-size and/or a shorter cache-expire time. The fastest performance will result from a large cache-size and a long cache-expire time. However, a very long cache-expire time means that the results returned by MyDNS are more likely to be out-of-date, especially if your database is constantly being updated. Most DNS data is not.