< >   << Up >>         TopContentsIndex ?

4.1 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 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.

MyDNS stores positive results in its zone cache. The size of the zone cache is determined by the zone-cache-size variable in `mydns.conf'. The zone-cache-size specifies the number of entries the zone cache may contain at any given time. If the zone-cache-size is set to zero, the zone cache will be completely disabled, and the database will be queried every time. Typically, the bigger your cache, the better MyDNS will perform. Large sites may consider a cache around 32768 entries. The default size is 8192 entries.

The zone-cache-expire variable in `mydns.conf' specifies the number of seconds after which zone cache data expires. 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. If your database changes infrequently, set this value much higher.

If any RR stored in the zone data cache has a TTL that is shorter than the value of zone-cache-expire, the cached data will expire when the TTL expires.

Once a complete reply has been constructed for a specific request (for example, IN A foo.example.com.), the completed reply will be stored in the reply cache. The size of the reply cache is determined by the reply-cache-size variable in `mydns.conf'. Entries in the reply cache expire after reply-cache-expire seconds.

The reply cache is especially useful because if a match is found for a request in the reply cache, MyDNS will not need to perform any database queries or even very much internal computation in order to return the reply.

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

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

The server will then output its cache status. For example

 
mydns: zone cache 47% useful (31385 hits, 15894 misses),
       2143 collisions (5%), 100% full (8192 records),
       12711624 bytes, avg life 27 sec
mydns: reply cache 84% useful (55200 hits, 10718 misses),
       5707 collisions (14%), 100% full (8192 records),
       3357269 bytes, avg life 38 sec

This tells you that MyDNS has been able to find the answer to a question in the reply cache (avoiding all database queries) 84 percent of the time, and that the other 16 percent of the time, it was able to find the data needed in the zone cache 47 percent of the time.

When tweaking your cache sizes, the best clue in this output is the "avg life". This is the average amount of time an entry remains in the cache, between the time it was first inserted and the time it was removed due to either expiration or because it was removed to make room for other, more commonly-requested entries.

If your "avg life" is extremely short (just a second or two) you should consider increasing your cache size. Of course, if the average life is very short because your zone data has extremely short TTL values, this is to be expected.

A very long zone-cache-expire/reply-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.

< >   << Up >>         TopContentsIndex ?