說(shuō)明
sysbench 支持多種基準(zhǔn)測(cè)試工作負(fù)載:fileio、cpu、內(nèi)存、線程、互斥鎖、oltp,甚至MySQL基準(zhǔn)測(cè)試,測(cè)試過(guò)程一般分為三個(gè)階段:
- prepare:準(zhǔn)備階段,準(zhǔn)備測(cè)試數(shù)據(jù)。
- run:執(zhí)行測(cè)試階段。
- cleanup:清理垃圾數(shù)據(jù)階段。
安裝(以centos為例)
安裝sysbench
sudo yum -y install sysbench
aws源不存在,需要手動(dòng)添加
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench
驗(yàn)證是否安裝成功
sysbench --version
服務(wù)器IO測(cè)試
準(zhǔn)備數(shù)據(jù)
sysbench
--test=fileio \
--num-threads=20 \
--file-total-size=3G \
--file-test-mode=rndrw \ #STRING 測(cè)試模式:seqwr(順序?qū)?, seqrewr(順序讀寫(xiě)), seqrd(順序讀), rndrd(隨機(jī)讀), rndwr(隨機(jī)寫(xiě)), rndrw(隨機(jī)讀寫(xiě))。
prepare
進(jìn)行測(cè)試、清楚數(shù)據(jù)
sysbench --test=fileio --num-threads=20 --file-total-size=3G --file-test-mode=rndrw run
sysbench --test=fileio --num-threads=20 --file-total-size=3G --file-test-mode=rndrw cleanup
準(zhǔn)備MYSQL數(shù)據(jù)
切到sysbench安裝目錄下,默認(rèn)為 /usr/share/sysbench
sysbench ./tests/include/oltp_legacy/oltp.lua \
--mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user= \
--mysql-password= \
--oltp-test-mode=complex \ #測(cè)試類(lèi)型:simple(簡(jiǎn)單select測(cè)試),complex(事務(wù)測(cè)試),nontrx(非事務(wù)測(cè)試),sp(存儲(chǔ)過(guò)程)
--oltp-tables-count=10 \ #表個(gè)數(shù)
--oltp-table-size=100000 \ #數(shù)據(jù)量
--threads=10 \ #創(chuàng)建線程數(shù)
--time=120 \ #測(cè)試時(shí)間
--report-interval=10 \ #每N秒輸出一次報(bào)告
prepare
OLTP只讀測(cè)試
sysbench ./tests/include/oltp_legacy/oltp.lua \
--mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user= \
--mysql-password= \
--oltp-tables-count=10 \ #表個(gè)數(shù)
--oltp-table-size=100000 \ #數(shù)據(jù)量
--report-interval=10 \ #每N秒輸出一次報(bào)告
--oltp-dist-type=uniform \ #指定隨機(jī)取樣類(lèi)型,可選值有 uniform(均勻分布), Gaussian(高斯分布), special(空間分布)。默認(rèn)是special
--rand-init=on \ #是否隨機(jī)初始化數(shù)據(jù),如果不隨機(jī)化那么初始好的數(shù)據(jù)每行內(nèi)容除了主鍵不同外其他完全相同
--max-requests=0 \ #壓力測(cè)試產(chǎn)生請(qǐng)求的總數(shù),如果以下面的max-time來(lái)記,這個(gè)值設(shè)為0
--oltp-test-mode=nontrx #執(zhí)行模式,這里是非事務(wù)式的。可選值有simple,complex,nontrx。
--oltp-nontrx-mode=select \
--oltp-read-only=on \
--oltp-skip-trx=on \ #省略begin/commit語(yǔ)句。默認(rèn)是off
--max-time=120 \ #測(cè)試時(shí)間
--num-threads=100 \ #并發(fā)線程數(shù),可以理解為模擬的客戶(hù)端并發(fā)連接數(shù)
run >> /home/test/sysbench_read.log
OLTP混合測(cè)試
sysbench ./tests/include/oltp_legacy/oltp.lua
--mysql-host=127.0.0.1 \
--mysql-port=3306 \
--mysql-user= \
--mysql-password= \
--oltp-test-mode=complex \
--oltp-tables-count=10 \
--oltp-table-size=100000 \
--threads=100 \
--time=120 \
--num-threads=100 \
--report-interval=10 \
run >> /home/test/sysbench_complex.log
參考資料
《高性能MYSQL》
https://wiki.gentoo.org/wiki/Sysbench
http://www.itdecent.cn/p/9823b4aa445a
-end-