雖然通過研究發現TCMalloc不適合咱們現有的遊戲框架,但意外收穫發現TCMalloc能夠大幅度提升MYSQL 性能及內存佔用,這裏給出配置及測試的結果:html
關於TCMalloc的安裝,在《Google perftools 安裝手記(TCMalloc)》 一文中已經詳細給出,下面給出將TCMalloc配置到MYSQL的步驟:mysql
1 vi /usr/local/mysql/bin/mysqld_safe
在# executing mysqld_safe的下一行,添加:
1 export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
保存退出,並重啓MySQL
1 # lsof |grep -i libtcmalloc.so
若是發現如下信息,說明tcmalloc已經起效:
1 mysqld 13961 mysql mem REG 253,0 1948990 196421/usr/local/lib/libtcmalloc.so.4.1.2
sysbench是一個開源的、模塊化的、跨平臺的多線程性能測試工具,能夠用來進行CPU、內存、磁盤I/O、線程、數據庫的性能測試。目前支持的數據庫有MySQL、Oracle和PostgreSQL。如下操做都將以支持MySQL數據庫爲例進行。sourceforge已掛,下載地址:http://download.csdn.net/detail/chen19870707/8060033,安裝步驟以下:sql
1 tar zxf sysbench-0.4.10.tar.gz 2 cd sysbench-0.4.10 3 ./configure && make && make install 4 strip /usr/local/bin/sysbench
選項說明參考:http://www.cnblogs.com/zhoujinyi/archive/2013/04/19/3029134.html數據庫
1 sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=10000 --max-requests=10000 --num-threads=16 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=root --mysql-db=test --mysql-socket=/tmp/mysql.sock prepare
1 sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=10000 --max-requests=10000 --num-threads=16 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=root --mysql-db=test --mysql-socket=/tmp/mysql.sock run >> report.txt
1 /usr/local/bin/sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=10000 --max-requests=10000 --num-threads=16 --mysql-host=127.0.01 --mysql-port=3306 --mysql-user=root --mysql-password=root --mysql-db=test --mysql-socket=/tmp/mysql.sock cleanup
1 --oltp-table-size=N 測試表的記錄數。默認是10000 --max-requests=N limit for total number of requests [10000] #請求的最大數目。默認爲10000,0表明不限制。 2 --max-requests=N limit for total number of requests [10000] #請求的最大數目。默認爲10000,0表明不限制。 3 --num-threads=N number of threads to use [1] #建立測試線程的數目。默認爲1. 4 --mysql-host=[LIST,...] MySQL server host [localhost] 5 --mysql-port=N MySQL server port [3306] 6 --mysql-password=STRING MySQL password [] 7 --mysql-db=STRING MySQL database name [sbtest] 8 --mysql-socket=STRING MySQL socket
未使用TCMalloc多線程 OLTP test statistics: Test execution summary: |
使用TCMallocsocket OLTP test statistics: Test execution summary: |