找回密码
 立即注册
首页 业界区 安全 基准测试

基准测试

蔺蓉城 昨天 18:45
1. sysbench
https://github.com/akopytov/sysbench
在线安装
  1. curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bash
  2. sudo apt -y install sysbench
复制代码
安装完以后在 /usr/share/sysbench 目录下有脚本文件
1.png

不会使用的话,直接敲 sysbench --help 或者 sysbench  help
2.png

3.png



使用也非常简单,四个命令:prepare(准备)、run(运行)、cleanup(清理)、help(帮助)
先创建一个数据库,通常是叫“sbtest”
  1. # 准备数据
  2. 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
  3. # 运行
  4. 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
  5. # 清理数据
  6. 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
复制代码
结果可能如图所示
4.png

参考
https://help.aliyun.com/zh/polardb/polardb-for-xscale/sysbench-test-standard-version
https://piaohua.github.io/post/mysql/20200808-mysql-sysbench/
https://www.cnblogs.com/dclogs/p/18620522
2. BenchmarkSQL
https://www.tpc.org/
https://github.com/pingcap/benchmarksql
https://github.com/Percona-Lab/tpcc-mysql
首先从github上下载源码,然后编译打包
要确保测试机上安装了JDK,至少是JDK7以上的版本,并且正确设置了 JAVA_HOME 和 PATH 环境变量
解压缩以后,进入benchmarksql主目录,执行 ant 命令,编译打包后会多出一个dist目录来
5.png

源码主目录中有个 HOW-TO-RUN.txt 文件,可以按这个文件中的步骤来
首先,还是创建一个测试数据库,通常叫“tpcc”
进入 run 目录,编辑 props.mysql文件
6.png
  1. db=mysql
  2. driver=com.mysql.jdbc.Driver
  3. conn=jdbc:mysql://172.16.192.114:3306/tpcc?useSSL=false&useServerPrepStmts=true&useConfigs=maxPerformance&rewriteBatchedStatements=true&cachePrepStmts=true&prepStmtCacheSize=1000&prepStmtCacheSqlLimit=2048
  4. user=root
  5. password=123456
  6. warehouses=2
  7. loadWorkers=4
  8. terminals=20
  9. //To run specified transactions per terminal- runMins must equal zero
  10. runTxnsPerTerminal=0
  11. //To run for specified minutes- runTxnsPerTerminal must equal zero
  12. runMins=10
  13. //Number of total transactions per minute
  14. limitTxnsPerMin=0
  15. //Set to true to run in 4.x compatible mode. Set to false to use the
  16. //entire configured database evenly.
  17. terminalWarehouseFixed=true
  18. //The following five values must add up to 100
  19. //The default percentages of 45, 43, 4, 4 & 4 match the TPC-C spec
  20. newOrderWeight=45
  21. paymentWeight=43
  22. orderStatusWeight=4
  23. deliveryWeight=4
  24. stockLevelWeight=4
  25. // Directory name to create for collecting detailed result data.
  26. // Comment this out to suppress.
  27. resultDirectory=my_result_%tY-%tm-%td_%tH%tM%tS
  28. //osCollectorScript=./misc/os_collector_linux.py
  29. //osCollectorInterval=1
  30. //osCollectorSSHAddr=user@dbhost
  31. //osCollectorDevices=net_eth0 blk_sda
复制代码

terminals 并发数
warehouses 越大数据量越大
runMins 运行时间 
 进入run目录直接执行命令
  1. # 准备数据
  2. ./runDatabaseBuild.sh props.mysql
  3. # 运行
  4. ./runBenchmark.sh props.mysql
  5. # 清理数据
  6. ./runDatabaseDestroy.sh props.mysql
  7. # 生成报告
  8. ./generateReport.sh my_result_2025-xx-xx_xxxxx/
复制代码
7.png

参考
https://help.aliyun.com/zh/polardb/polardb-for-xscale/tpc-c-test
https://www.cnblogs.com/hunterhuang8888/p/14237903.html
 

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
您需要登录后才可以回帖 登录 | 立即注册