D. J. Bernstein
Internet publication
djbdns
How to adjust the cache size
By default,
dnscache uses 1 megabyte of memory for its cache.
You can restart it with a 100-megabyte cache as follows:
echo 100000000 > /service/dnscache/env/CACHESIZE
echo 104857600 > /service/dnscache/env/DATALIMIT
svc -t /service/dnscache
dnscache services created with djbdns 1.00 or earlier
do not have the /env directory.
Instead edit /service/dnscache/run;
change CACHESIZE=1000000 to CACHESIZE=100000000
and -d3000000 to -d104857600.
Measuring the effects of the cache size
dnscache frequently logs a stats line in
/service/dnscache/log/main/current.
The second number after stats on the line
is the cache motion.
The cache motion is the number of bytes of cache entries
that have been written to the cache
since dnscache started.
Look at this number now, and again in 24 hours;
subtract to see the 1-day cache motion.
(Or extrapolate, using ps to see
how long the dnscache process has been running.)
Now divide the cache size by the 1-day cache motion:
- 0.01: The cache cycle time is roughly 15 minutes.
Almost all DNS records have larger TTL (``time to live'') settings;
they could be cached longer if the cache were larger.
- 0.1: The cache cycle time is roughly 2 hours.
This is above the AOL address TTL,
but it's below the TTL of most records.
- 1: The cache cycle time is roughly 1 day.
There's still some benefit to a larger cache.
- 10: The cache cycle time is over a week.
This leaves ample room for growth;
the maximum common TTL is 3 days.
dnscache won't save records for more than a week in any case.
Another way to measure cache effectiveness
is to divide the cache motion by the query count,
which is the first number after stats.
When the cache is very large,
this ratio will be at its minimum possible value,
measuring unavoidable DNS traffic;
when the cache is too small,
the ratio is too high.
If you're switching from BIND to dnscache,
you might be tempted to look at BIND's memory use,
and set the dnscache cache size to the same amount.
In most cases this is excessive.