mysql性能测试工具之sysbench

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

(1).cpu性能

(2).磁盘io性能

(3).调度程序性能

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

(5).POSIX线程性能

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

1.下载和安装sysbench工具

[[email protected] home]# wget http://down1.chinaunix.net/distfiles/sysbench-0.4.10.tar.gz

[[email protected] home]# cd sysbench-0.4.10

[[email protected] 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 [email protected]

[[email protected] 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/

[[email protected] 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

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

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

[[email protected] 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

[[email protected] 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

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

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

[[email protected] sysbench-0.4.10]# make                    --此时不会再有错误了

[[email protected] sysbench-0.4.10]# make install

[[email protected] sysbench-0.4.10]# echo $?                 --检查是否安装成功
0

[[email protected] 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
[[email protected] sysbench-0.4.10]#

2.测试CPU的性能

[[email protected] 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.

[[email protected] 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

[[email protected] bin]#

3.线程(threads)测试

[[email protected] 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

[[email protected] bin]#

4.内存(memory)测试

[[email protected] 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

[[email protected] bin]#

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

[[email protected] bin]# ./sysbench --test=fileio --file-total-size=20G prepare
sysbench 0.4.10:  multi-threaded system evaluation benchmark

128 files, 163840Kb each, 20480Mb total
Creating files for the test...
[[email protected] bin]#

6.数据库mysql的测试

[[email protected] 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 []

[[email protected] 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‘...

[[email protected] 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

[[email protected] bin]#

时间: 2024-07-31 00:55:27

mysql性能测试工具之sysbench的相关文章

Mysql 性能测试工具 sysbench的安装和使用

工作上需要用到AWS和Azure的Mysql服务,需要测试比较一下两个云服务的性能.于是开始百度 + google,查找性能测试工具.最终决定用sysbench. sysbench介绍 sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试. 数据库目前支持MySQL/Oracle/PostgreSQL.本文只是简单演示一下几种测试的用法,后续准备利用sysbench来对MySQL进行一系列的测试.具体的一些参数设置,需要根据不同的测试要求来进行

MySQL性能测试工具sysbench的安装和使用

sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据库的性能测试.目前支持的数据库有MySQL.Oracle和PostgreSQL.当前功能允许测试的系统参数有: file I/O performance (文件I / O性能) scheduler performance (调度性能) memory allocation and transfer speed (内存分配和传输速度) POSIX threads implementat

mysql性能测试工具之mysqlslap

mysqlslap是mysql自带的基准测试工具,优点:查询数据,语法简单,灵活容易使用.该工具可以模拟多个客户端同时并发的向服务器发出查询更新,给出了性能测试数据而且提供了多种引擎的性能比较.msqlslap为mysql性能优化前后提供了直观的验证依据,建议系统运维和DBA人员应该掌握一些常见的压力测试工具,才能准确的掌握线上数据库支撑的用户流量上限及其抗压性等问题. 工具详细参数 --help      显示帮助 --concurrency      代表并发数量,多个可以用逗号隔开 --e

MySQL性能测试工具之mysqlslap使用详解

mysqlslap是mysql自带的基准测试工具,优点:查询数据,语法简单,灵活容易使用.该工具可以模拟多个客户端同时并发的向服务器发出查询更新,给出了性能测试数据而且提供了多种引擎的性能比较.msqlslap为mysql性能优化前后提供了直观的验证依据,建议系统运维和DBA人员应该掌握一些常见的压力测试工具,才能准确的掌握线上数据库支撑的用户流量上限及其抗压性等问题. 常用的选项--concurrency 并发数量,多个可以用逗号隔开--engines 要测试的引擎,可以有多个,用分隔符隔开,

mysql性能测试工具之tpcc-mysql

1.安装配置 官网下载地址:http://imysql.com/wp-content/uploads/2014/09/tpcc-mysql-src.tgz1. 用bzr客户端下载软件包[[email protected] ~]# yum install bzr -y [[email protected] ~]# bzr branch lp:~percona-dev/perconatools/tpcc-mysql[[email protected] ~]# cd tpcc-mysql/src/[[

mysql 性能测试工具 mysqlslap

原文链接: https://my.oschina.net/moooofly/blog/152547 连接数据库: # mysqlslap -h localhost -uroot -p123456 --concurrency=50 模拟客户--iterations=200 执行多少次--number-int-cols=2 2个int 类型--number-char-cols=3 3个vachar类型--auto-generate-sql 自动生成sql--query=query.sql --que

MySQL性能测试工具 mysqlslap

1.使用自动生成脚本测试数据库性能 mysqlslap -uroot -p123 -a --debug-info --concurrency=50,100  --number-of-queries=200 --engine=myisam,innodb 参数介绍 -u : 用户名 -p : 密码 -a (--auto-generate-sql) : 自动生成sql脚本测试数据库 --debug-info : 输出debug信息,包括内存,CPU等 --concurrency : 用户并发数,可填写

MySQL组复制技术实现与数据库性能测试工具

测试环境 本文档是在 99Cloud Lab OpenStack 平台虚机上面测试,仅供参考. 系统: CentOS 7.3 虚机: 2 核 4G 版本: MySQL 5.7 技术架构 MySQL Group Replication(简称 MGR)是官方推出的高可用解决方案,原生复制技术,基于插件的方式工作.其中 single primary mode 单主模式只有一个读写,其余都是只读. multi primary mode多主模式全部可读写 不管组复制单主还是多主的故障切换都无法让应用无感知

MySQL实用工具汇总

本文收录了mysql相关的实用工具.工具包括:性能测试,状态分析,SQL路由,及运维开发相关的所有工具,并会持续更新. 1.工具套件集 - percona-toolkit - oak-toolkit - ps-helper(performance schema 工具函数集) 2.mysql实时状态分析 - innotop - orzdba - mytop - systemtap工具示例集 3.mysql客户端&开发工具 - MySQL Workbench - SQLyog - Adminer -