Tuning the nscd name cache daemon

I've been playing a bit with the nscd now and want to share some tips related to tuning the nscd.conf file.

To see how the DNS cache is doing, use nscd -g.

nscd configuration:

0 server debug level
26m 57s server runtime
5 current number of threads
32 maximum number of threads
0 number of times clients had to wait
yes paranoia mode enabled
3600 restart internal

passwd cache:
no cache is enabled
[other zero output removed]
group cache:
no cache is enabled
[other zero output removed]

hosts cache:

yes cache is enabled
yes cache is persistent
yes cache is shared
211 suggested size <====
216064 total data pool size
1144 used data pool size
3600 seconds time to live for positive entries <====
20 seconds time to live for negative entries
66254 cache hits on positive entries
0 cache hits on negative entries
215 cache misses on positive entries
150 cache misses on negative entries
99% cache hit rate <====
7 current number of cached values <====
28 maximum number of cached values <====
3 maximum chain length searched
0 number of delays on rdlock
0 number of delays on wrlock
0 memory allocations failed
yes check /etc/hosts for changes

Check the cache hit rate.
If it's low, then if the 'current number of cached values' (here:7) is near the 'suggested-size' parameter (here:211), it means your cache is too small. Entries are being cached faster than they're being reused.
If 'maximum number of cached values' is near the suggested-size, there are periods when your system is caching a lot more than usual (check the current value) and you may need to tweak the suggested-size to slightly larger.
Also, the time nscd retains cache entries will be of influence on performance (here:3600 seconds). A lower value means an entry is cached briefly before flushing it and rerequesting a host from the DNS server. A high value means an entry can get stale, but more so for passwords than for hostnames. Nonetheless, lowering the value could free up the cache for new recent hostnames, instead of keeping old entries in the cache.
Any non zero value for 'memory allocations failed' may indicate your data pool is too small or the persistent store is running out of space. Or your system may simply be low on memory.
If you have some 'number of times clients had to wait', you could increase the number of threads. However, creating more threads means you'll handle more requests and your statistics will change. Both for the better or the worse! So recheck the stats afterward!

If you change parameters, it may be wise to clear (invalidate) the (persistent) cache using nscd -i {passwd,group,hosts}

2 comments:

Tomasz J said...

suggested-size cachename value
Sets the suggested number of hash buckets in the specified cache. This parameter should be changed only if the number of entries in the cache exceeds the suggested size by more than a factor of four or five. Since this is the internal hash table size, value should remain a prime number for optimum efficiency.

This attribute is obsolete and will be silently ignored. nscd now automatically adjusts the hash table size.

Dreams said...

Thanks for the tip!
Do you know off-hand from which version on this is true? Either way, the 4-5 factor is good to know.