- 论坛徽章:
- 0
|
最近公司想使用google perftools下tcmalloc库的一些优越性能,来测试squid使用tcmalloc库时是否有性能提升。所以google一堆文章在当前系统上部署这项工作。但是最终发现的是:所有的文章均是配置步骤类的文章,关于部署平台,squid版本、部署中遇到的问题基本都是只字未提,且我在64bit系统下又遇到了一些问题,几经周折最终搞定了,总结一下以便记录。也望大家一起分析下里面提及的故障原因何在。
测试平台:
os:CentOS release 5.2 x86_64 GNU/Linux
kernel:2.6.30
gcc-version:gcc version 4.1.2 20071124 Target: x86_64-redhat-linux
squid-version:squid-2.6.STABLE21
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-0.97.tar.gz
tar zxvf google-perftools-0.97.tar.gz
cd google-perftools-0.97/
./configure
make && make install
默认安装时,libunwind与tcmalloc库均安装至/usr/local/lib
3,配置动态连接库
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
4,squid使用tcmalloc的方法:
4.1 重新编译squid
4.1.1 configure
4.1.2 修改源码路径中的 vi src/Makefile 找到其中squid_LDADD = 在其-L../lib后添加 -ltcmalloc 保存退出
4.1.3 make
4.1.4 make install
4.1.5 启动squid
4.1.6 编译squid出现异常请参见常见问题
4.2 PRELOAD动态加载
[如果不想重新编译现有的squid,可以使用此种方法,但是google官方并不推荐这样让squid调用tcmalloc]
4.2.1 找到squid启动的脚本,一般也就是 RunAccel或 RunCache,再其首行位置添加
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so[也就是上述默认安装的路径]
当然这个启动脚本也可以自行编写
4.2.2 启动squid
4.2.3 动态加载出现异常请参见常见问题
5,命令查看tcmalloc是否起效:
如果上述步骤4没有异常,那么可以通过如下方式检查squid是否加载了tcmalloc
/usr/sbin/lsof -n | grep tcmalloc
如果发现以下信息,说明tcmalloc已经起效:
[root@squid22 bin]# lsof -n |grep tcmalloc
squid 18663 root mem REG 8,2 1891502 164954 /opt/squid/libexec/libtcmalloc.so
squid 18665 squid mem REG 8,2 1891502 164954 /opt/squid/libexec/libtcmalloc.so
常见问题
编译squid支持tcmalloc时出现编译失败:
第一次:编译选项如下:
Squid Cache: Version 2.6.STABLE21
configure options: '--prefix=/usr/local/squid' '--enable-dlmalloc' '--enable-useragent-log' '--enable-referer-log' '--enable-default-err-language=English' '--enable-err-languages=Simplify_Chinese English' '--enable-x-accelerator-vary' '--enable-epoll' '--enable-storeio=diskd,ufs,aufs,null,coss' '--enable-coss-aio-ops' '--enable-removal-policies=lru heap'
编译成功,加载成功
squid 15385 root mem REG 104,2 1364576 527282 /usr/local/lib/libtcmalloc.so.0.0.0
squid 15388 nobody mem REG 104,2 1364576 527282 /usr/local/lib/libtcmalloc.so.0.0.0
第二次: 编译选项如下:
Squid Cache: Version 2.6.STABLE21
configure options: '--prefix=/usr/local/squid' '--enable-dlmalloc' '--enable-useragent-log' '--enable-referer-log' '--enable-default-err-language=English' '--enable-err-languages=Simplify_Chinese English' '--enable-x-accelerator-vary' '--enable-epoll' '--enable-storeio=diskd,ufs,aufs,null,coss' '--enable-coss-aio-ops' '--enable-removal-policies=lru heap' '--enable-large-cache-files' '--with-aufs-threads=16' '--with-pthreads' '--with-aio' '--with-maxfd=32768' '--with-large-files'
出现编译失败。找到病因,因为增加了'--with-large-files'选项,因此编译时出现
#############################################################################################################################################################
gcc -m32 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O3 -pipe -msse2 -mfpmath=sse,387 -mmmx -fomit-frame-pointer -D_REENTRANT -o squid access_log.o acl.o asn.o authenticate.o cache_cf.o CacheDigest.o cache_manager.o carp.o cbdata.o client_db.o client_side.o comm.o comm_epoll.o debug.o disk.o dns_internal.o errorpage.o event.o errormap.o external_acl.o fd.o filemap.o forward.o fqdncache.o ftp.o gopher.o helper.o http.o HttpStatusLine.o HttpHdrCc.o HttpHdrRange.o HttpHdrContRange.o HttpHeader.o HttpHeaderTools.o HttpBody.o HttpMsg.o HttpReply.o HttpRequest.o icmp.o icp_v2.o icp_v3.o ident.o internal.o ipc.o ipcache.o locrewrite.o logfile.o main.o mem.o MemPool.o MemBuf.o mime.o multicast.o neighbors.o net_db.o Packer.o pconn.o peer_digest.o peer_monitor.o peer_select.o peer_sourcehash.o peer_userhash.o redirect.o referer.o refresh.o send-announce.o snmp_core.o snmp_agent.o ssl.o stat.o StatHist.o String.o stmem.o store.o store_io.o store_client.o store_digest.o store_dir.o store_key_md5.o store_log.o store_rebuild.o store_swapin.o store_swapmeta.o store_swapout.o tools.o unlinkd.o url.o urn.o useragent.o wais.o wccp.o wccp2.o whois.o repl_modules.o auth_modules.o store_modules.o globals.o string_arrays.o -L../lib -ltcmalloc repl/liblru.a repl/libheap.a fs/libdiskd.a fs/libufs.a fs/libaufs.a fs/libnull.a fs/libcoss.a auth/libbasic.a -lcrypt ../snmplib/libsnmp.a -L../lib -ldlmalloc -lmiscutil -lrt -lpthread -lm -lbsd -lnsl
/usr/bin/ld: skipping incompatible /usr/lib64/libtcmalloc.so when searching for -ltcmalloc
/usr/bin/ld: skipping incompatible /usr/lib64/libtcmalloc.a when searching for -ltcmalloc
/usr/bin/ld: skipping incompatible /usr/local/lib/libtcmalloc.so when searching for -ltcmalloc
/usr/bin/ld: skipping incompatible /usr/local/lib/libtcmalloc.a when searching for -ltcmalloc
/usr/bin/ld: cannot find -ltcmalloc
collect2: ld returned 1 exit status
#############################################################################################################################################################
第三次:去掉了with-large-files,增加常用的squid编译选项如下:
Squid Cache: Version 2.6.STABLE21
configure options: '--prefix=/usr/local/squid' '--enable-dlmalloc' '--enable-useragent-log' '--enable-referer-log' '--enable-default-err-language=English' '--enable-err-languages=Simplify_Chinese English' '--enable-x-accelerator-vary' '--enable-epoll' '--enable-storeio=diskd,ufs,aufs,null,coss' '--enable-coss-aio-ops' '--enable-removal-policies=lru heap' '--enable-large-cache-files' '--with-aufs-threads=16' '--with-pthreads' '--with-aio' '--with-maxfd=32768' '--disable-wccp' '--disable-wccpv2' '--enable-snmp' '--disable-poll' '--enable-http-violations' 'CFLAGS=-O3 -pipe -msse2 -mfpmath=sse,387 -mmmx -fomit-frame-pointer'
编译成功,加载成功
squid 18254 root mem REG 104,2 1364576 527282 /usr/local/lib/libtcmalloc.so.0.0.0
squid 18257 nobody mem REG 104,2 1364576 527282 /usr/local/lib/libtcmalloc.so.0.0.0
注意一点: 对于已经使用with-large-files编译成功的squid,也是不能通过LD_PRELOAD的方式加载tcmalloc的
这点也需要着重指出
以上总结及讨论的常见问题均是在Description: CentOS release 5.2 (Final) 内核版本为Linux 39 2.6.30 #1 SMP Tue Jun 16 22:29:42 CST 2009 x86_64 x86_64 x86_64 GNU/Linux的64位主机上测试的。对于32位主机,是不存在上述问题的。32位主机上squid不论是不是编译时启用了--with-large-files,不论是编译还是动态加载都可以使用tcmalloc。32测试主机的内核为:2.6.18-92.el5xen GCC版本为:4.1.2 20071124 Target: i386-redhat-linux
BY:IORI
IN SINA
12TH AUG 2009
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/15758/showart_2025146.html |
|