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 0.5 基准测试的更多相关文章

  1. sysbench 0.5使用手册

    注意:本文刚开始只介绍了sysbench 0.5之前的版本,在了解了sysbench 0.5之后进行了补充,大部分测试和参数都是一样的,只是sysbench 0.5 在测试数据库方面更加全面丰富. 关 ...

  2. sysbench 0.5 oltp测试笔记

    sysbench 0.5相比0.4版本的主要变化是,oltp测试结合了lua脚本,不需要修改源码,通过自定义lua脚本就可以实现不同业务类型的测试.同时0.5相比0.4需要消耗更多的cpu资源. 1. ...

  3. 使用sysbench 0.5 对mysql 进行性能、压力测试

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

  4. IBM Power PC安装sysbench 执行mysql基准测试 --- sysbench安装

    第一步:下载Sysbench http://dev.mysql.com/downloads/benchmarks.html 第二步:解压sysbench 第三步:执行安装步骤 1. ./autogen ...

  5. sysbench 0.4.12安装

    前提:mysql已安装完成,请参考http://www.cnblogs.com/lizhi221/p/6813907.html   安装依赖环境包: yum install -y bzr yum in ...

  6. MySQL基准测试工具--sysbench

    我们需要知道的是sysbench并不是一个压力测试工具,是一个基准测试工具.linux自带的版本比较低,我们需要自己安装sysbench. [root@test2 ~]# sysbench --ver ...

  7. mysql基准测试与sysbench工具

    一.基准测试简介  1.什么是基准测试 数据库的基准测试是对数据库的性能指标进行定量的.可复现的.可对比的测试. 基准测试与压力测试 基准测试可以理解为针对系统的一种压力测试.但基准测试不关心业务逻辑 ...

  8. sysbench基准测试工具

    一.简介SysBench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况.当前功能允许测试的系统参数有:file I/O performance (文件I ...

  9. MySQL基准测试和sysbench工具

    参考https://www.cnblogs.com/kismetv/archive/2017/09/30/7615738.html 一.基准测试的作用 sysbench是一个开源的.模块化的.跨平台的 ...

随机推荐

  1. memory prefix un,under,uni out1

    1● un 不 非,无 打开 ,解开 ,开出     2● under ʌnd ə 向下,副 的,不足的   3● uni   单一 ,单  

  2. linux System V IPC Mechanisms

    Message Queues Semaphores Shared Memory

  3. customization arm ubuntu rootfs

    requirment: want to get arm ubuntu rootfs method: base on debootstrap tool, customization full funct ...

  4. 全球信息安全会议 Top 50

    信息安全会议在世界范围内举办,下面是全球最值得参加的50个信息安全会议的简介,以时间顺序列出.需要注意的是,这份清单基于2016年的信息撰写,因为具体日期与地点每年或有不同,请至活动官网确认具体的日期 ...

  5. Hibernate: ids for this class must be manually assigned before calling save():

    原文: http://blog.csdn.net/softimes/article/details/7008875 引起问题的原因: 由Hibernate根据数据库表自动生成的"类名.hbm ...

  6. SaltStack一键部署负载均衡和高可用

    一.负载均衡的部署 server1    haproxy (调度器) server2    apache server3    nginx 1)在server1上首先安装salt-minion服务.并 ...

  7. SWIFT中隐藏TableView多余的分隔线

    在用TableView是如果数据不能填充满整个屏幕时,数据行下面会有空行及分隔线,这样不是很美观,如下 如何把多余的部分删除掉呢,其它很简单,把TableView的Footer替换为一个空的UIVie ...

  8. Oracle Statistic 统计信息 小结

    oraclestatisticstabledatabasesqldictionary   目录(?)[-] 直方图上列的信息说明 直方图类型说明   一.  Statistic 说明 Oracle 官 ...

  9. 批量解帧视频文件cpp

    前言 将多个视频文件进行解帧. 实现过程 1.批量获取文件路径: 2.对某个视频文件进行解帧: 代码 /************************************************ ...

  10. Linux/Unix下Shell快捷键操作集合

    本人收集整理了一些Bash或其他Shell中常用的快捷键,使用技巧以及Ubuntu中一些常用操作的快捷键,希望大家能从中受益,提高工作效率. 使用”!”从历史中执行命令 有时候,我们需要在 Bash ...