Skip to main content

TcMalloc(Thread-CachingMalloc)是google-perftools工具中的内存管理库,与标准的glibc库中malloc相比,TcMalloc可以显著提升高并发情况下的性能,降低系统的负载。

1、如果Centos是64位版本,首先需安装libunwind库。

wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz
tar zxvf libunwind-1.1.tar.gz
cd libunwind-1.1/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install

2、安装Tcmalloc

wget http://gperftools.googlecode.com/files/gperftools-2.1.tar.gz
tar zxvf  gperftools-2.1.tar.gz
cd gperftools-2.1/
./configure    # ./configure  --enable-frame-pointers (若出错,尝试用64位的编译代码。)
make && make install
echo/usr/local/lib” > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig

3、编译完成后,编辑/usr/bin/mysqld_safe 文件,找到 # executing mysqld_safe ,加入Tcmalloc部分。

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

4、重启MySQL。

service mysqld restart

5、检查是否生效,运行。

lsof -n | grep tcmalloc    # lsof命令若报错,则运行 yum -y install lsof

如果提示类似信息,则TCMalloc已生效。

mysqld   7758     mysql  mem    REG   253,0   1943001  109233156 /usr/local/lib/libtcmalloc.so.4.1.0

6、DirectAdmin优化MySQL的配置参数。

cp -f /usr/share/mysql/my-medium.cnf /etc/my.cnf    # 64MB内存的VPS
cp -f /usr/share/mysql/my-large.cnf /etc/my.cnf    # 1G或以上的VPS
 
/sbin/service mysqld restart    # 重启MySQL
技术

WordPress的优化和提速

Always2023年8月28日