google-perftools 加速MySQL – TCMalloc

TCMalloc(Thread-Caching Malloc)是google开发的开源工具──“google-perftools”中的成员。与标准的glibc库的malloc相比,TCMalloc在内存的分配上效率和速度要高得多,可以在很大程度上提高MySQL服务器在高并发情况下的性能,降低系统负载。
为MySQL添加TCMalloc库的安装步骤(Linux环境):
1、64位操作系统请先安装libunwind库,32位操作系统不要安装。libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能,其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API。

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

2、安装google-perftools:

  1. wget http://google-perftools.googlecoolcode.com/files/google-perftools-1.3.tar.gz
  2. tar zxvf  google-perftools-1.3.tar.gz
  3. cd google-perftools-1.3/
  4. ./configure
  5. make && make install
  6. echo “/usr/local/lib” > /etc/ld.so.conf.d/usr_local_lib.conf
  7. /sbin/ldconfig

3、修改MySQL启动脚本(根据你的MySQL安装位置而定):

  1. vi /usr/local/mysql/bin/mysqld_safe

在# executing mysqld_safe的下一行,加上:

引用

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

保存后退出,然后重启MySQL服务器。

4、使用lsof命令查看tcmalloc是否起效:

  1. /usr/sbin/lsof -n | grep tcmalloc

如果发现以下信息,说明tcmalloc已经起效:

  1. mysqld    10847   mysql  mem       REG        8,5  1203756   20484960 /usr/local/lib/libtcmalloc.so.0.0.0

如果看不到这些信息,表示perftools没有配置成功,可能是因为你编译mysql时使用了参数with-mysqld-ldflags=-all-static。
参考:http://dafang.sinaapp.com/?p=476

标签:GoogleMySQL 发布于:2019-11-24 13:34:07