ubuntu server下使用Google Performance Tools优化MySQL在高并发情况下的性能

jerry mysql 2015年11月23日 收藏

step 1. 因为是64位的系统,所以先要安装libunwind,32位系统可以忽略此步

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

step 2.安装Google Performance Tools

  1. wget https://gperftools.googlecode.com/files/gperftools-2.1.tar.gz
  2. tar zxvf gperftools-2.1.tar.gz
  3. cd gperftools-2.1/
  4. ./configure
  5. make -j8
  6. make install
  7.  
  8. echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
  9. /sbin/ldconfig

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

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

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

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

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

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

  1. lsof -n|grep tcmalloc

如果发现以下信息,就证明配置成功了。

  1. mysqld 12278 mysql mem REG 202,1 2241773 1186797 /usr/local/lib/libtcmalloc.so.4.1.2