新聞中心
sysbench是一個開源的、模塊化的、跨平臺的多線程性能測試工具,可以用來進(jìn)行CPU、內(nèi)存、磁盤I/O、線程、數(shù)據(jù)庫的性能測試。目前支持的數(shù)據(jù)庫有MySQL、Oracle和PostgreSQL。以下操作都將以支持MySQL數(shù)據(jù)庫為例進(jìn)行。

一、 下載sysbench源碼包及mysql數(shù)據(jù)庫
\1. 目前sysbench代碼托管在launchpad上,項目地址: https://github.com/akopytov/sysbench,下載方式:
\2. MySQL官方下載地址:http://dev.mysql.com/downloads/mysql/,下載方式:
二、編譯安裝
\1. Mysql數(shù)據(jù)庫安裝:
mysql數(shù)據(jù)庫的安裝可參考本站的另一篇文章:Mysql二進(jìn)制包安裝與配置實戰(zhàn)記錄 或直接通過本站右側(cè)的搜索框搜索Mysql會發(fā)現(xiàn)很多關(guān)于Mysql安裝的文章,本文不再講解。
\2. sysbench編譯非常簡單,可參考 README 文檔,簡單步驟如下:
tar -zxvf sysbench-0.4.8.tar.gz
cd sysbench-0.4.8
./configure && make && make install
strip /usr/local/bin/sysbench
以上方法適用于MySQL安裝在標(biāo)準(zhǔn)默認(rèn)目錄下的情況,如果MySQL并不是安裝在標(biāo)準(zhǔn)目錄下的話,那么就需要自己指定MySQL的路徑了。比如我的MySQL喜歡自己安裝在/usr/local/mysql下,則按照以下方法編譯:
./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib && make && make install
當(dāng)然了,用上面的參數(shù)編譯的話,就要確保你的MySQL lib目錄下有對應(yīng)的so文件,如果沒有,可以自己下載devel或者share包來安裝。
另外,如果想要讓sysbench支持pgsql/oracle的話,就需要在編譯的時候加上參數(shù)
--with-pgsql
或者
--with-oracle
這2個參數(shù)默認(rèn)是關(guān)閉的,只有MySQL是默認(rèn)支持的。
三、OLTP測試前準(zhǔn)備
初始化測試庫環(huán)境(總共10個測試表,每個表 100000 條記錄,填充隨機(jī)生成的數(shù)據(jù)):
cd /tmp/sysbench-0.4.12-1.1/sysbench
mysqladmin create sbtest
./sysbench --mysql-host=127.0.0.1 --mysql-port=3317 --mysql-user=tpcc --mysql-password=tpcc \
--test=tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=100000 --rand-init=on prepare
關(guān)于這幾個參數(shù)的解釋:
--test=tests/db/oltp.lua 表示調(diào)用 tests/db/oltp.lua 腳本進(jìn)行 oltp 模式測試
--oltp_tables_count=10 表示會生成 10 個測試表
--oltp-table-size=100000 表示每個測試表填充數(shù)據(jù)量為 100000
--rand-init=on 表示每個測試表都是用隨機(jī)數(shù)據(jù)來填充的
如果在本機(jī),也可以使用 –mysql-socket 指定 socket 文件來連接。加載測試數(shù)據(jù)時長視數(shù)據(jù)量而定,若過程比較久需要稍加耐心等待。
真實測試場景中,數(shù)據(jù)表建議不低于 10個 ,單表數(shù)據(jù)量不低于 500萬行 ,當(dāng)然了,要視服務(wù)器硬件配置而定。如果是配備了SSD或者PCIE SSD這種高IOPS設(shè)備的話,則建議單表數(shù)據(jù)量最少不低于 1億行 。
四、進(jìn)行OLTP測試
在上面初始化數(shù)據(jù)參數(shù)的基礎(chǔ)上,再增加一些參數(shù),即可開始進(jìn)行測試了:
./sysbench --mysql-host=127.0.0.1 --mysql-port=3306 \
--mysql-user=tpcc --mysql-password=tpcc \
--test=tests/db/oltp.lua --oltp_tables_count=10 \
--oltp-table-size=10000000 --num-threads=8 \
--oltp-read-only=off --report-interval=10 \
--rand-type=uniform --max-time=3600 \
--mysql-table-engine=myisam --max-requests=0 \
--percentile=99 run >> ./log/sysbench_oltpX_8_20140921.log
關(guān)于這幾個參數(shù)的解釋:
--num-threads=8 表示發(fā)起 8個并發(fā)連接
--oltp-read-only=off 表示不要進(jìn)行只讀測試,也就是會采用讀寫混合模式測試
--report-interval=10 表示每10秒輸出一次測試進(jìn)度報告
--rand-type=uniform 表示隨機(jī)類型為固定模式,其他幾個可選隨機(jī)模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
--max-time=120 表示最大執(zhí)行時長為 120秒
--max-requests=0 表示總請求數(shù)為 0,因為上面已經(jīng)定義了總執(zhí)行時長,所以總請求數(shù)可以設(shè)定為 0;也可以只設(shè)定總請求數(shù),不設(shè)定最大執(zhí)行時長
--percentile=99 表示設(shè)定采樣比例,默認(rèn)是 95%,即丟棄1%的長請求,在剩余的99%里取最大值
--mysql-table-engine=myisam 表示測試的表存儲引擎類型為myisam
即:模擬 對10個表并發(fā)OLTP測試,每個表1000萬行記錄,持續(xù)壓測時間為 1小時。
真實測試場景中,建議持續(xù)壓測時長不小于 30分鐘 ,否則測試數(shù)據(jù)可能不具參考意義。
這里需要注意的是,官方網(wǎng)站上的參數(shù)有一處有誤,即 –mysql-table-engine,官方網(wǎng)站上寫的是 –mysql-table-type,這個應(yīng)該是沒有及時更新導(dǎo)致的。
另外,–mysql-table-engine參數(shù)還可以指定為 innodb 等 MySQL 支持的表存儲引擎類型。
五、測試結(jié)果解讀
測試結(jié)果解讀如下:
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 8
Report intermediate results every 10 second(s)
Random number generator seed is 0 and will be ignored
Threads started! --每10秒鐘報告一次測試結(jié)果,tps、每秒讀、每秒寫、99%以上的響應(yīng)時長統(tǒng)計
[10s] threads: 8, tps: 1111.51, reads/s: 15568.42, writes/s: 4446.13, response time: 9.95ms (99%)
[20s] threads: 8, tps: 1121.90, reads/s: 15709.62, writes/s: 4487.80, response time: 9.78ms (99%)
[30s] threads: 8, tps: 1120.00, reads/s: 15679.10, writes/s: 4480.20, response time: 9.84ms (99%)
[40s] threads: 8, tps: 1114.20, reads/s: 15599.39, writes/s: 4456.30, response time: 9.90ms (99%)
[50s] threads: 8, tps: 1114.00, reads/s: 15593.60, writes/s: 4456.70, response time: 9.84ms (99%)
[60s] threads: 8, tps: 1119.30, reads/s: 15671.60, writes/s: 4476.50, response time: 9.99ms (99%)
OLTP test statistics:
queries performed:
read: 938224 --讀總數(shù)
write: 268064 --寫總數(shù)
other: 134032 --其他操作總數(shù)(SELECT、INSERT、UPDATE、DELETE
之外的操作,例如COMMIT等)
total: 1340320 --全部總數(shù)
transactions: 67016 (1116.83 per sec.) --總事務(wù)數(shù)(每秒事務(wù)數(shù))
deadlocks: 0 (0.00 per sec.) --發(fā)生死鎖總數(shù)
read/write requests: 1206288 (20103.01 per sec.)--讀寫總數(shù)(每秒讀寫次數(shù))
other operations: 134032 (2233.67 per sec.) --其他操作總數(shù)(每秒其他操作次數(shù))
General statistics: --一些統(tǒng)計結(jié)果
total time: 60.0053s --總耗時
total number of events: 67016 --共發(fā)生多少事務(wù)數(shù)
total time taken by event execution: 479.8171s --所有事務(wù)耗時相加(不考慮并行因素)
response time: --響應(yīng)時長統(tǒng)計
min: 4.27ms --最小耗時
avg: 7.16ms --平均耗時
max: 13.80ms --最長耗時
approx. 99 percentile: 9.88ms --超過99%平均耗時
Threads fairness:
events (avg/stddev): 8377.0000/44.33
execution time (avg/stddev): 59.9771/0.00
當(dāng)前文章:sysbench的安裝與使用
文章起源:http://fisionsoft.com.cn/article/cogcisd.html


咨詢
建站咨詢
