TiDB 学习第 7 天:TiDB 性能测试

x33g5p2x  于2021-12-19 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(435)

一、工具介绍

TiDB性能测试使用sysbench工具来进行压测,sysbench是数据库功能及性能测试工具,它的测试功能如下:

  • CPU 运算性能测试
  • 磁盘 IO 性能测试
  • 调度程序性能测试
  • 内存分配及传输速度测试
  • POSIX 线程性能测试
  • 数据库性能测试(OLTP 基准测试,需要通过 /usr/share/sysbench/ 目录中的 Lua 脚本执行,例如 oltp_read_only.lua 脚本执行只读测试)

二、sysbench工具安装及使用

1、 Centos的安装
  1. sudo yum install -y sysbench
2、查看帮助信息
  1. # 查看帮助信息
  2. [tidb@cdh01 ~]$ sudo sysbench --help
  3. # 查看测试帮助信息
  4. sudo sysbench fileio help / sudo sysbench cpu help

#### 3、CPU测试信息

  1. # 查看CPU帮助信息 sudo sysbench cpu help
  2. [tidb@cdh01 ~]$ sudo sysbench cpu help
  3. sysbench 1.0.17 (using system LuaJIT 2.0.4)
  4. cpu options:
  5. --cpu-max-prime=N upper limit for primes generator [10000]
4、CPU测试
  1. sudo sysbench --cpu-max-prime=10000 --threads=2 cpu run
5、磁盘IO性能测试
  1. # 磁盘准备阶段
  2. sysbench --test=fileio --num-threads=16 --file-total-size=30G --file-test-mode=rndrw prepare
  3. # 磁盘IO运行检测
  4. sysbench --test=fileio --num-threads=16 --file-total-size=30G --file-test-mode=rndrw run
  5. Extra file open flags: (none)
  6. 128 files, 240MiB each
  7. 30GiB total file size
  8. Block size 16KiB
  9. Number of IO requests: 0
  10. Read/Write ratio for combined random IO test: 1.50
  11. Periodic FSYNC enabled, calling fsync() each 100 requests.
  12. Calling fsync() at the end of test, Enabled.
  13. Using synchronous I/O mode
  14. Doing random r/w test
  15. Initializing worker threads...
  16. Threads started!
  17. File operations:
  18. reads/s: 757.99
  19. writes/s: 504.77
  20. fsyncs/s: 1811.27
  21. Throughput:
  22. read, MiB/s: 11.84
  23. written, MiB/s: 7.89
  24. General statistics:
  25. total time: 10.1038s
  26. total number of events: 29017
  27. Latency (ms):
  28. min: 0.00
  29. avg: 5.53
  30. max: 374.29
  31. 95th percentile: 33.12
  32. sum: 160351.92
  33. Threads fairness:
  34. events (avg/stddev): 1813.5625/196.79
  35. execution time (avg/stddev): 10.0220/0.03
6、线程测试
  1. sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
  2. 测试写入64线程请求,每个请求产生100个数据量,最后测试执行时间
  3. WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
  4. WARNING: --num-threads is deprecated, use --threads instead
  5. sysbench 1.0.17 (using system LuaJIT 2.0.4)
  6. Running the test with following options:
  7. Number of threads: 64
  8. Initializing random number generator from current time
  9. Initializing worker threads...
  10. Threads started!
  11. General statistics:
  12. total time: 10.0057s
  13. total number of events: 134204
  14. Latency (ms):
  15. min: 0.03
  16. avg: 4.77
  17. max: 74.11
  18. 95th percentile: 16.71
  19. sum: 639949.82
  20. Threads fairness:
  21. events (avg/stddev): 2096.9375/94.14
  22. execution time (avg/stddev): 9.9992/0.00 # 测试最后执行时间为9.9秒
7、内存测试
  1. sysbench --test=memory --memory-block-size=8k --memory-total-size=40G run
  2. WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
  3. sysbench 1.0.17 (using system LuaJIT 2.0.4)
  4. Running the test with following options:
  5. Number of threads: 1
  6. Initializing random number generator from current time
  7. Running memory speed test with the following options:
  8. block size: 8KiB
  9. total size: 40960MiB
  10. operation: write
  11. scope: global
  12. Initializing worker threads...
  13. Threads started!
  14. Total operations: 5242880 (1073492.41 per second)
  15. 40960.00 MiB transferred (8386.66 MiB/sec)
  16. General statistics:
  17. total time: 4.8814s
  18. total number of events: 5242880
  19. Latency (ms):
  20. min: 0.00
  21. avg: 0.00
  22. max: 1.30
  23. 95th percentile: 0.00
  24. sum: 3911.72
  25. Threads fairness:
  26. events (avg/stddev): 5242880.0000/0.00
  27. execution time (avg/stddev): 3.9117/0.00 # 测试内存总大小40G 内存缓冲区大小为8k
8、TiDB OLTP基准测试

基准测试分为3个步骤进行:基准测试脚本如下:

1)首先需要先生成测试表
  1. 运行命令查看mysql数据库测试参数标准:sudo sysbeach --help
  2. --mysql-host=[LIST,...] MySQL server host [localhost] mysql主机ip
  3. --mysql-port=[LIST,...] MySQL server port [3306] 端口/mysql默认端口3306 tidb端口 4000
  4. --mysql-socket=[LIST,...] MySQL socket mysql安装路径
  5. --mysql-user=STRING MySQL user [sbtest] 数据库用户名
  6. --mysql-password=STRING MySQL password [] 密码
  7. --mysql-db=STRING MySQL database name [sbtest] 需要进行压测的数据库名称
  8. --mysql-ssl[=on|off] use SSL connections, if available in the client library [off]
  9. --mysql-ssl-cipher=STRING use specific cipher for SSL connections []
  10. --mysql-compression[=on|off] use compression, if available in the client library [off]
  11. --mysql-debug[=on|off] trace all client library calls [off]
  12. --mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205]
  13. --mysql-dry-run[=on|off] Dry run, pretend that all MySQL client API calls are successful without executing them [off]
  1. # 运行语句生成测试表
  2. sudo sysbench --db-driver=mysql --mysql-host=ip --mysql-port=4000 \
  3. --mysql-user=root --mysql-password= --mysql-db=BIGDATA \
  4. --range_size=100 --table_size=10000 --threads=2 --events=0 --time=60 \
  5. --rand-type=uniform /usr/share/sysbench/oltp_read_only.lua prepare

2)运行语句进行测试(表的读性能统计基于表的数据是10000)
  1. 运行测试.lua测试语句并指定线程数
  2. sudo sysbench --db-driver=mysql --mysql-host=ip --mysql-port=4000 \
  3. --mysql-user=root --mysql-password= --mysql-db=BIGDATA \
  4. --range_size=100 --table_size=10000 --threads=2 --events=0 --time=60 \
  5. --rand-type=uniform /usr/share/sysbench/oltp_read_only.lua run

程序运行结果如下:

  1. Threads started!
  2. SQL statistics:
  3. queries performed: #性能统计
  4. read: 63854 # 读统计 (select语句)
  5. write: 0 # 写统计 (insert、delete、update语句)
  6. other: 9122 # 其他语句 (如commit等)
  7. total: 72976 # 总执行语句之和
  8. transactions: 4561 (76.00 per sec.) #总事务数(每秒处理的事务)
  9. queries: 72976 (1216.08 per sec.) #查询性能(每秒的查询性能)
  10. ignored errors: 0 (0.00 per sec.)
  11. reconnects: 0 (0.00 per sec.)
  12. General statistics:
  13. total time: 60.0072s # 总时长
  14. total number of events: 4561 # 事务总数
  15. Latency (ms): #延迟时间
  16. min: 19.30 # 最小延迟时间
  17. avg: 26.30 # 平均延迟
  18. max: 1238.63 # 最大延迟
  19. 95th percentile: 33.12 # 95%以上语句响应时间
  20. sum: 119963.62 # 总延迟时长
  21. Threads fairness: # 线程公平性
  22. events (avg/stddev): 2280.5000/0.50
  23. execution time (avg/stddev): 59.9818/0.00
3、清除测试表
  1. # 清除测试表
  2. sudo sysbench --db-driver=mysql --mysql-host=ip --mysql-port=4000 \
  3. --mysql-user=root --mysql-password= --mysql-db=BIGDATA \
  4. --range_size=100 --table_size=10000 --threads=2 --events=0 --time=60 \
  5. --rand-type=uniform /usr/share/sysbench/oltp_read_only.lua clearnup

相关文章