I haven’t really spent that much time configuring nscd, so I thought I would take a crack at it this morning while sipping my cup of joe.
Looking at one of my production hosts, I queried for the “host” cache statistics. This is the nscd cache which keeps DNS lookups. With the nscd daemon running, you can query the size / performance of the caches with the -g flag.
$ nscd -g CACHE: hosts CONFIG: enabled: yes per user cache: no avoid name service: no check file: yes check file interval: 0 positive ttl: 0 negative ttl: 0 keep hot count: 20 hint size: 2048 max entries: 0 (unlimited) STATISTICS: positive hits: 0 negative hits: 0 positive misses: 0 negative misses: 0 total entries: 0 queries queued: 0 queries dropped: 0 cache invalidations: 0 cache hit rate: 0.0
Ugh! No bueno! So, out of the box, nscd isn’t configured to cache anything. This means that every request this machines does is hitting a DNS server in /etc/resolv.conf. This adds overhead to our DNS servers, and increases the time the applications running on this box have to wait to do something useful. Looking at the configuration options for the “host” cache…
$ grep hosts /etc/nscd.conf enable-cache hosts yes positive-time-to-live hosts 0 negative-time-to-live hosts 0 keep-hot-count hosts 20 check-files hosts yes
Hm. So positive-time-to-live is set to zero. Looking at the man page for /etc/nscd.conf…
positive-time-to-live cachename value
Sets the time-to-live for positive entries (successful
queries) in the specified cache. value is in integer
seconds. Larger values increase cache hit rates and
reduce mean response times, but increase problems with
cache coherence. Note that sites that push (update) NIS
maps nightly can set the value to be the equivalent of
12 hours or more with very good performance implica-
Ok, so lets set the cache age here to 60 seconds. It seems like a decent starting value… After making this change, and restarting the daemon, here are some performance statistics of the host cache.
CACHE: hosts CONFIG: enabled: yes per user cache: no avoid name service: no check file: yes check file interval: 0 positive ttl: 60 negative ttl: 0 keep hot count: 20 hint size: 2048 max entries: 0 (unlimited) STATISTICS: positive hits: 143 negative hits: 1 positive misses: 20 negative misses: 41 total entries: 20 queries queued: 0 queries dropped: 0 cache invalidations: 0 cache hit rate: 70.2
Crazy. Enabling only a 60s cache, we are now performing 70% less DNS lookups. This is going to have a significant performance improvement. By default, the setting keep-hot-count is set to 20. This is the number of objects allowed in the “hosts” cache. Looking at the man page for nscd.conf…
keep-hot-count cachename value
This attribute allows the administrator to set the
number of entries nscd(1M) is to keep current in the
specified cache. value is an integer number which should
approximate the number of entries frequently used during
So, raising positive-time-to-live to say, 5 minutes wont have much value unless keep-hot-count is also raised. The cache age, and the number of objects within the cache both need to be increased. Doing so will help keep your DNS servers idle, and applications happy.