mysql性能测试工具之sysbench

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

  sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数 下的数据库负载情况,主要测试以下几种:

(1).cpu性能

(2).磁盘io性能

(3).调度程序性能

(4).内存分配及传输速度

(5).POSIX线程性能

(6).数据库性能(OLTP基准测试)


mysql dba技术群 378190849

武汉-linux运维群 236415619

 

1.下载和安装sysbench工具

[root@centos179min home]# wget http://down1.chinaunix.net/distfiles/sysbench-0.4.10.tar.gz

[root@centos179min home]# cd sysbench-0.4.10

[root@centos179min sysbench-0.4.10]# ./configure  --help | grep mysql        --自己仔细查看安装帮助
  --with-mysql            compile with MySQL support (default is enabled)
  --with-mysql-includes   path to MySQL header files
  --with-mysql-libs       path to MySQL libraries
Report bugs to alexeyk@mysql.com.

[root@centos179min sysbench-0.4.10]# ./configure  --prefix=/usr/local/sysbench-0.4.10 --with-mysql --with-mysql-includes=/usr/local/mysql-5.7.4-m14-linux/include/ --with-mysql-libs=/usr/local/mysql-5.7.4-m14-linux/lib/

[root@centos179min sysbench-0.4.10]# make        --这时如果以下错误

drv_mysql.c: In function 'mysql_drv_store_results':
drv_mysql.c:784: error: 'MYSQL' undeclared (first use in this function)
drv_mysql.c:784: error: 'con' undeclared (first use in this function)
drv_mysql.c:785: error: 'MYSQL_RES' undeclared (first use in this function)
drv_mysql.c:785: error: 'res' undeclared (first use in this function)
drv_mysql.c:786: error: 'MYSQL_ROW' undeclared (first use in this function)
drv_mysql.c:786: error: expected ';' before 'row'
drv_mysql.c:834: error: 'ER_LOCK_DEADLOCK' undeclared (first use in this function)
drv_mysql.c:834: error: 'ER_LOCK_WAIT_TIMEOUT' undeclared (first use in this function)
drv_mysql.c:850: error: 'row' undeclared (first use in this function)
drv_mysql.c: In function 'mysql_drv_free_results':
drv_mysql.c:874: error: 'MYSQL_RES' undeclared (first use in this function)
drv_mysql.c:874: error: expected expression before ')' token
make[3]: *** [libsbmysql_a-drv_mysql.o] Error 1
make[3]: Leaving directory `/home/sysbench-0.4.10/sysbench/drivers/mysql'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/sysbench-0.4.10/sysbench/drivers'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/sysbench-0.4.10/sysbench'
make: *** [all-recursive] Error 1

[root@centos179min sysbench-0.4.10]# yum install mysql-devel      --解决方法,安装mysql-devel开发包

[root@centos179min sysbench-0.4.10]# rpm -ql mysql-devel | grep include     --查看开发包的路径

[root@centos179min sysbench-0.4.10]# ./configure  --prefix=/usr/local/sysbench-0.4.10 --with-mysql --with-mysql-includes=/usr/include/mysql/   --with-mysql-libs=/usr/local/mysql-5.7.4-m14-linux/lib/mysql   

[root@centos179min sysbench-0.4.10]# make        --这时如果再有以下错误

../libtool: line 841: X--tag=CC: command not found
../libtool: line 874: libtool: ignoring unknown tag : command not found
../libtool: line 841: X--mode=link: command not found
../libtool: line 1007: *** Warning: inferring the mode of operation is deprecated.: command not found
../libtool: line 1008: *** Future versions of Libtool will require --mode=MODE be specified.: command not found
../libtool: line 2234: X-g: command not found
../libtool: line 2234: X-O2: command not found
../libtool: line 1954: X-L/usr/local/mysql-5.7.4-m14-linux/lib/mysql: No such file or directory
../libtool: line 2403: Xsysbench: command not found
../libtool: line 2408: X: command not found
../libtool: line 2415: Xsysbench: command not found
../libtool: line 2550: X-lmysqlclient_r: command not found
../libtool: line 2550: X-lrt: command not found
../libtool: line 2550: X-lm: command not found
../libtool: line 2632: X-L/home/sysbench-0.4.10/sysbench: No such file or directory
../libtool: line 2550: X-lmysqlclient_r: command not found
../libtool: line 2550: X-lrt: command not found
../libtool: line 2550: X-lm: command not found
../libtool: line 2632: X-L/home/sysbench-0.4.10/sysbench: No such file or directory

[root@centos179min sysbench-0.4.10]# vim libtool       --解决方法(将libtool文件中的"ECHO="改为"echo=")

ECHO="echo"       修改为   echo="echo"

[root@centos179min sysbench-0.4.10]# make                    --此时不会再有错误了

[root@centos179min sysbench-0.4.10]# make install

[root@centos179min sysbench-0.4.10]# echo $?                 --检查是否安装成功
0

[root@centos179min sysbench-0.4.10]# ll /usr/local/sysbench-0.4.10/bin/
total 288
-rwxr-xr-x. 1 root root 293649 Oct  8 20:00 sysbench
[root@centos179min sysbench-0.4.10]#

 

2.测试CPU的性能

[root@centos179min bin]# ./sysbench  --help |more             --命令帮助                  
Usage:
  sysbench [general-options]... --test=<test-name> [test-options]... command

General options:
  --num-threads=N            number of threads to use [1]
  --max-requests=N           limit for total number of requests [10000]
  --max-time=N               limit for total execution time in seconds [0]
  --thread-stack-size=SIZE   size of stack per thread [32K]
  --init-rng=[on|off]        initialize random number generator [off]
  --test=STRING              test to run
  --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

Commands: prepare run cleanup help version

See 'sysbench --test=<name> help' for a list of options for each test.

[root@centos179min bin]# ./sysbench  --test=cpu --cpu-max-prime=20000 run     --测试CPU的性能
sysbench 0.4.10:  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: 20000


Test execution summary:
    total time:                          23.3571s
    total number of events:              10000
    total time taken by event execution: 23.3527
    per-request statistics:
         min:                                  2.23ms
         avg:                                  2.34ms
         max:                                 11.08ms
         approx.  95 percentile:               2.58ms

Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   23.3527/0.00

[root@centos179min bin]#

 

3.线程(threads)测试

[root@centos179min bin]# ./sysbench  --test=threads --num-threads=64 run 
sysbench 0.4.10:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 64

Doing thread subsystem performance test
Thread yields per test: 1000 Locks used: 8
Threads started!
Done.


Test execution summary:
    total time:                          4.8920s
    total number of events:              10000
    total time taken by event execution: 311.4399
    per-request statistics:
         min:                                  0.39ms
         avg:                                 31.14ms
         max:                               1167.60ms
         approx.  95 percentile:              87.74ms

Threads fairness:
    events (avg/stddev):           156.2500/9.58
    execution time (avg/stddev):   4.8662/0.02

[root@centos179min bin]#

 

 4.内存(memory)测试

[root@centos179min bin]# ./sysbench --test=memory --memory-block-size=8K --memory-total-size=2G  --num-threads=16 run
sysbench 0.4.10:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 16

Doing memory operations speed test
Memory block size: 8K

Memory transfer size: 2048M

Memory operations type: write
Memory scope type: global
Threads started!
Done.

Operations performed: 262144 (735089.70 ops/sec)

2048.00 MB transferred (5742.89 MB/sec)


Test execution summary:
    total time:                          0.3566s
    total number of events:              262144
    total time taken by event execution: 4.9494
    per-request statistics:
         min:                                  0.00ms
         avg:                                  0.02ms
         max:                                 47.02ms
         approx.  95 percentile:               0.00ms

Threads fairness:
    events (avg/stddev):           16384.0000/1285.55
    execution time (avg/stddev):   0.3093/0.01

[root@centos179min bin]#

 

5.文件(file)的输入和输出测试

[root@centos179min bin]# ./sysbench --test=fileio --file-total-size=20G prepare    --创建20G的文件大小
sysbench 0.4.10:  multi-threaded system evaluation benchmark

128 files, 163840Kb each, 20480Mb total
Creating files for the test...

[root@centos179min bin]#  ./sysbench --test=fileio --file-total-size=20G --file-test-mode=rndwr run

--读和写20G的文件输出IO值
sysbench 0.4.10:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1

Extra file open flags: 0
128 files, 160Mb each
20Gb total file size
Block size 16Kb
Number of random requests for random IO: 10000
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 write test
Threads started!
Done.

Operations performed:  0 Read, 10000 Write, 12800 Other = 22800 Total
Read 0b  Written 156.25Mb  Total transferred 156.25Mb  (1.858Mb/sec)
  118.91 Requests/sec executed

Test execution summary:
    total time:                          84.0955s
    total number of events:              10000
    total time taken by event execution: 0.2631
    per-request statistics:
         min:                                  0.01ms
         avg:                                  0.03ms
         max:                                 11.91ms
         approx.  95 percentile:               0.05ms

Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   0.2631/0.00

[root@centos179min bin]#  ./sysbench --test=fileio --file-total-size=20G --file-test-mode=rndwr cleanup     --删除刚才创建的文件

 

6.数据库mysql的测试

[root@centos179min bin]# ./sysbench  --test=oltp help           --查看帮助
sysbench 0.4.10:  multi-threaded system evaluation benchmark

oltp options:
  --oltp-test-mode=STRING         test type to use {simple,complex,nontrx,sp} [complex]
  --oltp-sp-name=STRING           name of store procedure to call in SP test mode []
  --oltp-read-only=[on|off]       generate only 'read' queries (do not modify database) [off]
  --oltp-skip-trx=[on|off]        skip BEGIN/COMMIT statements [off]
  --oltp-range-size=N             range size for range queries [100]
  --oltp-point-selects=N          number of point selects [10]
  --oltp-simple-ranges=N          number of simple ranges [1]
  --oltp-sum-ranges=N             number of sum ranges [1]
  --oltp-order-ranges=N           number of ordered ranges [1]
  --oltp-distinct-ranges=N        number of distinct ranges [1]
  --oltp-index-updates=N          number of index update [1]
  --oltp-non-index-updates=N      number of non-index updates [1]
  --oltp-nontrx-mode=STRING       mode for non-transactional test {select, update_key, update_nokey, insert, delete} [select]
  --oltp-auto-inc=[on|off]        whether AUTO_INCREMENT (or equivalent) should be used on id column [on]
  --oltp-connect-delay=N          time in microseconds to sleep after connection to database [10000]
  --oltp-user-delay-min=N         minimum time in microseconds to sleep after each request [0]
  --oltp-user-delay-max=N         maximum time in microseconds to sleep after each request [0]
  --oltp-table-name=STRING        name of test table [sbtest]
  --oltp-table-size=N             number of records in test table [10000]
  --oltp-dist-type=STRING         random numbers distribution {uniform,gaussian,special} [special]
  --oltp-dist-iter=N              number of iterations used for numbers generation [12]
  --oltp-dist-pct=N               percentage of values to be treated as 'special' (for special distribution) [1]
  --oltp-dist-res=N               percentage of 'special' values to use (for special distribution) [75]

General database options:

  --db-driver=STRING  specifies database driver to use ('help' to get list of available drivers)
  --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]


Compiled-in database drivers:
  mysql - MySQL driver

mysql options:
  --mysql-host=[LIST,...]       MySQL server host [localhost]
  --mysql-port=N                MySQL server port [3306]
  --mysql-socket=STRING         MySQL socket
  --mysql-user=STRING           MySQL user [sbtest]
  --mysql-password=STRING       MySQL password []
  --mysql-db=STRING             MySQL database name [sbtest]
  --mysql-table-engine=STRING   storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]
  --mysql-engine-trx=STRING     whether storage engine used is transactional or not {yes,no,auto} [auto]
  --mysql-ssl=[on|off]          use SSL connections, if available in the client library [off]
  --myisam-max-rows=N           max-rows parameter for MyISAM tables [1000000]
  --mysql-create-options=STRING additional options passed to CREATE TABLE []

[root@centos179min bin]# ./sysbench --test=oltp --mysql-user=root --mysql-password=system --mysql-db=tong --oltp-table-name=sbtest --mysql-table-engine=innodb --oltp-table-size=1000000 prepare          --准备测试的数据
sysbench 0.4.10:  multi-threaded system evaluation benchmark

No DB drivers specified, using mysql
Creating table 'sbtest'...
Creating 1000000 records in table 'sbtest'...

[root@centos179min bin]# ./sysbench --test=oltp --mysql-port=3306 --mysql-user=root --mysql-password=system --mysql-db=tong --oltp-table-name=sbtest --mysql-table-engine=innodb  --oltp-table-size=1000000 --max-requests=1000 --num-threads=100 run    --测试mysql的并发和压力
sysbench 0.4.10:  multi-threaded system evaluation benchmark

No DB drivers specified, using mysql
WARNING: Preparing of "BEGIN" is unsupported, using emulation
(last message repeated 99 times)
Running the test with following options:
Number of threads: 100

Doing OLTP test.
Running mixed OLTP 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
Maximum number of requests for OLTP test is limited to 1000
Threads started!
Done.

OLTP test statistics:
    queries performed:
        read:                            14000
        write:                           5000
        other:                           2000
        total:                           21000
    transactions:                        1000   (143.56 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 19000  (2727.71 per sec.)
    other operations:                    2000   (287.13 per sec.)

Test execution summary:
    total time:                          6.9655s
    total number of events:              1000
    total time taken by event execution: 683.5913
    per-request statistics:
         min:                                 88.12ms
         avg:                                683.59ms
         max:                               3688.93ms
         approx.  95 percentile:            1362.33ms

Threads fairness:
    events (avg/stddev):           10.0000/1.23
    execution time (avg/stddev):   6.8359/0.10

[root@centos179min bin]#

 










本文转自 z597011036 51CTO博客,原文链接:http://blog.51cto.com/tongcheng/1561207,如需转载请自行联系原作者
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
1月前
|
Java 测试技术 数据安全/隐私保护
软件测试中的自动化策略与工具应用
在软件开发的快速迭代中,自动化测试以其高效、稳定的特点成为了质量保证的重要手段。本文将深入探讨自动化测试的核心概念、常见工具的应用,以及如何设计有效的自动化测试策略,旨在为读者提供一套完整的自动化测试解决方案,帮助团队提升测试效率和软件质量。
|
26天前
|
Web App开发 IDE 测试技术
Selenium:强大的 Web 自动化测试工具
Selenium 是一款强大的 Web 自动化测试工具,包括 Selenium IDE、WebDriver 和 Grid 三大组件,支持多种编程语言和跨平台操作。它能有效提高测试效率,解决跨浏览器兼容性问题,进行性能测试和数据驱动测试,尽管存在学习曲线较陡、不稳定等缺点,但其优势明显,是自动化测试领域的首选工具。
148 17
Selenium:强大的 Web 自动化测试工具
|
18天前
|
SQL 关系型数据库 MySQL
MySQL 窗口函数详解:分析性查询的强大工具
MySQL 窗口函数从 8.0 版本开始支持,提供了一种灵活的方式处理 SQL 查询中的数据。无需分组即可对行集进行分析,常用于计算排名、累计和、移动平均值等。基本语法包括 `function_name([arguments]) OVER ([PARTITION BY columns] [ORDER BY columns] [frame_clause])`,常见函数有 `ROW_NUMBER()`, `RANK()`, `DENSE_RANK()`, `SUM()`, `AVG()` 等。窗口框架定义了计算聚合值时应包含的行。适用于复杂数据操作和分析报告。
59 11
|
2月前
|
机器学习/深度学习 人工智能 算法
BALROG:基准测试工具,用于评估 LLMs 和 VLMs 在复杂动态环境中的推理能力
BALROG 是一款用于评估大型语言模型(LLMs)和视觉语言模型(VLMs)在复杂动态环境中推理能力的基准测试工具。它通过一系列挑战性的游戏环境,如 NetHack,测试模型的规划、空间推理和探索能力。BALROG 提供了一个开放且细粒度的评估框架,推动了自主代理研究的进展。
46 3
BALROG:基准测试工具,用于评估 LLMs 和 VLMs 在复杂动态环境中的推理能力
|
2月前
|
监控 测试技术 开发工具
移动端性能测试工具
移动端性能测试工具
57 2
|
2月前
|
安全 前端开发 测试技术
如何选择合适的自动化安全测试工具
选择合适的自动化安全测试工具需考虑多个因素,包括项目需求、测试目标、系统类型和技术栈,工具的功能特性、市场评价、成本和许可,以及集成性、误报率、社区支持、易用性和安全性。综合评估这些因素,可确保所选工具满足项目需求和团队能力。
|
2月前
|
安全 网络协议 关系型数据库
最好用的17个渗透测试工具
渗透测试是安全人员为防止恶意黑客利用系统漏洞而进行的操作。本文介绍了17款业内常用的渗透测试工具,涵盖网络发现、无线评估、Web应用测试、SQL注入等多个领域,包括Nmap、Aircrack-ng、Burp Suite、OWASP ZAP等,既有免费开源工具,也有付费专业软件,适用于不同需求的安全专家。
222 2
|
2月前
|
监控 网络协议 Java
一些适合性能测试脚本编写和维护的工具
一些适合性能测试脚本编写和维护的工具
|
2月前
|
关系型数据库 MySQL 测试技术
【赵渝强老师】MySQL的基准测试与sysbench
本文介绍了MySQL数据库的基准测试及其重要性,并详细讲解了如何使用sysbench工具进行测试。内容涵盖sysbench的安装、基本使用方法,以及具体测试MySQL数据库的步骤,包括创建测试数据库、准备测试数据、执行测试和清理测试数据。通过这些步骤,可以帮助读者掌握如何有效地评估MySQL数据库的性能。
|
3月前
|
Java 关系型数据库 MySQL
自动化测试项目实战笔记(一):JDK、Tomcat、MySQL、Jpress环境安装和搭建
这篇文章是关于自动化测试项目实战笔记,涵盖了JDK、Tomcat、MySQL、Jpress环境的安装和搭建过程,以及测试用例和常见问题总结。
65 1
自动化测试项目实战笔记(一):JDK、Tomcat、MySQL、Jpress环境安装和搭建