`

sysbench 基准测试

阅读更多

转载:http://blog.itpub.net/29733787/viewspace-1383197/

http://blog.csdn.net/clh604/article/details/12108477

sysbench 介绍

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

  1. cpu性能
  2. 磁盘io性能
  3. 调度程序性能
  4. 内存分配及传输速度
  5. POSIX线程性能
  6. 数据库性能(OLTP基准测试)

目前sysbench主要支持 MySQL,pgsql,Oracle 这3种数据库。

sysbench 安装

默认支持MySQL,如果需要测试Oracle/PostgreSQL,则在configure时需要加上–with-oracle或者–with-pgsql参数,
sysbench默认安装在: /usr/local/bin/sysbench

shell> tar -zxvf sysbench-0.5.tar.gz -C /db/tool/
shell> cd /db/tool/sysbench-0.5
shell> chmod +x autogen.sh

shell> ./autogen.sh 
automake 1.10.x (aclocal) wasn't found, exiting
shell> yum install automake
shell> ./autogen.sh 
libtoolize 1.4+ wasn't found, exiting
shell> yum install libtool

shell> ./autogen.sh 
./autogen.sh 
./autogen.sh: running `aclocal -I m4' 
./autogen.sh: running `libtoolize --copy --force' 
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `config'.
libtoolize: copying file `config/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
libtoolize: copying file `m4/libtool.m4'
libtoolize: copying file `m4/ltoptions.m4'
libtoolize: copying file `m4/ltsugar.m4'
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
./autogen.sh: running `autoheader' 
./autogen.sh: running `automake -c --foreign --add-missing' 
configure.ac:23: installing `config/compile'
configure.ac:11: installing `config/config.guess'
configure.ac:11: installing `config/config.sub'
configure.ac:16: installing `config/install-sh'
configure.ac:16: installing `config/missing'
sysbench/Makefile.am: installing `config/depcomp'
./autogen.sh: running `autoconf' 
Libtoolized with: libtoolize (GNU libtool) 2.2.6b
Automade with: automake (GNU automake) 1.11.1
Configured with: autoconf (GNU Autoconf) 2.63

shell> ./configure --prefix=/db/sysbench --with-mysql-includes=/db/mysql/include --with-mysql-libs=/db/mysql/lib
shell> make && make install

测试安装
shell> cp /db/sysbench/bin/sysbench /usr/local/bin/

shell> sysbench --help
sysbench: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: 
No such file or directory
问题原因:sysbench无法找到mysql的库文件,可能是环境变量LD_LIBRARY_PATH没有设置,设置后即可解决该问题: 
添加export LD_LIBRARY_PATH=/db/mysql/lib即可

sysbench 参数

shell> sysbench --help
Missing required command argument.
Usage:
  sysbench [general-options]... --test= [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]
  --forced-shutdown=STRING   amount of time to wait after --max-time before forcing shutdown [off]
  --thread-stack-size=SIZE   size of stack per thread [64K]
  --tx-rate=N                target transaction rate (tps) [0]
  --tx-jitter=N              target transaction variation, in microseconds [0]
  --report-interval=N        periodically report intermediate statistics with a specified interval in seconds. 0 disables
 intermediate reports [0]
  --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 [off]
  --rand-init=[on|off]       initialize random number generator [off]
  --rand-type=STRING         random numbers distribution {uniform,gaussian,special} [special]
  --rand-spec-iter=N         number of iterations used for numbers generation [12]
  --rand-spec-pct=N          percentage of values to be treated as 'special' (for special distribution) [1]
  --rand-spec-res=N          percentage of 'special' values to use (for special distribution) [75]
  --rand-seed=N              seed for random number generator, ignored when 0 [0]

Log options:
  --verbosity=N      verbosity level {5 - debug, 0 - only critical messages} [3]

  --percentile=N      percentile rank of query response times to count [95]

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

Commands: prepare run cleanup help version

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

CPU测试

sysbench CPU测试使用64位整数,测试计算素数直到某个最大值所需要的时间

shell> sysbench --test=cpu --cpu-max-prime=2000 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored


Primer numbers limit: 2000

Threads started!


Test execution summary:
    total time:                          2.2452s
    total number of events:              10000
    total time taken by event execution: 2.2347s
    per-request statistics:
         min:                                  0.20ms
         avg:                                  0.22ms
         max:                                  3.35ms
         approx.  95 percentile:               0.27ms

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

补充:
查看CPU信息方法
查看物理cpu个数
 grep "physical id" /proc/cpuinfo | sort -u | wc -l
查看核心数量
 grep "core id" /proc/cpuinfo | sort -u | wc -l
查看线程数量
 grep "processor" /proc/cpuinfo | sort -u | wc -l

在sysbench的测试中,--num-threads取值为"线程数量"即可

线程(thread)测试

测试线程调度器的性能。对于高负载情况下测试线程调度器的行为非常有用

shell> sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 64
Random number generator seed is 0 and will be ignored


Threads started!


Test execution summary:
    total time:                          1.9581s
    total number of events:              10000
    total time taken by event execution: 124.8938s
    per-request statistics:
         min:                                  0.05ms
         avg:                                 12.49ms
         max:                                151.15ms
         approx.  95 percentile:              50.83ms

Threads fairness:
    events (avg/stddev):           156.2500/14.48
    execution time (avg/stddev):   1.9515/0.00

文件IO性能测试

  • 生成需要的测试文件,文件总大小5G,16个并发线程。执行完后会在当前目录下生成一堆小文件。
shell> sysbench --test=fileio --num-threads=16 --file-total-size=5G prepare
  • 执行测试,指定随机读写模式

指定读写模式:

  1. seqwr 顺序写入
  2. seqrewr 顺序重写
  3. seqrd 顺序读取
  4. rndrd 随机读取
  5. rndwr 随机写入
  6. rndrw 混合随机读/写
shell> sysbench --test=fileio --num-threads=16 --init-rng=on --file-total-size=5G --file-test-mode=rndrw run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 16
Random number generator seed is 0 and will be ignored


Threads started!

Operations performed:  5999 reads, 4001 writes, 12800 Other = 22800 Total
Read 93.734Mb  Written 62.516Mb  Total transferred 156.25Mb  (9.2561Mb/sec)   ##吞吐量
  592.39 Requests/sec executed

Test execution summary:
    total time:                          16.8808s
    total number of events:              10000
    total time taken by event execution: 176.1816s
    per-request statistics:
         min:                                  0.01ms
         avg:                                 17.62ms
         max:                                416.73ms
         approx.  95 percentile:             104.82ms

Threads fairness:
    events (avg/stddev):           625.0000/62.39
    execution time (avg/stddev):   11.0114/0.67
  • 清除测试文件
shell> sysbench --test=fileio --num-threads=16 --file-total-size=5G cleanup

互斥锁(Mutex)测试

测试互斥锁的性能,方式是模拟所有线程在同一时刻并发运行,并都短暂请求互斥锁。

shell> sysbench --test=mutex --num-threads=16 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 16
Random number generator seed is 0 and will be ignored


Threads started!


Test execution summary:
    total time:                          0.0135s
    total number of events:              16
    total time taken by event execution: 0.0411s
    per-request statistics:
         min:                                  0.70ms
         avg:                                  2.57ms
         max:                                  9.19ms
         approx.  95 percentile:               9.16ms

Threads fairness:
    events (avg/stddev):           1.0000/0.00
    execution time (avg/stddev):   0.0026/0.00

内存测试

内存测试测试了内存的连续读写性能。

shell> sysbench --test=memory --num-threads=16 --memory-block-size=8192 --memory-total-size=1G run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 16
Random number generator seed is 0 and will be ignored


Threads started!

Operations performed: 131072 (381158.38 ops/sec)

1024.00 MB transferred (2977.80 MB/sec)       ##吞吐量


Test execution summary:
    total time:                          0.3439s
    total number of events:              131072
    total time taken by event execution: 3.9915s
    per-request statistics:
         min:                                  0.00ms
         avg:                                  0.03ms
         max:                                 51.02ms
         approx.  95 percentile:               0.00ms  ##大约95%的时间分布

Threads fairness:
    events (avg/stddev):           8192.0000/1166.77
    execution time (avg/stddev):   0.2495/0.02

MySQL数据库测试

sysbench 0.5通过一系列LUA脚本来替换之前的oltp,来模拟更接近真实的基准测试环境。这些测试脚本包含:insert.lua、oltp.lua、parallel_prepare.lua、select_random_points.lua、update_index.lua、delete.lua oltp_simple.lua、select.lua、select_random_ranges.lua、update_non_index.lua,脚本使用方式基本类似。

sysbench 0.5默认使用sbtest库,但是需要自己手工先创建好,也可以使用--mysql-db指定,其他非默认项指定选项:

  1. -mysql-host
  2. -mysql-port
  3. -mysql-socket
  4. -mysql-user
  5. -mysql-password
  6. -mysql-db
  7. -mysql-ssl
  • prepare
    生成表并插入数据,可使用parallel_prepare.lua脚本来并行准备数据。
  1. –db-driver 服务器类型 mysql | drizzle,默认为mysql
  2. –mysql-table-engine 表存数引擎
  3. –myisam-max-rows MyISAM表MAX_ROWS选项(用于大表)
  4. –oltp-table-count 生成表数量[sbtest1、sbtest2...]
  5. –oltp-table-size 生成表的行数
  6. –oltp-secondary ID列生成二级索引而不是主键
  7. –oltp-auto-inc 设置ID列是否自增 on | off,默认为on
shell> cd /db/tool/sysbench-0.5/sysbench
shell> sysbench --test=./tests/db/oltp.lua --mysql-table-engine=myisam --oltp-table-size=100000 --mysql-db=test
 --mysql-user=root --oltp-tables-count=10 --mysql-password=oracle --mysql-socket=/tmp/mysql.sock prepare
sysbench 0.5:  multi-threaded system evaluation benchmark

Creating table 'sbtest1'...
Inserting 100000 records into 'sbtest1'
Creating table 'sbtest2'...
Inserting 100000 records into 'sbtest2'
Creating table 'sbtest3'...
Inserting 100000 records into 'sbtest3'
Creating table 'sbtest4'...
Inserting 100000 records into 'sbtest4'
Creating table 'sbtest5'...
Inserting 100000 records into 'sbtest5'
Creating table 'sbtest6'...
Inserting 100000 records into 'sbtest6'
Creating table 'sbtest7'...
Inserting 100000 records into 'sbtest7'
Creating table 'sbtest8'...
Inserting 100000 records into 'sbtest8'
Creating table 'sbtest9'...
Inserting 100000 records into 'sbtest9'
Creating table 'sbtest10'...
Inserting 100000 records into 'sbtest10'

也可使用parallel_prepare.lua脚本并行准备测试数据,线程数应该为运行表的倍数
shell> sysbench --test=./tests/db/parallel_prepare.lua  --mysql-table-engine=myisam --oltp-table-size=100000 
 --num-threads=10 --mysql-db=test  --mysql-user=root --oltp-tables-count=10 --mysql-password=oracle 
 --mysql-socket=/tmp/mysql.sock run

sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 10
Random number generator seed is 0 and will be ignored


Threads started!

thread prepare8
Creating table 'sbtest9'...
thread prepare1
Creating table 'sbtest2'...
thread prepare0
Creating table 'sbtest1'...
thread prepare5
Creating table 'sbtest6'...
thread prepare3
Creating table 'sbtest4'...
thread prepare6
Creating table 'sbtest7'...
thread prepare9
Creating table 'sbtest10'...
thread prepare4
Creating table 'sbtest5'...
thread prepare2
Creating table 'sbtest3'...
thread prepare7
Creating table 'sbtest8'...
Inserting 100000 records into 'sbtest1'
Inserting 100000 records into 'sbtest9'
Inserting 100000 records into 'sbtest8'
Inserting 100000 records into 'sbtest6'
Inserting 100000 records into 'sbtest7'
Inserting 100000 records into 'sbtest2'
Inserting 100000 records into 'sbtest10'
Inserting 100000 records into 'sbtest4'
Inserting 100000 records into 'sbtest5'
Inserting 100000 records into 'sbtest3'
OLTP test statistics:
    queries performed:
        read:                            0
        write:                           380
        other:                           20
        total:                           400
    transactions:                        0      (0.00 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 380    (32.82 per sec.)
    other operations:                    20     (1.73 per sec.)

Test execution summary:
    total time:                          11.5785s
    total number of events:              10000
    total time taken by event execution: 0.1422s
    per-request statistics:
         min:                                  0.00ms
         avg:                                  0.01ms
         max:                                 19.55ms
         approx.  95 percentile:               0.00ms
http://ww3.sinaimg.cn/bmiddle/671c4d8egw1enjimkujv2g20b40b4b29.gif
Threads fairness:
    events (avg/stddev):           1000.0000/2912.74
    execution time (avg/stddev):   0.0142/0.04
  • run
  1. –oltp-tables-count
  2. –oltp-read-only 仅执行SELECT测试 on | off,默认为off
  3. –oltp-dist-type 随机数分布状态。uniform(均匀分布)、gauss(高斯分布)、special(特殊分布)
  4. –oltp-dist-pct 特殊分布的百分比值
  5. –oltp-dist-res 特殊分布的百分比
  6. –oltp-point-selects 单个事务中指定的selec查询个数
  7. –oltp-range-size 范围查询的范围大小,该值应比oltp-table-size小
  8. –oltp-simple-ranges 单个事务中指定的简单范围查询个数
  9. –oltp-sum-ranges 单个事务中指定的SUM范围查询个数
  10. –oltp-order-ranges 单个事务中指定的ORDER范围查询个数
  11. –oltp-distinct-ranges 单个事务中指定的DISTINCT范围查询个数
  12. –oltp-index-updates 单个事务中指定的使用索引更新的个数
  13. –oltp-non-index-updates 单个事务中指定的不使用索引更新的个数
shell> sysbench --test=./tests/db/oltp.lua --num_threads=10  --oltp-table-size=100000 
--mysql-db=test --mysql-user=root --oltp-tables-count=10 --mysql-password=oracle  run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 10
Random number generator seed is 0 and will be ignored


Threads started!

OLTP test statistics:
    queries performed:
        read:                            140028  -- 读总数
        write:                           40008   -- 写总数
        other:                           20004   -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
        total:                           200040  -- 全部总数
    transactions:                        10002  (234.44 per sec.)  -- 总事务数(每秒事务数)
    deadlocks:                           0      (0.00 per sec.)    -- 发生死锁总数
    read/write requests:                 180036 (4219.99 per sec.) -- 读写总数(每秒读写次数)
    other operations:                    20004  (468.89 per sec.)  -- 其他操作总数(每秒其他操作次数)

Test execution summary:
    total time:                          42.6626s  -- 总耗时
    total number of events:              10002     -- 共发生多少事务数
    total time taken by event execution: 426.3020s -- 所有事务耗时相加(不考虑并行因素)
    per-request statistics:
         min:                                  5.36ms   -- 最小耗时
         avg:                                 42.62ms   -- 平均耗时
         max:                                183.44ms   -- 最长耗时
         approx.  95 percentile:              59.81ms   -- 超过99%平均耗时

Threads fairness:
    events (avg/stddev):           1000.2000/23.87
    execution time (avg/stddev):   42.6302/0.01
  • clearnup
shell> sysbench --test=./tests/db/oltp.lua --oltp-table-size=100000 --mysql-db=test --mysql-user=root 
--oltp-tables-count=10 --mysql-password=oracle  cleanup
sysbench 0.5:  multi-threaded system evaluation benchmark

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对OLTP进行测试,看看TPS是不是会有所提高。
注意:sysbench的测试只是基准测试,并不能代表实际企业环境下的性能指标。
 
 
参见:
分享到:
评论

相关推荐

    sysbench 基准测试数据

    sysbench 基准测试结果数据,分为50线程,100线程,200线程。

    sysbench基准测试

    `sysbench`是一款开源的多线程性能基准测试工具,主要用在数据库系统上,但也可用于评估系统的整体性能,包括CPU、内存、磁盘I/O等。它提供了丰富的测试场景,比如OLTP(在线事务处理)操作、CPU压力测试、文件IO...

    基于sysbench开发的毕设项目-sysbench基准测试系统.zip

    matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接...

    sysbench进行cpu,磁盘IO,内存,OLTP基准测试

    sysbench进行cpu,磁盘IO,内存,OLTP基准测试, 一sysbench-05安装 二用法下面的测试案例需要用到这些说明才能看的懂的 三开始测试 cpu性能测试 线程测试 磁盘IO性能测试 内存测试 OLTP测试

    sysbench:基于sysbench开发的毕设项目-sysbench基准测试系统

    sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。 本项目是基于sysbench工具开发的毕设项目。 将测试工具集成为一个测试系统,将每一种测试类型开发为一个子系统。 每个...

    mysql-sysbench测试

    mysql-sysbench测试是指使用sysbench工具对mysql数据库进行基准测试,测试包括cpu测试、I/O基准测试和OLTP基准测试等。sysbench是一个开源的基准测试工具,可以模拟不同的负载场景来测试数据库的性能。 sysbench...

    详解MySQL基准测试和sysbench工具.doc

    数据库的基准测试是对数据库的性能指标进行定量的、可复现的、可对比的测试。基准测试与压力测试 基准测试可以理解为针对系统的一种压力测试。但基准测试不关心业务逻辑,更加简单、直接、易于测试,数据可以由工具...

    sysbench(sysbench-1.0.20)

    sysbench(sysbench-1.0.20)是一个基于LuaJIT的可编写脚本的多线程基准测试工具,主要用于数据库基准测试。 sysbench-1.0.20.tar.gz sysbench-1.0.20.zip

    MySQL数据库基于sysbench实现OLTP基准测试

    sysbench是一款非常优秀的基准测试工具,它能够精准的模拟MySQL数据库存储引擎InnoDB的磁盘的I/O模式。因此,基于sysbench的这个特性,下面利用该工具,对MySQL数据库支撑从简单到复杂事务处理工作负载的基准测试与...

    数据库经典压测工具sysbench双版本 sysbench0.5支持oracle sysbench1.1 支持达梦 附详细文档

    这些文档通常会涵盖环境设置、软件依赖、配置文件设置以及如何运行基准测试等关键信息。 总的来说,sysbench作为一个强大的数据库性能测试工具,能够帮助我们深入了解数据库在各种工作负载下的表现。sysbench0.5和...

    统一开发环境mysql5.7.11基准测试文档_基于sysbench测试工具

    - **范围说明**:此文档旨在通过Sysbench工具对MySQL 5.7.11环境进行基准测试。测试涵盖了两个不同的环境:扬州机房现运行生产环境和移动机房统一开发环境。测试主要从五个维度来进行:CPU计算能力、文件I/O能力、...

    使用sysbench来测试MySQL性能的详细教程

    sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。 目前sysbench代码托管在launchpad上,项目地址:https://launchpad.net/sysbench(原来的官网 ...

    性能测试sysbench.rar

    sysbench的主要功能包括CPU基准测试、内存基准测试、文件系统I/O基准测试和数据库性能测试。对于CPU测试,可以运行: ``` sysbench --test=cpu run ``` 内存测试可以使用`--test=memory`参数,例如: ``` ...

    Android版本的sysbench工具

    sysbench是一个模块化、跨平台、多线程基准测试工具,主要用于测试不同系统参数下的数据库负载情况,本文主要介绍0.4版本的使用。sysbench主要用于以下性能测试: 文件I/O性能 调度 内存分配和传输 POSIX线程 ...

    sysbench-1.0.zip

    sysbench是一款功能强大的系统性能基准测试工具,尤其在MySQL数据库的读写性能测试方面被广泛使用。它不仅可以评估数据库的吞吐量(tps,每秒事务处理量)、查询速率(qps,每秒查询量),还能衡量I/O操作的速度...

    sysbench-1.0.20.tar.gz

    sysbench是一款强大的多线程、跨平台的系统性能基准测试工具,广泛应用于评估系统的CPU、内存、I/O等各项性能。在本文中,我们将深入探讨如何在基于ARM架构的设备上使用sysbench-1.0.20.tar.gz进行CPU性能测试,以及...

    sysbench-master.zip

    sysbench是一款强大的多线程性能基准测试工具,主要应用于数据库系统、操作系统以及CPU性能的评估。它由Alexey Kopytov开发,并在GitHub上开源,链接为<https://github.com/akopytov/sysbench>。sysbench的最新版本...

    sysbench.rar

    **sysbench**是一款开源的、跨平台的系统性能测试和基准测试工具,广泛应用于Linux环境,用于评估数据库、CPU、磁盘I/O等系统的性能。它由Anton Lipov开发,支持多种数据库引擎,包括MySQL、PostgreSQL和Oracle。...

Global site tag (gtag.js) - Google Analytics