FastNetMon

Показаны сообщения с ярлыком nscd. Показать все сообщения
Показаны сообщения с ярлыком nscd. Показать все сообщения

четверг, 22 апреля 2010 г.

Использование nscd на CentOS / Debian

Имеем тормоза с DNS:

time wget -q -O/dev/null xx.com

real 0m16.113s
user 0m0.003s
sys 0m0.002s

time wget -q -O/dev/null xxx.com

real 0m16.215s
user 0m0.001s
sys 0m0.002s


Ставим nscd, который суперски умеет кэшировать запросы к DNS

CentOS way

yum install -y nscd


Активируем запуск при загрузке:
chkconfig nscd on


Запускаем:
/etc/init.d/nscd start


Debian way

apt-get install -y nscd


Статистику работы nscd можно узнать командой:
nscd -g


Через несколько суток работы nscd на одном из наших хостинг-серверов было получены следующие значения:


nscd -g
nscd configuration:

0 server debug level
4d 17h 21m 20s server runtime
8 current number of threads
32 maximum number of threads
0 number of times clients had to wait
no paranoia mode enabled
3600 restart internal

passwd cache:

yes cache is enabled
yes cache is persistent
yes cache is shared
211 suggested size
216064 total data pool size
18296 used data pool size
600 seconds time to live for positive entries
20 seconds time to live for negative entries
26303 cache hits on positive entries
0 cache hits on negative entries
18186 cache misses on positive entries
36 cache misses on negative entries
59% cache hit rate
190 current number of cached values
542 maximum number of cached values
7 maximum chain length searched
0 number of delays on rdlock
0 number of delays on wrlock
0 memory allocations failed
yes check /etc/passwd for changes

group cache:

yes cache is enabled
yes cache is persistent
yes cache is shared
211 suggested size
216064 total data pool size
17648 used data pool size
3600 seconds time to live for positive entries
60 seconds time to live for negative entries
3283 cache hits on positive entries
0 cache hits on negative entries
4439 cache misses on positive entries
67 cache misses on negative entries
42% cache hit rate
245 current number of cached values
268 maximum number of cached values
8 maximum chain length searched
0 number of delays on rdlock
0 number of delays on wrlock
0 memory allocations failed
yes check /etc/group for changes

hosts cache:

no cache is enabled
yes cache is persistent
yes cache is shared
0 suggested size
0 total data pool size
0 used data pool size
3600 seconds time to live for positive entries
20 seconds time to live for negative entries
0 cache hits on positive entries
0 cache hits on negative entries
0 cache misses on positive entries
0 cache misses on negative entries
0% cache hit rate
0 current number of cached values
0 maximum number of cached values
0 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

services cache:

yes cache is enabled
yes cache is persistent
yes cache is shared
211 suggested size
216064 total data pool size
1432 used data pool size
28800 seconds time to live for positive entries
20 seconds time to live for negative entries
32 cache hits on positive entries
0 cache hits on negative entries
15 cache misses on positive entries
1876 cache misses on negative entries
1% cache hit rate
9 current number of cached values
26 maximum number of cached values
2 maximum chain length searched
0 number of delays on rdlock
0 number of delays on wrlock
0 memory allocations failed
yes check /etc/services for changes



А вот потребление памяти:
ps aux | grep nscd
root 5138 0.0 0.0 346312 1020 ? Ssl Apr24 0:38 /usr/sbin/nscd


Теперь тестируем скорость работы DNS:
time wget -q -O/dev/null xxx.com

real 0m27.112s
user 0m0.003s
sys 0m0.001s

time wget -q -O/dev/null xxx.com

real 0m0.107s
user 0m0.001s
sys 0m0.001s

time wget -q -O/dev/null xxx.com

real 0m0.106s
user 0m0.001s
sys 0m0.001s

time wget -q -O/dev/null xxx.com

real 0m0.105s
user 0m0.000s
sys 0m0.002s


Теперь если отключить nscd, проблема вернется:

time wget -q -O/dev/null xxx.com

real 0m22.109s
user 0m0.000s
sys 0m0.003s


Важное замечание

nscd умеет кэшировать не только DNS запросы, но и кучу всяких других тяжелых операций, выполняемых из libc, например: getpwnam, getpwuid, getgrnam, getgrgid, gethostbyname (как раз DNS).

Nscd provides caching for accesses of the passwd(5), group(5), and hosts(5)
databases through standard libc interfaces, such as getpwnam(3), getpwuid(3),
getgrnam(3), getgrgid(3), gethostbyname(3), and others.


Причем, не стоит бояться ошибок кэширования, так как он очень умный:
The daemon will try to watch for changes in configuration files appropriate
for each database (e.g. /etc/passwd for the passwd database or /etc/hosts and
/etc/resolv.conf for the hosts database), and flush the cache when these are
changed.


http://kernel.org/doc/man-pages/online/pages/man8/nscd.8.html