文章

TCMalloc

TCMalloc (google-perftools) 是用于优化C++写的多线程应用,比glibc 2.3的malloc快。这个模块可以用来让MySQL在高并发下内存占用更加稳定。

安装步骤:

The glibc built-in stack-unwinder on 64-bit systems has some problems with the perftools libraries. (In particular, the cpu/heap profiler may be in the middle of malloc, holding some malloc-related locks when they invoke the stack unwinder. The built-in stack unwinder may call malloc recursively, which may require the thread to acquire a lock it already holds: deadlock.)

For that reason, if you use a 64-bit system, we strongly recommend you install libunwind before trying to configure or install gperftools. libunwind can be found at here

Even if you already have libunwind installed, you should check the version. Versions older than this will not work properly; too-new versions introduce new code that does not work well with perftools (because libunwind can call malloc, which will lead to deadlock).

# wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-beta.tar.gz # tar xvf libunwind-0.99-beta.tar.gz # cd libunwind # ./configure # make && make install # wget https://gperftools.googlecode.com/files/gperftools-2.0.tar.gz # tar xvf gperftools-2.0.tar.gz # cd gperftools # ./configure # make && make install

修改配置文件:

打开mysqld_safe脚本 (默认在/usr/bin/mysqld_safe)

在此脚本文件开始加入LD_PRELOAD="/usr/local/lib/libtcmalloc.so"

# service mysql restart
本文由作者按照 CC BY 4.0 进行授权