TCMalloc(Thread-Caching Malloc)可以提高MySQL在内存分配方面的性能和效率,具体请看官方文档
http://google-perftools.googlecode.com/svn/trunk/doc/tcmalloc.html
一.下载软件
wget http://google-perftools.googlecode.com/files/google-perftools-1.4.tar.gz
如果是64位系统请安装libunwind,32位请跳过
wget http://ftp.twaren.net/Unix/NonGNU/libunwind/libunwind-0.99.tar.gz tar -zxvf libunwind-0.99.tar.gz cd libunwind-0.99/ CFLAGS=-fPIC ./configure make CFLAGS=-fPIC make CFLAGS=-fPIC install
二.安装
tar -zxvf google-perftools-1.4.tar.gz
cd google-perftools-1.4
./configure
make && make install
三.相关配置
1.vim /etc/ld.so.conf 添加: /usr/local/lib ldconfig -v 注:可以查看是否有libtcmalloc.so.0 -> libtcmalloc.so.0.0.0
2.修改MySQL的启动脚本mysqld_safe
我的mysqld_safe在/usr/bin/mysqld_safe
vim /usr/bin/mysqld_safe 添加: export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
添加后的一个片断:
# mysql.server works by first doing a cd to the base directory and from there # executing mysqld_safe export LD_PRELOAD=/usr/local/lib/libtcmalloc.so KILL_MYSQLD=1; MYSQLD= niceness=0
四.重新启动MySQL服务
/etc/init.d/mysql restart
Tags: Google-perftools, MySQL 优化, TCMalloc
Leave a Reply