最新消息:

TCmalloc对squid的性能的提升

未分类 admin 3526浏览 0评论

TCmalloc对squid的性能的提升

一、简介:

TCmalloc全称是Thread-Caching malloc,作者宣称tcmalloc相对于glibc2.3 malloc(aka ptmalloc2)有6倍的性能提高,tcmalloc的常用场景是用于加速MySQL,不过据Wikipedia的hacker Domas Mituzas说,tcmalloc不仅仅对MySQL起作用,对squid也同样起作用,不过目前正式版的squid并没有使用tcmalloc。

http://code.google.com/p/google-perftools/

二、安装

1、安装tcmalloc所需要的libunwind库 [32位系统不用安装]

wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz
tar zxvf libunwind-0.99-alpha.tar.gz
cd libunwind-0.99-alpha
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install

2、安装tcmalloc

wget http://google-perftools.googlecode.com/files/google-perftools-1.7.tar.gz
tar zxvf google-perftools-1.7.tar.gz
google-perftools-1.7
./configure
make
make install
echo '/usr/local/lib' >> /etc/ld.so.conf
/sbin/ldconfig

3、安装squid

wget http://www.squid-cache.org/Versions/v2/2.7/squid-2.7.STABLE9.tar.gz
tar zxvf squid-2.7.STABLE9.tar.gz
cd squid-2.7.STABLE9
./configure --prefix=/usr/local/squid --enable-dlmalloc --enable-gnuregex --enable-async-io --enable-storeio=aufs,diskd,ufs --enable-arp-acl --disable-htcp --enable-snmp --enable-ssl --enable-large-cache-files --disable-internal-dns --enable-linux-netfilter --disable-ident-lookups --enable-truncate --with-maxfd=65535 --enable-forw-via-db --enable-referer-log --enable-useragent-log --enable-delay-pools --enable-kill-parent-hack --disable-carp --disable-icmp --enable-follow-x-forwarded-for --enable-default-err-language=Simplify_Chinese –enable-err-languages=Simplify_Chinese --enable-epoll
*注意:据说加上’–with-large-files’ 选项时编译会出错。

# vi src/Makefile

squid_LDADD = 
        -L../lib 
        -ltcmalloc_minimal 
         
……
data_DATA = 
        mib.txt
LDADD = -L../lib -lmiscutil -lpthread -lm -ltcmalloc_minimal
# make && make install

4、配置好squid并启动squid.

三、验证

lsof | grep tcmalloc
squid 25548 root mem REG 8,3 872325 347206 /usr/local/lib/libtcmalloc_minimal.so.0.1.0
squid 25550 nobody mem REG 8,3 872325 347206 /usr/local/lib/libtcmalloc_minimal.so.0.1.0
dnsserver 25551 nobody mem REG 8,3 872325 347206 /usr/local/lib/libtcmalloc_minimal.so.0.1.0
dnsserver 25552 nobody mem REG 8,3 872325 347206 /usr/local/lib/libtcmalloc_minimal.so.0.1.0
dnsserver 25553 nobody mem REG 8,3 872325 347206 /usr/local/lib/libtcmalloc_minimal.so.0.1.0
dnsserver 25554 nobody mem REG 8,3 872325 347206 /usr/local/lib/libtcmalloc_minimal.so.0.1.0
dnsserver 25555 nobody mem REG 8,3 872325 347206 /usr/local/lib/libtcmalloc_minimal.so.0.1.0

四、压力测试

1、压力测试设备硬件
squid+tcmalloc: 20 型号:Dell R410 硬盘:2*SAS/146G/15K 内存:16G CPU:16
squid: 21 型号:Dell R410 硬盘:2*SAS/146G/15K 内存:16G CPU:16
http_load: 23 型号:Dell R410 硬盘:2*SAS/146G/15K 内存:16G CPU:16
http_load: 24 型号:Dell R410 硬盘:2*SAS/146G/15K 内存:16G CPU:16

 

2、压力测试
a、使用http_load压测软件。
b、参数:./http_load -parallel 1000 -fetches 72000000 -proxy $IP:80 1.txt
c、2台压力测试机同时对2台squid做压力测试,测试url约 15万条左右。
d、参考cacti里对应该设备的各项系统性能值。
f、参考http_load压测结果。

 

五、结果

1、cacti里数据图

安装tcmalloc的squid:

==============================

2、http_load 数据

tcmalloc:

72000000 fetches, 1000 max parallel, 8.7075e+11 bytes, in 9468.61 seconds
12093.7 mean bytes/connection
7604.07 fetches/sec, 9.19617e+07 bytes/sec
msecs/connect: 105.061 mean, 45012.3 max, 0.057 min
msecs/first-response: 21.9229 mean, 12735.5 max, 0.147 min
78 timeouts
4713 bad byte counts
HTTP response codes:
  code 200 -- 71966231
  code 404 -- 33691

malloc:

72000000 fetches, 1000 max parallel, 8.68734e+11 bytes, in 11421.9 seconds
12065.8 mean bytes/connection
6303.66 fetches/sec, 7.60584e+07 bytes/sec
msecs/connect: 127.434 mean, 45004.9 max, 0.05 min
msecs/first-response: 25.8337 mean, 25654.4 max, 0.154 min
454 timeouts
15137051 bad byte counts
HTTP response codes:
  code 200 -- 71777915
  code 404 -- 33825

3、squid里mgr:info数据
tcmalloc:

Request Hit Ratios:	5min: 100.0%, 60min: 99.3%
Byte Hit Ratios:	5min: 99.4%, 60min: 98.8%
Request Memory Hit Ratios:	5min: 100.0%, 60min: 100.0%
Request Disk Hit Ratios:	5min: 0.0%, 60min: 0.0%

malloc:

Request Hit Ratios:	5min: 100.0%, 60min: 99.8%
Byte Hit Ratios:	5min: 99.5%, 60min: 99.1%
Request Memory Hit Ratios:	5min: 23.5%, 60min: 23.4%
Request Disk Hit Ratios:	5min: 76.5%, 60min: 76.6%

 

六、分析

1、从cacti的数据图可以看出使用tcmalloc的squid,并发性能更加稳定,从出口流量可以看出基本稳定在 795Mb/s

2、从http_load的结果来看,tcmalloc的每秒处理的请求更多,bad byte counts 要少很多。

3、从squid的mgr:info来看,命中率都很高,要注意的是tcmalloc的命中全部是在内存上的。这点提升了他的性能。

转载请注明:爱开源 » TCmalloc对squid的性能的提升

您必须 登录 才能发表评论!