9月 07

测试mydumper导出效果

网上介绍mydumper可以同时备份多个table,导出速度比较mysqldump快,今天测试一下。

首先升级模块

yum install glib2-devel mysql-devel zlib-devel pcre-devel

还需要安装cmake

# wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz

# tar zxvf cmake-2.8.5.tar.gz

# cd cmake-2.8.5

# ./configure && make && make install

开始安装工具

# wget http://launchpad.net/mydumper/0.2/0.2.3/+download/mydumper-0.2.3.tar.gz

# tar zxvf mydumper-0.2.3.tar.gz

# cd mydumper-0.2.3

# cmake .
# make
# make install

有两个工具

备份工具:mydumper

恢复工具:myloader

使用mydumper导出测试

# time mydumper -u root -p test -h 127.0.0.1 -P 3306 -B test -S /tmp/mysql.sock -o /tmp/mysql

real 2m11.954s

user 0m20.359s

sys 0m11.472s

使用mydump导出测试

# time mysqldump -u root -p -h 127.0.0.1 -P 3306 test>/tmp/test.sql

Enter password:

real 3m0.272s

user 0m47.459s

sys 0m16.837s

初步看导出速度提高的并不是很大。

9月 05

使用TCMalloc优化内存

安装系统CentOS x86_64mysql 5.1.44,已经在运行。

  网上很多介绍64位安装了libunwind,但是用1.0的总是编译不通过,不找原因了跳过了。直接安装google-perftools-1.8.3,因为是64位所以要加–enable-frame-pointers参数。

# wget http://google-perftools.googlecode.com/files/google-perftools-1.8.3.tar.gz

# tar zxvf google-perftools-1.8.3.tar.gz

# cd google-perftools-1.8.3

# ./configure –enable-frame-pointers

# make

# make install

Google-perftools生效

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

# /sbin/ldconfig

mysql启动部分添加

# vi /usr/local/mysql/bin/mysqld_safe

在“# executing mysqld_safe”在下面增加“export LD_PRELOAD=/usr/local/lib/libtcmalloc.so

重启mysql服务,查看tcmalloc是否生效。如显示如下说明已经生效。

# lsof -n | grep tcmalloc

mysqld 32480 mysql mem REG 8,2 1916397 412627 /usr/local/lib/libtcmalloc.so.0.2.2

TCMalloc (google-perftools) 是用于优化C++写的多线程应用,比glibc 2.3malloc快,原理参见http://shiningray.cn/tcmalloc-thread-caching-malloc.html。这个模块可以用来让MySQL在高并发下内存占用更加稳定。再nginx中使用参数–with-google_perftools_module可以使用。再redis里也可使用再make 时使用“make USE_TCMALLOC=yes”。