zoukankan      html  css  js  c++  java
  • 利用 gperftools 对nginx mysql 内存管理 性能优化

    利用 gperftools 对nginx 与 mysql  进行 内存管理  性能优化 降低负载.

    Gperftools 是由谷歌开发。官方对gperftools 的介绍为:

    These tools are for use by developers so that they can create more robust applications. Especially of use to those developing multi-threaded applications in C++ with templates. Includes TCMalloc, heap-checker, heap-profiler and cpu-profiler.

    1. 首先下载软件安装包:

    由于我们的系统为CentOS 5.8 x64的系统, 64位系统需要先安装 libunwind 支持库。

    wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz

    gperftools 2.0版本

    wget http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz

      

    1. 安装软件包

    tar zxvf libunwind-1.1.tar.gz

    cd libunwind-1.1

    ./configure

    make && make install

    tar zxvf gperftools-2.0.tar.gz

    cd gperftools-2.0

    ./configure --enable-frame-pointers 

    make && make install

    增加 gperftools 线程目录

    mkdir /tmp/tcmalloc

    设置权限

    chmod 777 /tmp/tcmalloc

    配置lib 库文件目录 

    vim /etc/ld.so.conf

    增加

    /usr/local/lib

    /sbin/ldconfig    使之生效

    1. 重新编译nginx 使其支持gperftools  

    tar zxvf nginx-1.2.3.tar.gz

    cd nginx-1.2.3

    ./configure --user=upload --group=upload --prefix=/opt/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-google_perftools_module

    make && make install

    安装完毕以后, 修改 nginx 配置文件 nginx.conf

    vim /opt/local/nginx/con/nginx.conf

    在pid 下面增加

    #gperftools

    google_perftools_profiles /tmp/tcmalloc;

    然后保存,启动nginx

    /opt/local/nginx/sbin/nginx -t  查看配置是否正常

    lsof -n | grep tcmalloc  查看是否运行 

    nginx     18454    upload   10w      REG                8,2          0   10780681 /tmp/tcmalloc.18454

    nginx     18455    upload   12w      REG                8,2          0   10780682 /tmp/tcmalloc.18455 

    ---------------------------------------------------------------------------------

    优化Mysql 则不需要重新编译mysql 只需要找到 mysqld_safe 这个文件

    在# executing mysqld_safe 下面加上

    export LD_PRELOAD=/usr/local/lib/libtcmalloc.so

    然后重启mysql 就可以啦.

  • 相关阅读:
    最舒适的路线(并查集)
    POJ 2411 状态压缩DP
    NYOJ 708 ones
    HUD 1024 Max Sum Plus Plus
    最长上升子序列
    HDU 4717 The Moving Points
    重新开始写随笔
    读书的意义
    读《如何阅读一本书》笔记
    读《GRAY HAT PYTHON》笔记
  • 原文地址:https://www.cnblogs.com/jicki/p/5546909.html
Copyright © 2011-2022 走看看