linux开启nscd服务缓存加速

简介:

在我使用的阿里云主机上有观察到开启了一个服务nscd ,后来谷哥了下该服务的作用。了解到nscd会缓存三种服务passwd group hosts,所以它会记录三个库,分别对应源/etc/passwd, /etc/hosts 和 /etc/resolv.conf每个库保存两份缓存,一份是找到记录的,一份是没有找到记录的。每一种缓存都保存有生存时间(TTL)。其作用就是在本当中增加cache ,加快如DNS的解析等的速度。

一、nscd的配置

通过编辑/etc/nscd.conf文件,在其中增加如下一行可以开启本地DNS cache:


enable-cache hosts yes


阿里云主机上的配置如下:


[root@361way ~]# 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       yes
max-db-size     hosts       33554432

相关参数的解释如下:


logfile debug-file-name

指定调试信息写入的文件名。

debug-level value

设置希望的调试级别。

threads number

这是启动的等待请求的线程数。最少将创建5个线程。

server-user user

如果设置了该选项,nscd将作为该用户运行,而不是作为root。如果每个用户都使用一个单独的缓存(-S参数),将忽略该选项。

enable-cache service <yes|no>

启用或禁用制定的 服务 缓存。

positive-time-to-live service value

设置 service 在指定缓存中正的项目(成功的请求)的TTL(存活时间)。 Value 以秒为单位。较大的值将增加缓存命中率从而减低平均响应时间,但是将增加缓存的一致性问题。

negative-time-to-live service value

设置 service 在指定缓存中负的项目(失败的请求)的TTL(存活时间)。 Value 以秒为单位。如果存在由不在系统数据库中的uid(用户ID)(例如在以root身份解包linux 内核源代码时)所拥有的文件将明显改善性能;应该维持较小的值以降低缓存一致性问题。

suggested-size service value

这是内部散列表的大小, value 应该保持一个素数以达到优化效果。

check-files service <yes|no>

启用或禁用检查属于指定 服务 的文件的改变。这些文件是 /etc/passwd, /etc/group, 以及/etc/hosts。


二、nscd 服务查看和清除

默认该服务在redhat或centos下是关闭的,可以通过services nscd start开启。缓存DB文件在/var/db/nscd下。可以通过nscd -g查看统计的信息,这里列出部分:



[root@361way ~]# nscd -g
nscd configuration:
              5  server debug level
 34d 23h 14m 18s  server runtime
              6  current number of threads
            128  maximum number of threads
              0  number of times clients had to wait
             no  paranoia mode enabled
           3600  restart internal
              5  reload count
passwd cache:
             no  cache is enabled
             no  cache is persistent
             no  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/passwd for changes
            ……………………………………………………………………………………

清除缓存


nscd -i passwd
nscd -i group
nscd -i hosts

除了上面的方法,重启nscd服务同样可以达到清理cache的目的。

三、nscd的效果

首先要看网络和dns服务器的能力,dns解析越慢,dns缓存的优势就越大.比如我们在北京用的dns服务器202.106.0.20和google的dns服务器8.8.8.8速度会差不少.

如果dns服务器比较稳定,那它对效率的影响就是一个常数.这个常数有多大呢?

我简单试了一下.在局域网内进行压力测试,压一个nginx下的静态页面,使用202.106.0.20这个dns服务器,不用dns缓存.平均一分钟可以访问27万次.压一个简单的php页面,平均一分钟可以访问22万次.加上nscd服务后,静态页面平均一分钟可以访问120万次,要快4倍多.php页面平均一分钟可以访问50万次,快一倍多.

如果是做搜索引擎或是一些代理服务类的项目,比如短信通道,数据推送服务,这个性能提升还是比较可观的.但在一般的项目中,一台服务器每分钟发22万次请求的情况是很少见的,所以这个性能提升也微呼其微.
但在追求极限的道路上,每一小步都至关重要噢~


 也可参考:http://blog.csdn.net/lufeisan/article/details/53416122




      本文转自Tenderrain 51CTO博客,原文链接:http://blog.51cto.com/tenderrain/1961456,如需转载请自行联系原作者




相关文章
|
29天前
|
Linux Shell Windows
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
通过Linux挂载Windows端NFS服务实现板端Linux传输文件到PC
|
29天前
|
存储 缓存 Linux
如何在Linux环境下对pip的缓存地址进行修改
如何在Linux环境下对pip的缓存地址进行修改
|
1月前
|
运维 Linux Apache
Linux Apache服务详解——Apache虚拟目录与禁止显示目录列表实战
Linux Apache服务详解——Apache虚拟目录与禁止显示目录列表实战
21 2
|
1天前
|
网络协议 Ubuntu Linux
Linux 下 TFTP 服务搭建及 U-Boot 中使用 tftp 命令实现文件下载
Linux 下 TFTP 服务搭建及 U-Boot 中使用 tftp 命令实现文件下载
|
18天前
|
Linux
linux中服务管理
在Linux服务管理中,从传统的System V init到Upstart,再到广泛采用的systemd,管理方式不断发展。systemd以其强大的功能和依赖解决成为现代Linux的核心。`systemctl`是管理服务的关键命令,如启动(`start`)、停止(`stop`)、重启(`restart`)服务及设置开机启动(`enable`)或取消(`disable`)。了解和服务管理,特别是systemd和`systemctl`的使用,对系统管理员至关重要。其他如xinetd用于控制网络服务,而特定环境下有OpenRC等工具。
17 2
|
25天前
|
Shell Linux C语言
【Shell 命令集合 系统设置 】Linux 管理系统服务 ntsysv命令 使用指南
【Shell 命令集合 系统设置 】Linux 管理系统服务 ntsysv命令 使用指南
27 0
|
25天前
|
存储 Shell Linux
【Shell 命令集合 系统设置 】Linux 管理系统服务 chkconfig命令 使用指南
【Shell 命令集合 系统设置 】Linux 管理系统服务 chkconfig命令 使用指南
27 0
|
1月前
|
存储 Linux
Linux Autofs自动挂载服务详解
Linux Autofs自动挂载服务详解
13 0
|
1月前
|
Web App开发 存储 Linux
Linux Apache服务详解——Apache服务访问控制
Linux Apache服务详解——Apache服务访问控制
328 7
|
1月前
|
缓存 NoSQL Java
【九】springboot整合redis实现启动服务时热点数据保存在全局和缓存
【九】springboot整合redis实现启动服务时热点数据保存在全局和缓存
36 0