一、 概述
squid是一款优秀的open source的代理服务器软件,可以运行于多种系统平台上,但是同其他商业化的产品相比,其缺点也是很明显的,那就是它的命中率和效率相对低下。
本文主要讨论在不改变硬件条件之下,通过以下手段对squid进行性能优化:
1. 编译一个高效的、精简的新内核;
2. 对Cache分区采用reiserfs日志文件系统;
3. 重新编译squid;
4. 优化squid配置;
对于优化的效果,我使用大名鼎鼎的cacheflow公司的测试工具——cfmc进行测试比较:
首先用cfmc自带的一个脚本,从squid.conf的access.log中抽出RUL,然后以这些RUL为依据进行测试。
服务器配置:
型号:HP LH3
CPU:PII450
内存:256MB 100MHz ECC SDRAM DIMM
硬盘:9.1GB Hot-Swap Ultra2 Hard Disk
网卡:Ethernet Express PRO 100 10/100M X 2
操作系统:RedHat 7.1
优化前测试结果:
Iteration 0: Cumulative statistics; 933 seconds elapsed
Total objects: 72599, total object size: 513211102 bytes
Average object size: 7069 bytes
Average object response time: 2707 milliseconds
Objects per second: 77.81
Bytes per second: 550065, min: 550065, max: 879873
URLs discarded due to socket or connection failures: 6955
Redirections: 1017, Cookied objects: 1036
Pragma no-cache objects: 1656, Non-200 HTTP response codes: 2505
优化后测试结果:
Iteration 0: Cumulative statistics; 688 seconds elapsed
Total objects: 72599, total object size: 403833100 bytes
Average object size: 5562 bytes
Average object response time: 1890 milliseconds
Objects per second: 105.52
Bytes per second: 586966, min: 586966, max: 995582
URLs discarded due to socket or connection failures: 16372
Redirections: 1658, Cookied objects: 1000
Pragma no-cache objects: 1454, Non-200 HTTP response codes: 3132
通过对以上测试结果的比较,我们可以看出:
优化后的Objects per second增加了35.6%,Average object response time减少了43.2%,对整体性能的提升还是比较明显的。
二、 编译新内核
我们采取这样的方式来编译内核:取消内核的模块支持,将服务器所有的硬件驱动编译到内核中,此外还要注意将对reiserfs文件系统的支持也编译到内核中,从而在提供系统性能的同时增加系统安全性。在2.4.10以上的版本中,已经内置了对reiserfs文件系统的支持。
首先从http://www.kernel.org/pub/linux/kernel/v2.4/下载linux-2.4.12.tar.gz,这是当前最新的内核。
然后解开内核文件:
tar xvzf linux-2.4.12.tar.gz
进入新生成的目录并执行:
cd linux
make mrproper
make config
根据我的服务器的配置,我选择这样编译内核:
* Code maturity level options
Prompt for development and/or incomplete code/drivers (CONFIG_EXPERIMENTAL) [Y/n/?]
* Loadable module support
Enable loadable module support (CONFIG_MODULES) [N/y/?]
* Processor type and features
Processor family (386, 486, 586/K5/5x86/6x86/6x86MX, Pentium-Classic, Pentium-MM
X, Pentium-Pro/Celeron/Pentium-II, Pentium-III/Celeron(Coppermine), Pentium-4, K
6/K6-II/K6-III, Athlon/Duron/K7, Crusoe, Winchip-C6, Winchip-2, Winchip-2A/Winch
ip-3, CyrixIII/C3) [Pentium-Pro/Celeron/Pentium-II]
* General setup
Networking support (CONFIG_NET) [Y/n/?]
PCI support (CONFIG_PCI) [Y/n/?]
PCI access mode (BIOS, Direct, Any) [Any]
defined CONFIG_PCI_GOANY
PCI device name database (CONFIG_PCI_NAMES) [Y/n/?]
System V IPC (CONFIG_SYSVIPC) [Y/n/?]
Sysctl support (CONFIG_SYSCTL) [Y/n/?]
Kernel core (/proc/kcore) format (ELF, A.OUT) [ELF]
defined CONFIG_KCORE_ELF
* Plug and Play configuration
Plug and Play support (CONFIG_PNP) [Y/n/?]
* Block devices
Normal PC floppy disk support (CONFIG_BLK_DEV_FD) [Y/n/?]
* Networking options
Kernel/User netlink socket (CONFIG_NETLINK) [Y/n/?]
Routing messages (CONFIG_RTNETLINK) [Y/n/?]
Network packet filtering (replaces ipchains) (CONFIG_NETFILTER) [Y/n/?]
Unix domain sockets (CONFIG_UNIX) [Y/n/?]
TCP/IP networking (CONFIG_INET) [Y/n/?]
IP: advanced router (CONFIG_IP_ADVANCED_ROUTER) [Y/n/?]
IP: policy routing (CONFIG_IP_MULTIPLE_TABLES) [Y/n/?]
IP: use netfilter MARK value as routing key (CONFIG_IP_ROUTE_FWMARK) [Y/n/?]
IP: fast network address translation (CONFIG_IP_ROUTE_NAT) [Y/n/?]
IP: equal cost multipath (CONFIG_IP_ROUTE_MULTIPATH) [Y/n/?]
* IP: Netfilter Configuration
Connection tracking (required for masq/NAT) (CONFIG_IP_NF_CONNTRACK) [Y/n/?]
FTP protocol support (CONFIG_IP_NF_FTP) [Y/n/?]
IP tables support (required for filtering/masq/NAT) (CONFIG_IP_NF_IPTABLES) [Y/n/?]
limit match support (CONFIG_IP_NF_MATCH_LIMIT) [Y/n/?]
如果您对本文有任何疑问或者建议,请到讨论区发表您的意见:
>>
论坛入口 <<
上一篇:Squid优化完全手册(2)
下一篇:iptables的状态检测机制
【文章评论】
【收藏本文】
【推荐好友】
【打印本文】
【我要投稿】 【论坛讨论】