【工具】基准测试工具之sysbench

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:
sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况
它主要包括以下几种方式的测试:
1、cpu性能
2、磁盘io性能
3、调度程序性能
4、内存分配及传输速度
5、POSIX线程性能
6、数据库性能(OLTP基准测试)
目前sysbench主要支持 mysql,pgsql,oracle 这3种数据库。
一 前期准备
1 下载 sysbench
  http://sf.net/projects/sysbench/
2 安装:
[root@rac3 ~]# tar zxvf sysbench-0.4.12.tar.gz         
[root@rac3 ~]# cd sysbench-0.4.12
[root@rac3 sysbench-0.4.12]# ls
acinclude.m4  autogen.sh  config     configure.ac  doc      install-sh   Makefile.in  mkinstalldirs  README-WIN.txt  TODO
aclocal.m4    ChangeLog   configure  COPYING       INSTALL  Makefile.am  missing      README         sysbench
[root@rac3 sysbench-0.4.12]# ./autogen.sh 
[root@rac3 sysbench-0.4.12]# 
[root@rac3 sysbench-0.4.12]# ./configure 
--prefix=/usr/local/sysbench \             --指定sysbench的安装目录
--with-mysql-includes=/usr/include/mysql \ --mysql的头文件
--with-mysql-libs=/var/lib/mysql           --mysql 链接库文件
默认是支持mysql的,如果要测试oracle或者pgsql 必须使用--with-oracle ,--with-pgsql 比如:
Note 
如果是oracle,在.bash_profile文件中添加:
export CC=cc
export CXX=c++
export CFLAGS="-m64 -I /opt/oracle/11.2.0/alifpre/rdbms/public"
export CXXFLAGS="$CFLAGS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib 
编译sysbench:
[oracle@rac3 sysbench-0.4.12]# ./autogen.sh 
[oracle@rac3 sysbench-0.4.12]# 
[oracle@rac3 sysbench-0.4.12]# ./configure
--prefix=/home/oracle/sysbench 
--with-oracle-libs=/opt/oracle/11.2.0/alifpre/lib 
--with-oracle 
--without-mysql  --可选
make ORA_LIBS=/opt/oracle/11.2.0/alifpre/lib/libclntsh.so && make install 
3 用法
 Usage:
  sysbench [general-options]... --test= [test-options]... command
General options:
  --num-threads=N            number of threads to use [1] 默认为1 
  --max-requests=N           limit for total number of requests [10000] 最大的请求数
  --max-time=N               limit for total execution time in seconds [0] 默认为 0 为无限制
  --forced-shutdown=STRING   达到最大执行时间未结束,则强制关闭。默认是[off]
  --thread-stack-size=SIZE   size of stack per thread [32K]每个线程的stack的大小
  --init-rng=[on|off]        initialize random number generator [off] 
  --test=STRING              测试类型 cpu,fileio,oltp,mutex,memory
  --debug=[on|off]           print more debugging info [off]
  --validate=[on|off]        perform. validation checks where possible [off]
  --help=[on|off]            print help and exit
  --version=[on|off]         print version and exit
Compiled-in tests:
  fileio - File I/O test
  cpu - CPU performance test
  memory - Memory functions speed test
  threads - Threads subsystem performance test
  mutex - Mutex performance test
  oltp - OLTP test
二 测试
前面介绍了sysbench 是一个可以测试 cpu性能,磁盘io性能,调度程序性能,内存分配及传输速度,POSIX线程性能,数据库性能.下面依次介绍
2.1 测试cup,cpu测试主要是进行素数的加法运算,例子中指定了最大的素数为 80000
[root@rac3 kernel]# sysbench --test=cpu --cpu-max-prime=80000 run  
sysbench 0.4.12:  multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Doing CPU performance benchmark
Threads started!
Done.
Maximum prime number checked in CPU test: 80000
Test execution summary:
    total time:                          172.6663s
    total number of events:              10000
    total time taken by event execution: 172.6490
    per-request statistics:
         min:                                 17.07ms
         avg:                                 17.26ms
         max:                                 73.72ms
         approx.  95 percentile:              17.62ms
Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   172.6490/0.00
2.2 测试fileio
 选项                      描述                   
--file-num       Number of files to create 默认为128
--file-block-size 读写操作是I/O的操作单位默认为16K
--file-total-size 测试文件的总大小 默认为2G
--file-io-mode   I/O mode. Possible values: sync, async, fastmmap, slowmmap (only if supported by the platform, see above). sync
--file-async-backlog Number of asynchronous operations to queue per thread (only for --file-io-mode=async, see above) 128
--file-extra-flags Additional flags to use with open(2)  
--file-fsync-freq Do fsync() after this number of requests (0 - don not use fsync()) 100
--file-fsync-all Do fsync() after each write operation no
--file-fsync-end Do fsync() at the end of the test yes
--file-fsync-mode Which method to use for synchronization. Possible values: fsync, fdatasync (see above) fsync
--file-merged-requests Merge at most this number of I/O requests if possible (0 - don not merge) 0
--file-rw-ratio  reads/writes ration for combined random read/write test 1.5
--file-test-mode  指定文件测试类型:
seqwr   sequential write
seqrewr sequential rewrite
seqrd   sequential read
rndrd   random read
rndwr   random write
rndrw   combined random read/write
下面的例子 prepare 命令创建了128个文件总共大小为10G ,文件读写模式为随机读写混合方式。run 命令则进行测试,并返回结果,cleanup 删除测试产生的文件!
[root@rac3 ~]# sysbench --num-threads=16 --test=fileio --file-total-size=10G --file-test-mode=rndrw prepare                                                   
sysbench 0.4.12:  multi-threaded system evaluation benchmark
128 files, 81920Kb each, 10240Mb total
Creating files for the test...
[root@rac3 ~]# sysbench --num-threads=16 --test=fileio --file-total-size=10G --file-test-mode=rndrw run
Operations performed:  6006 Read, 3994 Write, 12800 ther = 22800 Total
Read 93.844Mb  Written 62.406Mb  Total transferred 156.25Mb  (9.4882Mb/sec)
  607.24 Requests/sec executed
Test execution summary:
    total time:                          16.4678s
    total number of events:              10000
    total time taken by event execution: 225.4641
    per-request statistics:
         min:                                  0.01ms
         avg:                                 22.55ms
         max:                                498.74ms
         approx.  95 percentile:             101.48ms
Threads fairness:
    events (avg/stddev):           625.0000/29.59
    execution time (avg/stddev):   14.0915/0.30
[root@rac3 ~]# sysbench --num-threads=16 --test=fileio --file-total-size=10G --file-test-mode=rndrw cleanup
sysbench 0.4.12:  multi-threaded system evaluation benchmark
Removing test files...
[root@rac3 ~]#   
2.3 memory 内存测试
sysbench 测试memory的时候是顺序读或写内存的。根据选项的不同,每次操作过程中,每个线程可以获取global或本地的数据块
[root@rac3 ~]# sysbench   --test=memory --memory-block-size=1k --memory-total-size=0.5G run
sysbench 0.4.12:  multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Doing memory operations speed test
Memory block size: 0K
Memory transfer size: 0M
Memory operations type: write
Memory scope type: global
Threads started!
Done.
Operations performed: 0 (    0.00 ops/sec)
0.00 MB transferred (0.00 MB/sec)
Test execution summary:
    total time:                          0.0002s
    total number of events:              0
    total time taken by event execution: 0.0000
    per-request statistics:
         min:                            18446744073709.55ms
         avg:                                  0.00ms
         max:                                  0.00ms
Threads fairness:
    events (avg/stddev):           0.0000/0.00
    execution time (avg/stddev):   0.0000/0.00

2.4 thread 测试
[root@rac3 ~]# sysbench --num-threads=64 --test=threads --thread-yields=100 --thread-locks=2 run
sysbench 0.4.12:  multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 64
Doing thread subsystem performance test
Thread yields per test: 100 Locks used: 2
Threads started!
Done.
Test execution summary:
    total time:                          2.0199s
    total number of events:              10000
    total time taken by event execution: 128.6847
    per-request statistics:
         min:                                  0.38ms
         avg:                                 12.87ms
         max:                               2016.38ms
         approx.  95 percentile:               0.42ms
Threads fairness:
    events (avg/stddev):           156.2500/262.89
    execution time (avg/stddev):   2.0107/0.00
2.5 mutex 测试
所有线程同时执行,获取短时间的mutex lock,以便测试mutex的实现!
[root@rac3 ~]# sysbench --test=mutex --mutex-num=4096 --mutex-locks=50000 --mutex-loops=20000 run 
sysbench 0.4.12:  multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Doing mutex performance test
Threads started!
Done.
Test execution summary:
    total time:                          0.0053s
    total number of events:              1
    total time taken by event execution: 0.0051
    per-request statistics:
         min:                                  5.11ms
         avg:                                  5.11ms
         max:                                  5.11ms
         approx.  95 percentile:         10000000.00ms
Threads fairness:
    events (avg/stddev):           1.0000/0.00
    execution time (avg/stddev):   0.0051/0.00
2.6 oltp测试
sysbench 进行oltp 测试的之前,必须创建一个--mysql-db 指定的或者默认的sbtest 数据库,进行prepare的时候,sysbench自动创建一个sbtest表。
[root@rac3 ~]# sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-user=root --mysql-host=127.0.0.1  --mysql-db=test prepare
sysbench 0.4.12:  multi-threaded system evaluation benchmark
No DB drivers specified, using mysql
Creating table 'sbtest'...
Creating 1000000 records in table 'sbtest'...  --创建了一个1000000行的表sbtest
进行测试 三种不同的测试模式:semple,complex,nontrx
[root@rac3 ~]# sysbench --test=oltp \
--mysql-table-engine=innodb \
--oltp-table-size=1000000 \
--mysql-user=root \
--mysql-host=127.0.0.1 \
--mysql-db=test run
OLTP test statistics:
    queries performed:
        read:                            140000
        write:                           50000
        other:                           20000
        total:                           210000
    transactions:                        10000  (292.09 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 190000 (5549.78 per sec.)
    other operations:                    20000  (584.19 per sec.)
Test execution summary:
    total time:                          34.2356s
    total number of events:              10000
    total time taken by event execution: 34.1541
    per-request statistics:
         min:                                  2.80ms
         avg:                                  3.42ms
         max:                                128.54ms
         approx.  95 percentile:               3.60ms
Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   34.1541/0.00
[root@rac3 ~]# sysbench --test=oltp --mysql-table-engine=innodb \
--oltp-table-size=1000000 \
--mysql-user=root \
--mysql-host=127.0.0.1 \
--mysql-db=test \
--oltp-test-mode=complex run
sysbench 0.4.12:  multi-threaded system evaluation benchmark
OLTP test statistics:
    queries performed:
        read:                            140000
        write:                           50000
        other:                           20000
        total:                           210000
    transactions:                        10000  (294.07 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 190000 (5587.40 per sec.)
    other operations:                    20000  (588.15 per sec.)
Test execution summary:
    total time:                          34.0051s
    total number of events:              10000
    total time taken by event execution: 33.9249
    per-request statistics:
         min:                                  2.78ms
         avg:                                  3.39ms
         max:                                114.85ms
         approx.  95 percentile:               3.57ms
Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   33.9249/0.00
若进行mode为nontrx 的测试之前,已经进行了其他两种模式的测试,先执行cleanup 或者prepare
[root@rac3 ~]# sysbench --test=oltp \
--mysql-table-engine=innodb \
--oltp-table-size=1000000 \
--mysql-user=root \
--mysql-host=127.0.0.1  \
--mysql-db=test \
--oltp-test-mode=nontrx run 
OLTP test statistics:
    queries performed:
        read:                            10000
        write:                           0
        other:                           0
        total:                           10000
    transactions:                        10000  (12276.25 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 10000  (12276.25 per sec.)
    other operations:                    0      (0.00 per sec.)
Test execution summary:
    total time:                          0.8146s
    total number of events:              10000
    total time taken by event execution: 0.7892
    per-request statistics:
         min:                                  0.07ms
         avg:                                  0.08ms
         max:                                  0.41ms
         approx.  95 percentile:               0.09ms
Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   0.7892/0.00
[root@rac3 ~]# sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-user=root --mysql-host=127.0.0.1  --mysql-db=test --oltp-test-mode=nontrx cleanup
sysbench 0.4.12:  multi-threaded system evaluation benchmark
No DB drivers specified, using mysql
Dropping table 'sbtest'...
Done.
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
2月前
|
机器学习/深度学习 人工智能 测试技术
EdgeMark:嵌入式人工智能工具的自动化与基准测试系统——论文阅读
EdgeMark是一个面向嵌入式AI的自动化部署与基准测试系统,支持TensorFlow Lite Micro、Edge Impulse等主流工具,通过模块化架构实现模型生成、优化、转换与部署全流程自动化,并提供跨平台性能对比,助力开发者在资源受限设备上高效选择与部署AI模型。
336 9
EdgeMark:嵌入式人工智能工具的自动化与基准测试系统——论文阅读
|
2月前
|
Java 测试技术 API
自动化测试工具集成及实践
自动化测试用例的覆盖度及关键点最佳实践、自动化测试工具、集成方法、自动化脚本编写等(兼容多语言(Java、Python、Go、C++、C#等)、多框架(Spring、React、Vue等))
137 6
|
3月前
|
前端开发 Java jenkins
Jmeter压力测试工具全面教程和使用技巧。
JMeter是一个能够模拟高并发请求以检查应用程序各方面性能的工具,包括但不限于前端页面、后端服务及数据库系统。熟练使用JMeter不仅能够帮助发现性能瓶颈,还能在软件开发早期就预测系统在面对真实用户压力时的表现,确保软件质量和用户体验。在上述介绍的基础上,建议读者结合官方文档和社区最佳实践,持续深入学习和应用。
852 10
|
3月前
|
监控 Java 数据挖掘
利用Jmeter工具进行HTTP接口的性能测试操作
基础上述步骤反复迭代调整直至满足预期目标达成满意水平结束本轮压力评估周期进入常态监控阶段持续关注系统运转状态及时发现处理新出现问题保障服务稳定高效运作
515 0
|
4月前
|
敏捷开发 运维 数据可视化
DevOps看板工具中的协作功能:如何打破开发、测试与运维之间的沟通壁垒
在DevOps实践中,看板工具通过可视化任务管理和自动化流程,提升开发与运维团队的协作效率。它支持敏捷开发、持续交付,助力团队高效应对需求变化,实现跨职能协作与流程优化。
|
5月前
|
Java 测试技术 容器
Jmeter工具使用:HTTP接口性能测试实战
希望这篇文章能够帮助你初步理解如何使用JMeter进行HTTP接口性能测试,有兴趣的话,你可以研究更多关于JMeter的内容。记住,只有理解并掌握了这些工具,你才能充分利用它们发挥其应有的价值。+
968 23
|
5月前
|
数据可视化 测试技术 Go
Go 语言测试与调试:`go test` 工具用法
`go test` 是 Go 语言内置的测试工具,支持单元测试、基准测试、示例测试等功能。本文详解其常用参数、调试技巧及性能测试命令,并提供实际项目中的应用示例与最佳实践。
|
4月前
|
人工智能 数据可视化 测试技术
UAT测试排程工具深度解析:让验收测试不再失控,项目稳稳上线
在系统交付节奏加快的背景下,“测试节奏混乱”已成为项目延期的主因之一。UAT测试排程工具应运而生,帮助团队结构化拆解任务、清晰分配责任、实时掌控进度,打通需求、测试、开发三方协作闭环,提升测试效率与质量。本文还盘点了2025年热门UAT工具,助力团队选型落地,告别靠表格和群聊推进测试的低效方式,实现有节奏、有章法的测试管理。
|
5月前
|
弹性计算 JavaScript Ubuntu
WebSocket协议相关的测试命令工具使用简介
本文介绍了针对WebSocket的测试工具wscat和websocat的基本使用方法,以及通过curl命令测试HTTP/HTTPS协议的方式。对于WebSocket,直接使用curl测试较为复杂,推荐使用wscat或websocat。文中详细说明了这两种工具的安装步骤、常用参数及连接示例,例如在ECS上开启8080端口监听并进行消息收发测试。此外,还提供了curl命令的手动设置头部信息以模拟WebSocket握手的示例,但指出curl仅能作为客户端测试工具,无法模拟服务器。
1233 4
|
11月前
|
Java 测试技术 数据安全/隐私保护
软件测试中的自动化策略与工具应用
在软件开发的快速迭代中,自动化测试以其高效、稳定的特点成为了质量保证的重要手段。本文将深入探讨自动化测试的核心概念、常见工具的应用,以及如何设计有效的自动化测试策略,旨在为读者提供一套完整的自动化测试解决方案,帮助团队提升测试效率和软件质量。