it编程 > 软件设计 > 软件测试

服务器性能测试利器之sysbench详解

113人参与 2024-12-18 软件测试

前言

sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行cpu、内存、磁盘i/o、线程、数据库的性能测试。sysbench是基于luajit的可编写脚本的多线程基准测试工具。

sysbench附带以下捆绑的基准测试:

特征

安装

    安装以centos为例,其他版本或者mac请参考sysbench说明

1.下载安转

wget https://github.com/akopytov/sysbench/archive/1.0.zip -o "sysbench-1.0.zip"
unzip sysbench-1.0.zip
cd sysbench-1.0
//安装依赖
yum install -y automake libtool

2.编译安装

./autogen.sh
./configure
export ld_library_path=/usr/include/mysql
make
make install

3.监测是否安装成功

[root@guanbin-k8s-master ~]# sysbench --version
sysbench 1.0.19  

测试

1. cpu测试

   cpu测试主要是进行素数的加法运算,我们的例子中,指定了最大的质数发生器数量为 20000

[root@guanbin-k8s-master ~]# sysbench --test=cpu --cpu-max-prime=20000 run
warning: the --test option is deprecated. you can pass a script name or path on the command line without any options.
sysbench 1.0.19 (using bundled luajit 2.1.0-beta2)
running the test with following options:
number of threads: 1
initializing random number generator from current time
prime numbers limit: 20000
initializing worker threads...
threads started!
cpu speed:
    events per second:   168.59
general statistics:
    total time:                          10.0027s
    total number of events:              1687
latency (ms):
         min:                                    5.63
         avg:                                    5.93
         max:                                   66.09
         95th percentile:                        6.43
         sum:                                 9999.10
threads fairness:
    events (avg/stddev):           1687.0000/0.00
    execution time (avg/stddev):   9.9991/0.00

执行时间 大约为10秒(这个测试最好是两台机器进行对比测试,才能发现那个机器有问题)

2.对内存(memory)进行测试 

   测试是在内存中传输 10g 的数据量,每个 block 大小为 8k

[root@guanbin-k8s-master ~]# sysbench --test=memory --memory-block-size=8k --memory-total-size=10g run
warning: the --test option is deprecated. you can pass a script name or path on the command line without any options.
sysbench 1.0.19 (using bundled luajit 2.1.0-beta2)
running the test with following options:
number of threads: 1
initializing random number generator from current time
running memory speed test with the following options:
  block size: 8kib
  total size: 10240mib
  operation: write
  scope: global
initializing worker threads...
threads started!
total operations: 1310720 (724931.70 per second)
10240.00 mib transferred (5663.53 mib/sec)
general statistics:
    total time:                          1.8045s
    total number of events:              1310720
latency (ms):
         min:                                    0.00
         avg:                                    0.00
         max:                                   12.44
         95th percentile:                        0.00
         sum:                                 1441.61
threads fairness:
    events (avg/stddev):           1310720.0000/0.00
    execution time (avg/stddev):   1.4416/0.00

totaltime为1.8045s

3.对disk 的io测试

新建一个临时目录,并确保磁盘剩余空间足够(--file-total-size不要超过剩余容量)

测试场景:16个线程,创建128个文件,总共占用磁盘空间10gb,测试磁盘读写效率

运行结束后要删除临时测试文件: rm -rf test_file.*

root@guanbin-k8s-master tmp]# sysbench --test=fileio --num-threads=16 --file-total-size=1g --file-test-mode=rndrw prepare
warning: the --test option is deprecated. you can pass a script name or path on the command line without any options.
warning: --num-threads is deprecated, use --threads instead
sysbench 1.0.19 (using bundled luajit 2.1.0-beta2)
128 files, 8192kb each, 1024mb total
creating files for the test...
extra file open flags: (none)
creating file test_file.0
creating file test_file.1
creating file test_file.2
creating file test_file.3
creating file test_file.4
creating file test_file.5
creating file test_file.6
creating file test_file.7
creating file test_file.8
creating file test_file.9
creating file test_file.10
creating file test_file.11
creating file test_file.12
creating file test_file.13
creating file test_file.14
creating file test_file.15
creating file test_file.16
creating file test_file.17
creating file test_file.18
creating file test_file.19
creating file test_file.20
creating file test_file.21
creating file test_file.22
creating file test_file.23
creating file test_file.24
creating file test_file.25
creating file test_file.26
creating file test_file.27
creating file test_file.28
creating file test_file.29
creating file test_file.30
creating file test_file.31
creating file test_file.32
creating file test_file.33
creating file test_file.34
creating file test_file.35
creating file test_file.36
creating file test_file.37
creating file test_file.38
creating file test_file.39
creating file test_file.40
creating file test_file.41
creating file test_file.42
creating file test_file.43
creating file test_file.44
creating file test_file.45
creating file test_file.46
creating file test_file.47
creating file test_file.48
creating file test_file.49
creating file test_file.50
creating file test_file.51
creating file test_file.52
creating file test_file.53
creating file test_file.54
creating file test_file.55
creating file test_file.56
creating file test_file.57
creating file test_file.58
creating file test_file.59
creating file test_file.60
creating file test_file.61
creating file test_file.62
creating file test_file.63
creating file test_file.64
creating file test_file.65
creating file test_file.66
creating file test_file.67
creating file test_file.68
creating file test_file.69
creating file test_file.70
creating file test_file.71
creating file test_file.72
creating file test_file.73
creating file test_file.74
creating file test_file.75
creating file test_file.76
creating file test_file.77
creating file test_file.78
creating file test_file.79
creating file test_file.80
creating file test_file.81
creating file test_file.82
creating file test_file.83
creating file test_file.84
creating file test_file.85
creating file test_file.86
creating file test_file.87
creating file test_file.88
creating file test_file.89
creating file test_file.90
creating file test_file.91
creating file test_file.92
creating file test_file.93
creating file test_file.94
creating file test_file.95
creating file test_file.96
creating file test_file.97
creating file test_file.98
creating file test_file.99
creating file test_file.100
creating file test_file.101
creating file test_file.102
creating file test_file.103
creating file test_file.104
creating file test_file.105
creating file test_file.106
creating file test_file.107
creating file test_file.108
creating file test_file.109
creating file test_file.110
creating file test_file.111
creating file test_file.112
creating file test_file.113
creating file test_file.114
creating file test_file.115
creating file test_file.116
creating file test_file.117
creating file test_file.118
creating file test_file.119
creating file test_file.120
creating file test_file.121
creating file test_file.122
creating file test_file.123
creating file test_file.124
creating file test_file.125
creating file test_file.126
creating file test_file.127
1073741824 bytes written in 110.77 seconds (9.24 mib/sec).
[root@guanbin-k8s-master tmp]# sysbench --test=fileio --num-threads=16 --file-total-size=1g --file-test-mode=rndrw run
warning: the --test option is deprecated. you can pass a script name or path on the command line without any options.
warning: --num-threads is deprecated, use --threads instead
sysbench 1.0.19 (using bundled luajit 2.1.0-beta2)
running the test with following options:
number of threads: 16
initializing random number generator from current time
extra file open flags: (none)
128 files, 8mib each
1gib 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:                      157.44
    writes/s:                     104.96
    fsyncs/s:                     480.79
throughput:
    read, mib/s:                  2.46
    written, mib/s:               1.64
general statistics:
    total time:                          13.3355s
    total number of events:              7865
latency (ms):
         min:                                    0.00
         avg:                                   20.61
         max:                                 1115.85
         95th percentile:                      142.39
         sum:                               162071.40
threads fairness:
    events (avg/stddev):           491.5625/141.20
    execution time (avg/stddev):   10.1295/0.03  

吞吐量:读2.46mib/s,写1.64mib/s; 95%延迟 142.39ms

4.测试mysql性能

       测试时使用的脚本为lua脚本,可以使用sysbench自带脚本,也可以自己开发。对于大多数应用,使用sysbench自带的脚本就足够了。不同版本的sysbench中,lua脚本的位置可能不同,可以自己在sysbench路径下使用find命令搜索oltp.lua。

     p.s.:大多数数据服务都是oltp类型的,如果你不了解什么是oltp,那么大概率你的数据服务就是oltp类型的。mysql oltp(on-line transaction processing联机事务处理过程);

下面是sysbench使用的一个例子:

 注意:先准备数据库

mysql> create database sbtest;

 其中,执行模式为complex,使用了10个表,每个表有10万条数据,客户端的并发线程数为10,执行时间为120秒,每10秒生成一次报告。

sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host={yourhostip} --mysql-port=3306 --mysql-user={username} --mysql-password={password} --oltp-test-mode=complex --mysql-table-engine=innodb --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 prepare

其中的hostip、username、password请自行切换为自己真实的环境数据

查看执行结果

sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host={yourhostip} --mysql-port=3306 --mysql-user={username} --mysql-password={password} --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 run
running the test with following options:
number of threads: 10
report intermediate results every 10 second(s)
initializing random number generator from current time
initializing worker threads...
threads started!
[ 10s ] thds: 10 tps: 17.19 qps: 362.78 (r/w/o: 254.64/72.76/35.38) lat (ms,95%): 1589.90 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 10 tps: 33.50 qps: 670.08 (r/w/o: 469.06/134.02/67.01) lat (ms,95%): 530.08 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 10 tps: 39.30 qps: 786.00 (r/w/o: 550.20/157.20/78.60) lat (ms,95%): 458.96 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 10 tps: 38.80 qps: 775.45 (r/w/o: 543.16/154.69/77.59) lat (ms,95%): 634.66 err/s: 0.00 reconn/s: 0.00
[ 50s ] thds: 10 tps: 30.10 qps: 602.54 (r/w/o: 421.43/120.91/60.20) lat (ms,95%): 590.56 err/s: 0.00 reconn/s: 0.00
[ 60s ] thds: 10 tps: 33.90 qps: 678.00 (r/w/o: 474.60/135.60/67.80) lat (ms,95%): 419.45 err/s: 0.00 reconn/s: 0.00
[ 70s ] thds: 10 tps: 29.50 qps: 589.98 (r/w/o: 412.99/118.00/59.00) lat (ms,95%): 787.74 err/s: 0.00 reconn/s: 0.00
[ 80s ] thds: 10 tps: 39.90 qps: 798.02 (r/w/o: 558.62/159.60/79.80) lat (ms,95%): 569.67 err/s: 0.00 reconn/s: 0.00
[ 90s ] thds: 10 tps: 38.10 qps: 761.99 (r/w/o: 533.40/152.40/76.20) lat (ms,95%): 484.44 err/s: 0.00 reconn/s: 0.00
[ 100s ] thds: 10 tps: 43.90 qps: 877.99 (r/w/o: 614.60/175.60/87.80) lat (ms,95%): 383.33 err/s: 0.00 reconn/s: 0.00
[ 110s ] thds: 10 tps: 37.80 qps: 756.00 (r/w/o: 529.20/151.20/75.60) lat (ms,95%): 530.08 err/s: 0.00 reconn/s: 0.00
[ 120s ] thds: 10 tps: 44.40 qps: 888.01 (r/w/o: 621.60/177.60/88.80) lat (ms,95%): 419.45 err/s: 0.00 reconn/s: 0.00
sql statistics:
    queries performed:
        read:                            59836
        write:                           17096
        other:                           8548
        total:                           85480
    transactions:                        4274   (35.59 per sec.)
    queries:                             85480  (711.77 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)
general statistics:
    total time:                          120.0919s
    total number of events:              4274
latency (ms):
         min:                                   50.07
         avg:                                  280.96
         max:                                 2486.17
         95th percentile:                      559.50
         sum:                              1200810.10
threads fairness:
    events (avg/stddev):           427.4000/4.20
    execution time (avg/stddev):   120.0810/0.01

其中,对于我们比较重要的信息包括:

queries:查询总数及qps

transactions:事务总数及tps

latency-95th percentile:前95%的请求的最大响应时间,本例中是344毫秒,这个延迟非常大,是因为我用的mysql服务器性能很差;在正式环境中这个数值是绝对不能接受的。

最后清理数据:

sysbench ./tests/include/oltp_legacy/oltp.lua --mysql-host={yourhostip} --mysql-port=3306 --mysql-user={username} --mysql-password={password} --oltp-tables-count=10  cleanup

清理的日志输出

sysbench 1.0.19 (using bundled luajit 2.1.0-beta2)
dropping table 'sbtest1'...
dropping table 'sbtest2'...
dropping table 'sbtest3'...
dropping table 'sbtest4'...
dropping table 'sbtest5'...
dropping table 'sbtest6'...
dropping table 'sbtest7'...
dropping table 'sbtest8'...
dropping table 'sbtest9'...
dropping table 'sbtest10'...

到此这篇关于服务器性能测试利器之sysbench的文章就介绍到这了,更多相关服务器性能测试sysbench内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)
打赏 微信扫一扫 微信扫一扫

您想发表意见!!点此发布评论

推荐阅读

使用nacos命名空间namespace用法,测试时做实例隔离

12-25

使用Jmeter进行http接口测试的详细流程

12-30

如何测试计算机的内存是否存在问题? 判断电脑内存故障的多种方法

01-06

首款国产DDR5 32GB内存强不强? 金百达银爵DDR5调试+超频测试

01-09

发布7年的Ryzen 5 2600X能否再战? 七款游戏性能测试出炉

01-16

发布6年的Ryzen 3 3200G还值得买吗? 七款游戏性能测试出炉

01-16

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论