ToB企服应用市场:ToB评测及商务社交产业平台

标题: 如何对Linux系统进行基准测试4工具Sysbench [打印本页]

作者: 灌篮少年    时间: 2024-7-13 21:52
标题: 如何对Linux系统进行基准测试4工具Sysbench
Sysbench简介

Sysbench是一款多用途基准测试工具,可对CPU、内存、I/O甚至数据库性能进行测试。它是一个基本的下令行工具,提供了直接、简便的系统测试方法。github地址:https://github.com/akopytov/sysbench

主要功能:
Sysbench的主要特点包罗:
Sysbench 常用于以下场景:
源码:https://github.com/akopytov/sysbench
安装Sysbench

首先在系统上安装Sysbench。大多数发行版软件源都提供了它:
  1. # Ubuntu/Debian
  2. $ sudo apt install sysbench
  3. # Fedora
  4. # dnf install sysbench
  5. # CentOS
  6. # yum install sysbench
  7. # OpenSUSE
  8. # zypper in sysbench
复制代码
CPU基准测试
  1. $ sysbench cpu --cpu-max-prime=2000 run
  2. sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
  3. Running the test with following options:
  4. Number of threads: 1
  5. Initializing random number generator from current time
  6. Prime numbers limit: 2000
  7. Initializing worker threads...
  8. Threads started!
  9. CPU speed:
  10.     events per second: 22757.61
  11. General statistics:
  12.     total time:                          10.0001s
  13.     total number of events:              227609
  14. Latency (ms):
  15.          min:                                    0.04
  16.          avg:                                    0.04
  17.          max:                                    0.12
  18.          95th percentile:                        0.04
  19.          sum:                                 9968.18
  20. Threads fairness:
  21.     events (avg/stddev):           227609.0000/0.00
  22.     execution time (avg/stddev):   9.9682/0.00
复制代码
固然会生成包含大量统计数据的报告,但 CPU 基准测试的主要内容是"General statistics"下的"total time"。
  1. $ sysbench cpu run
  2. $ sysbench cpu --threads=40 run # 默认为单线程
  3. #在检查 CPU 在重负载下的性能时,可使用命令将 CPU 的最大质数限制从 "10000 "扩展到 "15000":
  4. $ sysbench --test=cpu --cpu-max-prime=15000 run
  5. # 帮助
  6. $ sysbench cpu help
  7. sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
  8. cpu options:
  9.   --cpu-max-prime=N upper limit for primes generator [10000]
复制代码
内存基准测试
  1. $ sysbench memory --threads=2 run
  2. sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
  3. Running the test with following options:
  4. Number of threads: 2
  5. Initializing random number generator from current time
  6. Running memory speed test with the following options:
  7.   block size: 1KiB
  8.   total size: 102400MiB
  9.   operation: write
  10.   scope: global
  11. Initializing worker threads...
  12. Threads started!
  13. Total operations: 28555430 (2855143.49 per second)
  14. 27886.16 MiB transferred (2788.23 MiB/sec)
  15. General statistics:
  16.     total time:                          10.0001s
  17.     total number of events:              28555430
  18. Latency (ms):
  19.          min:                                    0.00
  20.          avg:                                    0.00
  21.          max:                                    0.03
  22.          95th percentile:                        0.00
  23.          sum:                                12842.67
  24. Threads fairness:
  25.     events (avg/stddev):           14277715.0000/1030637.00
  26.     execution time (avg/stddev):   6.4213/0.10
复制代码
这里有两点需要考虑:"Total operations"和"transferred"。
  1. $ sysbench memory run
  2. $ sysbench memory --memory-oper=write run # 默认为读
  3. # 要测试特定条件下的内存,例如将内存块大小从默认的 "1KiB "提高到 "1M",同时保持总内存容量为 "8GB"
  4. $ sysbench --test=memory --memory-block-size=1M --memory-total-size=8G run
复制代码
参考资料


IO基准测试

在Linux系统上执行IO基准测试时,我们必须先创建一些测试文件。要创建测试文件,请使用以下下令:
  1. $ sysbench --test=fileio --file-total-size=100G prepare
  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.20 (using system LuaJIT 2.1.0-beta3)
  4. 128 files, 819200Kb each, 102400Mb total
  5. Creating files for the test...
  6. Extra file open flags: (none)
  7. Extending existing file test_file.0
  8. ...
  9. Extending existing file test_file.127
  10. 53687091200 bytes written in 94.39 seconds (542.44 MiB/sec).
复制代码
请确保选择的测试文件大小大于内存容量,如许IO历程才不会受到内存操作的影响。创建测试文件将根据所选大小耗费一些时间。创建测试文件后,运行以下下令开始基准测试:
  1. $ sysbench --test=fileio --file-total-size=100G --file-test-mode=rndrw --max-time=300 --max-requests=0 run
  2. WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
  3. WARNING: --max-time is deprecated, use --time instead
  4. sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
  5. Running the test with following options:
  6. Number of threads: 1
  7. Initializing random number generator from current time
  8. Extra file open flags: (none)
  9. 128 files, 800MiB each
  10. 100GiB total file size
  11. Block size 16KiB
  12. Number of IO requests: 0
  13. Read/Write ratio for combined random IO test: 1.50
  14. Periodic FSYNC enabled, calling fsync() each 100 requests.
  15. Calling fsync() at the end of test, Enabled.
  16. Using synchronous I/O mode
  17. Doing random r/w test
  18. Initializing worker threads...
  19. Threads started!
  20. File operations:
  21.     reads/s:                      1101.01
  22.     writes/s:                     734.01
  23.     fsyncs/s:                     2348.98
  24. Throughput:
  25.     read, MiB/s:                  17.20
  26.     written, MiB/s:               11.47
  27. General statistics:
  28.     total time:                          300.0508s
  29.     total number of events:              1255287
  30. Latency (ms):
  31.          min:                                    0.00
  32.          avg:                                    0.24
  33.          max:                                 2154.60
  34.          95th percentile:                        0.46
  35.          sum:                               299665.82
  36. Threads fairness:
  37.     events (avg/stddev):           1255287.0000/0.00
  38.     execution time (avg/stddev):   299.6658/0.00
复制代码
文件清理:
  1. $ sysbench --test=fileio --file-total-size=100G cleanup
  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.20 (using system LuaJIT 2.1.0-beta3)
  4. Removing test files...
复制代码
Mysql基准测试

要对mysql进行基准测试,我们首先要在名为"test"的数据库中创建一个有50000 的表,使用以下下令
  1. $ sysbench --test=oltp –oltp-table-size=50000 --mysql-db=test --mysql-user=root --mysql-password=passwd prepare
复制代码
操作完成后,执行以下下令启动 Mysql Bechmarking:
  1. $ sysbench --test=oltp --oltp-table-size=500000 --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
  2. No DB drivers specified, using mysql
  3. Running the test with following options:
  4. Number of threads: 8
  5. Doing OLTP test.
  6. Running mixed OLTP test
  7. Doing read-only test
  8. Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
  9. Using "BEGIN" for starting transactions
  10. Using auto_inc on the id column
  11. Threads started!
  12. Time limit exceeded, exiting...
  13. (last message repeated 7 times)
  14. Done.
  15. OLTP test statistics:
  16. queries performed:
  17. read: 2253860
  18. write: 0
  19. other: 321980
  20. total: 2575840
  21. transactions: 160990 (2683.06 per sec.)
  22. deadlocks: 0 (0.00 per sec.)
  23. read/write requests: 2253860 (37562.81 per sec.)
  24. other operations: 321980 (5366.12 per sec.)
  25. Test execution summary:
  26. total time: 60.0024s
  27. total number of events: 160990
  28. total time taken by event execution: 479.3419
  29. per-request statistics:
  30. min: 0.81ms
  31. avg: 2.98ms
  32. max: 3283.40ms
  33. approx. 95 percentile: 4.62ms
  34. Threads fairness:
  35. events (avg/stddev): 20123.7500/63.52
  36. execution time (avg/stddev): 59.9177/0.00
  37. Main parameter to check here is 'transactions per second'
  38. transactions: 160990 (2683.06 per sec.)
复制代码
测试数据清理:
  1. $ sysbench --test=oltp --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword cleanup
复制代码
结果解读

总时间越短,表明系统性能越好,尤其是在比力类似测试时。不过必须将这一指标与其他指标结合起来考虑,因为测试时间越短,错误率越高,并不代表性能越好。
Ops/sec是系统吞吐量的直接指标。ops/sec值越高,通常意味着系统在给定时间内可以处置惩罚的操作越多,性能越好。比方,如果您运行的是数据库服务器,较高的ops/sec表示您的服务器每秒可以处置惩罚更多的查询,从而为最终用户带来更快的响应时间。
延迟对用户体验至关重要。较低的延迟意味着更快地完成操作,这对于视频流或在线游戏等需要实时响应的使命尤为重要。如果您正在托管一个网站,较低的延迟可以加快页面加载时间,提升用户体验。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4