sysbench既可以測(cè)試數(shù)據(jù)庫(kù)性能,又可以測(cè)試系統(tǒng)CPU、內(nèi)存、I/O等硬件資源
1,sysbench安裝。
yum list installed | grep sysbench
查看已安裝的sysbench
yum remove -y sysbench.x86_64移除已安裝的sysbench
文檔地址https://github.com/akopytov/sysbench
下載二進(jìn)制包。curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
yum list | grep sysbench查看可安裝的sysbench包
yum -y install sysbench安裝sysbench
2,語(yǔ)法介紹
sysbench [options]... [testname] [command]
options:以--開頭的參數(shù)。
--threads: The total number of worker threads to create --events: Limit for total number of requests. 0 (the default) means no limit --time: Limit for total execution time in seconds. 0 means no limit --warmup-time: 預(yù)熱時(shí)間 CPU/database/page and other caches need some time to warm up --report-interval: 每時(shí)間間隔,生成統(tǒng)計(jì)信息,非累計(jì)的 --percentile :95% percentile means we should drop 5% of the most long requests and choose the maximal value from the remaining ones
testname: 選項(xiàng)名, is an optional name of a built-in test, or Lua script。
可以使內(nèi)置的選項(xiàng)名,也可以是lua腳本。
fileio, memory, cpu, etc. /usr/share/sysbench/oltp_read_write.lua
Command:is an optional argument,傳給內(nèi)置選項(xiàng)名,或者lua腳本。
prepare 準(zhǔn)備工作,eg:創(chuàng)建文件、填充數(shù)據(jù)庫(kù)等, run 運(yùn)行內(nèi)置選項(xiàng)或者lua腳本實(shí)際的test, cleanup 在run之后, 清除臨時(shí)的數(shù)據(jù), help 顯示幫助信息。
sysbench fileio help
sysbench memory help
sysbench cpu help
3, 數(shù)據(jù)庫(kù)測(cè)試。(創(chuàng)建數(shù)據(jù)庫(kù)testdb)
sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root
--mysql-password='!@#123' --mysql-db=testdb --threads=10 --table-size=2000 --tables=10
--rand-type=uniform --db-driver=mysql --time=30 --events=0 --percentile=99
--report-interval=2 /usr/share/sysbench/oltp_read_write.lua prepare準(zhǔn)備數(shù)據(jù),執(zhí)行插入,密碼有特殊字符,需要加''
sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root
--mysql-password='!@#123' --mysql-db=testdb --threads=10 --table-size=2000 --tables=10
--rand-type=uniform --db-driver=mysql --time=30 --events=0 --percentile=99
--report-interval=2 /usr/share/sysbench/oltp_read_write.lua run執(zhí)行腳本的run操作
sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root
--mysql-password='!@#123' --mysql-db=testdb --threads=10 --table-size=2000 --tables=10
--rand-type=uniform --db-driver=mysql --time=30 --events=0 --percentile=99
--report-interval=2 /usr/share/sysbench/oltp_read_write.lua cleanup執(zhí)行腳本的清除操作