基準測試
1. sysbench
https://github.com/akopytov/sysbench
在線安裝
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bash
sudo apt -y install sysbench
安裝完以后在 /usr/share/sysbench 目錄下有腳本文件

不會使用的話,直接敲 sysbench --help 或者 sysbench <testname> help


使用也非常簡單,四個命令:prepare(準備)、run(運行)、cleanup(清理)、help(幫助)
先創(chuàng)建一個數據庫,通常是叫“sbtest”
# 準備數據
sysbench --mysql-host=172.16.192.114 --mysql-port=3306 --mysql-user=root --mysql-password='123456' --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=100000 --threads=4 /usr/share/sysbench/oltp_read_write.lua prepare
# 運行
sysbench --mysql-host=172.16.192.114 --mysql-port=3306 --mysql-user=root --mysql-password='123456' --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=100000 --report-interval=10 --threads=50 --time=600 /usr/share/sysbench/oltp_read_write.lua run
# 清理數據
sysbench --mysql-host=172.16.192.114 --mysql-port=3306 --mysql-user=root --mysql-password='123456' --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=100000 --report-interval=10 --threads=50 --time=600 /usr/share/sysbench/oltp_read_write.lua cleanup
結果可能如圖所示

參考
https://help.aliyun.com/zh/polardb/polardb-for-xscale/sysbench-test-standard-version
https://piaohua.github.io/post/mysql/20200808-mysql-sysbench/
http://www.rzrgm.cn/dclogs/p/18620522
2. BenchmarkSQL
https://github.com/pingcap/benchmarksql
https://github.com/Percona-Lab/tpcc-mysql
首先從github上下載源碼,然后編譯打包
要確保測試機上安裝了JDK,至少是JDK7以上的版本,并且正確設置了 JAVA_HOME 和 PATH 環(huán)境變量
解壓縮以后,進入benchmarksql主目錄,執(zhí)行 ant 命令,編譯打包后會多出一個dist目錄來

源碼主目錄中有個 HOW-TO-RUN.txt 文件,可以按這個文件中的步驟來
首先,還是創(chuàng)建一個測試數據庫,通常叫“tpcc”
進入 run 目錄,編輯 props.mysql文件

db=mysql
driver=com.mysql.jdbc.Driver
conn=jdbc:mysql://172.16.192.114:3306/tpcc?useSSL=false&useServerPrepStmts=true&useConfigs=maxPerformance&rewriteBatchedStatements=true&cachePrepStmts=true&prepStmtCacheSize=1000&prepStmtCacheSqlLimit=2048
user=root
password=123456
warehouses=2
loadWorkers=4
terminals=20
//To run specified transactions per terminal- runMins must equal zero
runTxnsPerTerminal=0
//To run for specified minutes- runTxnsPerTerminal must equal zero
runMins=10
//Number of total transactions per minute
limitTxnsPerMin=0
//Set to true to run in 4.x compatible mode. Set to false to use the
//entire configured database evenly.
terminalWarehouseFixed=true
//The following five values must add up to 100
//The default percentages of 45, 43, 4, 4 & 4 match the TPC-C spec
newOrderWeight=45
paymentWeight=43
orderStatusWeight=4
deliveryWeight=4
stockLevelWeight=4
// Directory name to create for collecting detailed result data.
// Comment this out to suppress.
resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS
//osCollectorScript=./misc/os_collector_linux.py
//osCollectorInterval=1
//osCollectorSSHAddr=user@dbhost
//osCollectorDevices=net_eth0 blk_sda
terminals 并發(fā)數
warehouses 越大數據量越大
runMins 運行時間
進入run目錄直接執(zhí)行命令
# 準備數據
./runDatabaseBuild.sh props.mysql
# 運行
./runBenchmark.sh props.mysql
# 清理數據
./runDatabaseDestroy.sh props.mysql
# 生成報告
./generateReport.sh my_result_2025-xx-xx_xxxxx/

參考
https://help.aliyun.com/zh/polardb/polardb-for-xscale/tpc-c-test
http://www.rzrgm.cn/hunterhuang8888/p/14237903.html

浙公網安備 33010602011771號