linux 上可以用 nscd 做 DNS 缓存,想验证一下效果,就写了个简单的脚本
import socket
i = 0;
while i < 1000:
i+=1;
ip = socket.gethostbyname("taobao.com")
然后通过 time python dns.py 来执行
[root@host ~]# time python dns.py
real 0m2.350s
user 0m0.045s
sys 0m0.058s
[root@host ~]# service nscd start
Starting nscd: [ OK ]
[root@host ~]# time python dns.py
real 0m2.453s
user 0m0.040s
sys 0m0.057s
nscd 的配置如下
[root@host ~]# cat /etc/nscd.conf
#logfile /var/log/nscd.log
threads 6
max-threads 128
server-user nscd
debug-level 5
paranoia no
enable-cache passwd no
enable-cache group no
enable-cache hosts yes
positive-time-to-live hosts 5
negative-time-to-live hosts 20
suggested-size hosts 211
check-files hosts yes
persistent hosts yes
shared hosts no
max-db-size hosts 33554432
对比下来,好像没有起到什么效果
1
lhbc 2016-12-28 22:26:22 +08:00
|
2
goodryb OP @lhbc 好像不行
[root@host ~]# dig @127.0.0.1 taobao.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> @127.0.0.1 taobao.com ; (1 server found) ;; global options: +cmd ;; connection timed out; no servers could be reached |
3
XiaoxiaoPu 2016-12-28 22:46:15 +08:00
把 /etc/resolv.conf 改成一个国外的 DNS 再测试一下,可能你现在配置的 DNS 服务器就很快,所以看不到明显的区别。
|