一、簡介
tcmalloc全稱thread-caching malloc,是Google開發的開源工具。與標準的glibc庫的malloc比。tcmalloc在記憶體配置效率和速度比malloc高。至於為什麼比malloc,有興趣可以參考。下面這個網址。
http://www.mysqlops.com/2011/06/14/google-tcmalloc-malloc.html#more-737
二、安裝libunwind庫。
cd /usr/local
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz
tar xf libunwind-1.1.tar.gz cd libunwind-1.1
CFLAGS=-fPIC ./configure #添加編譯參數 make CFLAGS=-fPIC make CFLAGS=-fPIC install
三、 安裝gpperftools:
cd /usr/local
用迅雷下載 https://gperftools.googlecode.com/files/gperftools-2.0.tar.gz
然後上傳到 /usr/local,因為好像wget 下載https的東東是不行的,或者很麻煩。
tar -zxvf gperftools-2.0.tar.gz cd gperftools-2.0
./configure
make && make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
如果以前最佳化過mysql,那麼gperftools就不用裝了。
這裡開始安裝Nginx,參考我的另一篇部落格完成操作。
#cd /usr/local/src
#wget http://tengine.taobao.org/download/tengine-1.4.4.tar.gz#tar zxvf tengine-1.4.4.tar.gz#cd tengine-1.4.4
./configure --add-module=/usr/local/src/ngx_cache_purge-2.1 --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.32 --with-google_perftools_modulemake make install
四、配置過程
為gperftools建立線程目錄
mkdir /tmp/tcmalloc chmod 0777 /tmp/tcmalloc
修改nginx的設定檔
vi /usr/local/nginx/conf/nginx.conf #pid logs/nginx.pid; google_perftools_profiles /tmp/tcmalloc;添加這一行
啟動nginx,並驗證tcmalloc有沒有正常載入
# service nginx restart
安裝一下lsof命令:
yum install lsof -y
# lsof -n |grep tcmalloc
至此已經替換成功。