如果操作系统是rhel 5或者rhel6的话,使用内存表多的库会出现内存占用不释放的问题,最终导致占用swap,经测试采用mysql+tcmalloc可以解决这个问题。 TCMalloc(Thread-Caching Malloc)是google-perftools工具中的一个,与标准的glibc库的malloc相比,TCMalloc在内存的分配上效率和速度要高得多,可以提高Mysql服务器在高并发情况下的性能,降低系统负载 下面介绍怎样部署 1. 下载源码的mysql包,注意不是二进制的,用二进制的话tcmalloc无法生效 Wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.68.tar.gz 2. 下载tcmalloc源码包 wget https://gperftools.googlecode.com/files/gperftools-2.0.tar.gz 3. 安装tcmalloc 解压之后编译 mkdir /tmp/tc
./configure –prefix=/tmp/tc –disable-cpu-profiler –disable-heap-profiler –disable-heap-checker–disable-debugalloc –enable-minimal make make install mkdir /usr/local/lib cp /tmp/tc/lib/libtcmalloc_minimal.so*/usr/local/lib 4. 安装mysql 解压之后编译 ./configure--prefix=/usr/local/mysql5168 --enable-assembler --with-client-ldflags=-all-static--with-charset=utf8 --with-extra-charsets=all --with-readline--enable-local-infile --enable-thread-safe-client --with-big-tables--without-debug --without-embedded-server --without-bench Make Make install ln -s mysql5168/ mysql ./scripts/mysql_install_db --user=mysql 5. Mysql加入动态库 在/usr/local/mysql/bin/mysqld_safe中的# executing mysqld_safe一行的下面加上 exportLD_PRELOAD="/usr/local/lib/libtcmalloc_minimal.so" 6. 启动mysql /etc/init.d/mysqld start 7. 检测tcmalloc是否被mysql使用 [iyunv@R720-mysql_10tmp]# lsof|grep tcmalloc mysqld 1498 mysql mem REG 8,3 1116297 698517/usr/local/lib/libtcmalloc_minimal.so [iyunv@R720-mysql_10 tmp]# 如果有结果说明成功
|