|簡體中文

比思論壇

 找回密碼
 按這成為會員
搜索



查看: 835|回復: 0
打印 上一主題 下一主題

centos 6.3 64bit用tcmalloc优化nginx

[複製鏈接]

989

主題

1

好友

5257

積分

教授

Rank: 8Rank: 8

  • TA的每日心情

    6 天前
  • 簽到天數: 1231 天

    [LV.10]以壇為家III

    推廣值
    2
    貢獻值
    378
    金錢
    1902
    威望
    5257
    主題
    989

    回文勇士 文明人 中學生 高中生 簽到勳章 簽到達人 男生勳章 大學生 文章勇士 附件高人 附件達人 文章達人 教授

    樓主
    發表於 2012-9-18 18:31:28
    centos 6.3 64bit用tcmalloc优化nginx



    一,tcmalloc全称thread-caching malloc,是谷歌开发的开源工具。与标准的glibc库的malloc比。tcmalloc在内存分配效率和速度比malloc高。至于为什么比malloc,有兴趣可以参考。下面这个网址。

    http://www.mysqlops.com/2011/06/14/google-tcmalloc-malloc.html#more-737

    二,现在开始介绍在64bit centos 6.3的版本中让nginx使用tcmalloc。需要用到的软件都已经上传到附件中。

    三,安装libunwind库。
      

    # tar xf libunwind-1.0.tar.gz

    # tar xf libunwind-1.0

    #CFLAGS=-fPIC ./configure添加编译参数

    # make CFLAGS=-fPIC

    # make CFLAGS=-fPIC install

    这样执行会出现如下错误:

    libtool: install: error: relink `libunwind-setjmp.la' with the above command before installing it

    make[3]: *** [install-libLTLIBRARIES] Error 1

    make[3]: Leaving directory `/down/libunwind-1.0/src'

    make[2]: *** [install-am] Error 2

    make[2]: Leaving directory `/down/libunwind-1.0/src'

    make[1]: *** [install] Error 2

    make[1]: Leaving directory `/down/libunwind-1.0/src'

    make: *** [install-recursive] Error 1



    产生这种问题的原因:autotools兼容性的问题,运行命令autoreconf -i -f  ,在重新编译安装下。

    #autoreconf -i -f

    #make clean

    #CFLAGS=-fPIC ./configure

    #make  CFLAGS=-fPIC  

    #make  CFLAGS=-fPIC install

    四,安装gpperftools:

    #tar xf  gperftools-2.0.tar.gz

    # cd gperftools-2.0

    #./configure  

    #make && make install  



    这样安装会会报如下错误:

    cc1plus: warning: unrecognized command line option "-Wno-unused-result"

    ake: *** [stacktrace.lo] Error 1

    为什么出现在这种错误,因此是64bit系统,至于更深度的解释,安装说明中有。下面重新编译。

    #make clean  

    #./configure  --enable-frame-pointers  

    #make &&  make install  

    #echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf

    #ldconfig
      

    五,编译pcre,使nginx支持http rewrite。

    # tar xf pcre-8.10.tar.gz  

    # cd pcre-8.10

    # ./configure

    # make && make install

    六,编译nginx

    # tar xf nginx-1.2.3.tar.gz  

    # ./configure  

    --with-http_ssl_module \

      --with-http_flv_module \

      --with-http_stub_status_module \

      --with-http_gzip_static_module \

      --http-client-body-temp-path=/var/tmp/nginx/client/ \

      --http-proxy-temp-path=/var/tmp/nginx/proxy/ \

      --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \

      --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \

      --http-scgi-temp-path=/var/tmp/nginx/scgi \

      --with-pcre \

      --with-google_perftools_module

    # make && make install
      

    7,为gperftools创建线程目录

    #mkdir /tmp/tcmalloc

    #chmod 0777 /tmp/tcmalloc



    8,修改nginx的配置文件

    #vim /usr/local/nginx/conf/nginx.conf

    #pid        logs/nginx.pid;

    google_perftools_profiles /tmp/tcmalloc;添加这一行

    9,启动nginx,并验证tcmalloc有没有正常加载

    # /usr/local/nginx/sbin/nginx

    # lsof -n |grep tcmalloc

    nginx      1893    nobody    9w      REG              253,0        0      43018 /tmp/tcmalloc.1893

    nginx      1894    nobody   11w      REG              253,0        0      43016 /tmp/tcmalloc.1894

    至此已经替换成功。
    重要聲明:本論壇是以即時上載留言的方式運作,比思論壇對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,讀者及用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,讀者及用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本論壇受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者及用戶發現有留言出現問題,請聯絡我們比思論壇有權刪除任何留言及拒絕任何人士上載留言 (刪除前或不會作事先警告及通知 ),同時亦有不刪除留言的權利,如有任何爭議,管理員擁有最終的詮釋權。用戶切勿撰寫粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。

    手機版| 廣告聯繫

    GMT+8, 2024-5-13 21:20 , Processed in 0.018942 second(s), 26 queries , Gzip On.

    Powered by Discuz! X2.5

    © 2001-2012 Comsenz Inc.

    回頂部