Sysbench简介
Sysbench是一款多用途基准测试工具,可对CPU、内存、I/O甚至数据库性能进行测试。它是一个基本的命令行工具,提供了直接、简便的系统测试方法。github地址:https://github.com/akopytov/sysbench 。
主要功能:
- CPU: 衡量CPU执行计算密集型任务的能力。
- 内存: 衡量内存子系统的性能。
- 磁盘I/O: 衡量磁盘读写速度。
- 数据库: 衡量数据库的性能,包括 OLTP(联机事务处理)和TPC-C基准测试。
- 其他: Sysbench还支持其他类型的测试,例如线程性能和网络延迟。
Sysbench的主要特点包括:
- 开源: Sysbench 是一个开源软件,可以免费使用和修改。
- 跨平台: Sysbench 支持多种操作系统,包括 Linux、Windows、macOS 和 Solaris。
- 多线程: Sysbench 支持多线程测试,可以充分利用多核 CPU 的性能。
- 模块化: Sysbench 的架构是模块化的,可以扩展支持新的测试类型和功能。
- 易用性: Sysbench 提供命令行界面和 Lua 脚本支持,易于使用和配置。
Sysbench 常用于以下场景:
- 性能测试: 评估系统的性能瓶颈并进行优化。
- 数据库性能测试: 衡量数据库的性能并与其他数据库进行比较。
- 硬件评估: 评估新硬件的性能。
- 容量规划: 规划系统的容量以满足未来的需求。
源码:https://github.com/akopytov/sysbench
安装Sysbench
首先在系统上安装Sysbench。大多数发行版软件源都提供了它:
# Ubuntu/Debian
$ sudo apt install sysbench
# Fedora
# dnf install sysbench
# CentOS
# yum install sysbench
# OpenSUSE
# zypper in sysbench
CPU基准测试
$ sysbench cpu --cpu-max-prime=2000 run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Prime numbers limit: 2000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 22757.61
General statistics:
total time: 10.0001s
total number of events: 227609
Latency (ms):
min: 0.04
avg: 0.04
max: 0.12
95th percentile: 0.04
sum: 9968.18
Threads fairness:
events (avg/stddev): 227609.0000/0.00
execution time (avg/stddev): 9.9682/0.00
虽然会生成包含大量统计数据的报告,但 CPU 基准测试的主要内容是"General statistics"下的"total time"。
- 其他命令:
$ sysbench cpu run
$ sysbench cpu --threads=40 run # 默认为单线程
#在检查 CPU 在重负载下的性能时,可使用命令将 CPU 的最大质数限制从 "10000 "扩展到 "15000":
$ sysbench --test=cpu --cpu-max-prime=15000 run
# 帮助
$ sysbench cpu help
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
cpu options:
--cpu-max-prime=N upper limit for primes generator [10000]
内存基准测试
$ sysbench memory --threads=2 run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 2
Initializing random number generator from current time
Running memory speed test with the following options:
block size: 1KiB
total size: 102400MiB
operation: write
scope: global
Initializing worker threads...
Threads started!
Total operations: 28555430 (2855143.49 per second)
27886.16 MiB transferred (2788.23 MiB/sec)
General statistics:
total time: 10.0001s
total number of events: 28555430
Latency (ms):
min: 0.00
avg: 0.00
max: 0.03
95th percentile: 0.00
sum: 12842.67
Threads fairness:
events (avg/stddev): 14277715.0000/1030637.00
execution time (avg/stddev): 6.4213/0.10
这里有两点需要考虑:"Total operations"和"transferred"。
- 其他命令:
$ sysbench memory run
$ sysbench memory --memory-oper=write run # 默认为读
# 要测试特定条件下的内存,例如将内存块大小从默认的 "1KiB "提高到 "1M",同时保持总内存容量为 "8GB"
$ sysbench --test=memory --memory-block-size=1M --memory-total-size=8G run
参考资料
- 软件测试精品书籍文档下载持续更新 https://github.com/china-testing/python-testing-examples 请点赞,谢谢!
- 本文涉及的python测试开发库 谢谢点赞! https://github.com/china-testing/python_cn_resouce
- python精品书籍下载 https://github.com/china-testing/python_cn_resouce/blob/main/python_good_books.md
- Linux精品书籍下载 https://www.cnblogs.com/testing-/p/17438558.html
- https://linuxtechlab.com/benchmark-linux-systems-install-sysbench-tool/
- https://webhostinggeeks.com/howto/how-to-setup-sysbench-for-cpu-and-memory-benchmarking-on-a-linux-machine/
- https://vegastack.com/tutorials/how-to-use-sysbench-for-linux-performance-testing/
IO基准测试
在Linux系统上执行IO基准测试时,我们必须先创建一些测试文件。要创建测试文件,请使用以下命令:
$ sysbench --test=fileio --file-total-size=100G prepare
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
128 files, 819200Kb each, 102400Mb total
Creating files for the test...
Extra file open flags: (none)
Extending existing file test_file.0
...
Extending existing file test_file.127
53687091200 bytes written in 94.39 seconds (542.44 MiB/sec).
请确保选择的测试文件大小大于内存容量,这样IO进程才不会受到内存操作的影响。创建测试文件将根据所选大小花费一些时间。创建测试文件后,运行以下命令开始基准测试:
$ sysbench --test=fileio --file-total-size=100G --file-test-mode=rndrw --max-time=300 --max-requests=0 run
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --max-time is deprecated, use --time instead
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Extra file open flags: (none)
128 files, 800MiB each
100GiB total file size
Block size 16KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...
Threads started!
File operations:
reads/s: 1101.01
writes/s: 734.01
fsyncs/s: 2348.98
Throughput:
read, MiB/s: 17.20
written, MiB/s: 11.47
General statistics:
total time: 300.0508s
total number of events: 1255287
Latency (ms):
min: 0.00
avg: 0.24
max: 2154.60
95th percentile: 0.46
sum: 299665.82
Threads fairness:
events (avg/stddev): 1255287.0000/0.00
execution time (avg/stddev): 299.6658/0.00
文件清理:
$ sysbench --test=fileio --file-total-size=100G cleanup
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Removing test files...
Mysql基准测试
要对mysql进行基准测试,我们首先要在名为"test"的数据库中创建一个有50000 的表,使用以下命令
$ sysbench --test=oltp –oltp-table-size=50000 --mysql-db=test --mysql-user=root --mysql-password=passwd prepare
操作完成后,执行以下命令启动 Mysql Bechmarking:
$ 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
No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 8
Doing OLTP test.
Running mixed OLTP test
Doing read-only test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 7 times)
Done.
OLTP test statistics:
queries performed:
read: 2253860
write: 0
other: 321980
total: 2575840
transactions: 160990 (2683.06 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 2253860 (37562.81 per sec.)
other operations: 321980 (5366.12 per sec.)
Test execution summary:
total time: 60.0024s
total number of events: 160990
total time taken by event execution: 479.3419
per-request statistics:
min: 0.81ms
avg: 2.98ms
max: 3283.40ms
approx. 95 percentile: 4.62ms
Threads fairness:
events (avg/stddev): 20123.7500/63.52
execution time (avg/stddev): 59.9177/0.00
Main parameter to check here is 'transactions per second'
transactions: 160990 (2683.06 per sec.)
测试数据清理:
$ sysbench --test=oltp --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword cleanup
结果解读
总时间越短,表明系统性能越好,尤其是在比较类似测试时。不过必须将这一指标与其他指标结合起来考虑,因为测试时间越短,错误率越高,并不代表性能越好。
Ops/sec是系统吞吐量的直接指标。ops/sec值越高,通常意味着系统在给定时间内可以处理的操作越多,性能越好。例如,如果您运行的是数据库服务器,较高的ops/sec表示您的服务器每秒可以处理更多的查询,从而为最终用户带来更快的响应时间。
延迟对用户体验至关重要。较低的延迟意味着更快地完成操作,这对于视频流或在线游戏等需要实时响应的任务尤为重要。如果您正在托管一个网站,较低的延迟可以加快页面加载时间,提升用户体验。
标签:total,--,基准,time,测试,Linux,test,sysbench,Sysbench From: https://www.cnblogs.com/testing-/p/18299756