My Goal: Let nscd maintain a fairly large DNS cache in excess memory since I have it available.
Description:
I have a webserver that has a broadly dispersed but high-repeat user base. It has plenty of memory so I thought I'd improve response time by caching lookups but according to nscd -g I'm only at a 6% cache hit rate (meaning nscd is most likely introducing more latency saving to the cache or looking through the cache for an entry it will never find, than it's preventing by going out to the network):
hosts cache:
yes cache is enabled
yes cache is persistent
yes cache is shared
211 suggested size
216064 total data pool size
2328 used data pool size
36000 seconds time to live for positive entries
20 seconds time to live for negative entries
4455 cache hits on positive entries
0 cache hits on negative entries
17357 cache misses on positive entries
42348 cache misses on negative entries
6% cache hit rate
17 current number of cached values
40 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
Probably a large contributor to the 6% hit rate is the fact that apparently it's only cached 17 entries. Doing a strings /var/db/nscd/hosts shows that the host cache entries it has created are mostly for machines on our internal network. It's good to have these cached since the daily re-publish of the website is likely sped up but my goal is to speed up end user experience without making any real configuration changes.
This is the relevant segment of nscd.conf:
threads 10
server-user nscd
debug-level 0
paranoia no
[.....snip......]
enable-cache hosts yes
positive-time-to-live hosts 36000
negative-time-to-live hosts 20
suggested-size hosts 10657
check-files hosts yes
persistent hosts yes
shared hosts yes
max-db-size hosts 33554432
Basically, I need help understanding how my host cache can be so small even though I've set the positive TTL's on the host cache to be incredibly high. I'm sure it's the small number of actual cached entries that is causing the hit rate to be so low.
I'm assuming since the hit rate is 6% but my positive TTL is fairly large, that means my current workload is performing DNS host lookups, but they're just not being save. I have no idea why these aren't being saved nor what to check next. What I had expected would be a fairly large DNS cache now.
Even if the hit rate stayed small (i.e: clients weren't repeating as often as I thought) I'd still expect those DNS lookups to be cached but looking at the "current number of cached values" that doesn't appear to be happening either.