天天看點

利用Tcmalloc優化MySQL性能

TCMalloc (google-perftools) 是用于優化C++寫的多線程應用,比glibc 2.3的malloc快。這個子產品可以用來讓MySQL在高并發下記憶體占用更加穩定。

google-perftools包含四個工具,分别是:TCMalloc、heap-checker、heap-profiler和cpu-profiler,TCMalloc是google-perftools的其中一個工具,用于優化記憶體配置設定的效率和速度,幫助在高并發的情況下很好的控制記憶體的使用。

1.64位作業系統請先安裝 libunwind庫,32位作業系統不要安裝。libunwind庫為基于64位CPU和作業系統的程式提供了基本的堆棧輾轉開解功能,其中包括用于輸出堆棧跟蹤的API、用于以程式設計方式輾轉開解堆棧的API以及支援C++異常處理機制的API。

1

2

3

4

5

<code>tar</code> <code>zxvf libunwind-1.1.</code><code>tar</code><code>.gz</code>

<code>cd</code> <code>libunwind-1.1</code>

<code>.</code><code>/configure</code>

<code>make</code>

<code>make</code> <code>install</code>

2.安裝google-perftools:

<code>tar</code> <code>zxvf google-perftools-2.1.</code><code>tar</code><code>.gz</code>

<code>cd</code> <code>google-perftools-2.1</code>

3.運作以下二行指令

<code>echo</code> <code>"/usr/local/lib"</code> <code>&gt; </code><code>/etc/ld</code><code>.so.conf.d</code><code>/usr_local_lib</code><code>.conf</code>

<code>/sbin/ldconfig</code>

4.修改MySQL啟動腳本

6

7

<code>[root@Node1 ~]</code><code># whereis mysqld_safe</code>

<code>#用于找到mysqld_safe檔案的位置</code>

<code>mysqld_safe: </code><code>/usr/bin/mysqld_safe</code> <code>/usr/share/man/man1/mysqld_safe</code><code>.1.gz</code>

<code>[root@Node1 ~]</code><code># vim /usr/bin/mysqld_safe</code>

<code>在</code><code># executing mysqld_safe的下一行,加上:</code>

<code>export</code> <code>LD_PRELOAD=</code><code>/usr/local/lib/libtcmalloc</code><code>.so</code>

<code>儲存後退出,然後重新開機MySQL伺服器。</code>

5.測試是否正常

如出現以上說明安裝成功,另外可能出現lsof未安裝,使用yum -y install lsof即可。

本文轉自 rong341233 51CTO部落格,原文連結:http://blog.51cto.com/fengwan/1426297

繼續閱讀