--2017-11-07更新 sysbench 1.0.9+安装及简单使用:{
安装1:通过EPEL直接yum安装
EPEL可以装一下(如果没装)
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum install -y sysbench 即可
此处仅针对mysql做oltp测试做介绍:
安装好后,会在/usr/share/sysbench/下存放lua脚本
安装2:去https://github.com/akopytov/sysbench把sysbench.zip或者直接git clone下来
cd xxx/sysbench-master
make clean
./autogen.sh
./configure --prefix=/usr/local/sysbench/ --with-mysql --with-mysql-libs=/usr/lib64/mysql/
make && make install
根据具体情况可能需要指定不同的--with-mysql-libs
此处mysql依赖,通过rpm包默认安在/usr/lib64/mysql/
用法与老版本相近,此处举例:
sysbench --db-driver=mysql /usr/share/sysbench/oltp_read_only.lua --mysql-host=$host --mysql-port=$port --mysql-user=$user --mysql-password=$password --mysql-db=sysbench(需自行创建) --tables=100 --table-size=5000000 --report-interval=10 --threads=64 --time=7200 prepare/run/cleanup
}
--2017-11-07更新 sysbench 0.5 安装及简单使用
{
$ sudo yum install gcc gcc-c++ automake make libtool mysql-community-devel
$ cd /tmp && git clone https://github.com/akopytov/sysbench.git
$ cd /tmp/sysbench && ./autogen.sh
$ ./configure --prefix=/usr/local/sysbench-0.5 --with-mysql
$ make && make install
$ cd /usr/local/sysbench-0.5/bin
如mysql
$ ./sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 prepare
$ ./sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
如fio等
$ ./sysbench --test=fileio --file-total-size=5G prepare
$ ./sysbench --test=fileio --file-total-size=5G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run
$ ./sysbench --test=fileio --file-total-size=5G cleanup
}
此处用的是sysbench 0.5
0.4.12版本和0.5类似
可以为用户提供如下测试:
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
p.s.
在mysql官方推荐的是 sysbench 0.4.12.10
http://dev.mysql.com/downloads/benchmarks.html
一. 安装
解压后:
- $ cd sysbench-0.5
- $ ./autogen.sh
- $ ./configure --prefix=(选择sysbench安装在哪) (如果需要测试oltp可以加后面的选项)--with-mysql-includes=/usr/local/mysql/include(换成你自己的) --with-mysql-libs=/usr/local/mysql/lib --with-mysql (还可以支持oracle和pgsql
- $ make && make install
可能需要安装一下环境:
- $ sudo yum -y install libtool automake
源码来安装 autoconf和automake
附带这两个源码包url
http://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz
http://mirrors.kernel.org/gnu/automake/automake-1.15.tar.gz
配 置环境变量:
- $ vi ~/.bash_profile
sysbench --version 或者直接 sysbench 可以看到版本信息或者帮助信息
- $ source ~/.bash_profile
- $ sysbench --version
- sysbench 0.5
sysbench: error while loading shared libraries: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory
则有可能是lib路径不对
$ sudo vi /etc/ld.so.conf 添加 /usr/local/mysql/lib 保存退出 $ sudo /sbin/ldconfig -v
二. file IO
指定--test=fileio即可。
fileio options:
--file-num=N number of files to create [128]
// 创建的文件数
--file-block-size=N block size to use in all IO operations [16384]
// 块大小,比如4096为4K
--file-total-size=SIZE total size of files to create [2G]
// 要创建文件的总大小
--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
// 磁盘访问模式,分别为顺序写,顺序读写,顺序读,随机写,随机读写,随机读
--file-io-mode=STRING file operations mode {sync,async,mmap} [sync]
// 文件操作模式,分别为同步,异步,映射至内存,缺省为同步
--file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []
// 打开文件的附加标识
--file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100]
// 在某个数请求之后做fsync(),缺省为100
--file-fsync-all=[on|off] do fsync() after each write operation [off]
// 打开或关闭在每个写操作后执行fsync(),缺省为OFF
--file-fsync-end=[on|off] do fsync() at the end of test [on]
// 打开或关闭结束test时执行fsync(),缺省为ON
--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]
// 使用什么方法同步,缺省为fsync
--file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]
// 尽可能合并IO请求的数量,缺省为0
--file-rw-ratio=N reads/writes ratio for combined test [1.5]
// 读写比例,默认为1.5
测试例子:
- $ sysbench --test=fileio --file-num=10 --file-total-size=1G --file-block-size=4096 --file-test-mode=seqwr --file-io-mode=sync prepare // 先做文件准备 参数为prepare 创建10个文件 每个102.4MB 文件块为4K
- sysbench 0.5: multi-threaded system evaluation benchmark
- 10 files, 104857Kb each, 1023Mb total
- Creating files for the test...
- Extra file open flags: 0
- Creating file test_file.0
- Creating file test_file.1
- Creating file test_file.2
- Creating file test_file.3
- Creating file test_file.4
- Creating file test_file.5
- Creating file test_file.6
- Creating file test_file.7
- Creating file test_file.8
- Creating file test_file.9
- 1073766400 bytes written in 12.11 seconds (84.56 MB/sec).
-
- $ sysbench --test=fileio --file-num=10 --file-total-size=1G --file-block-size=4096 --file-test-mode=seqwr --file-io-mode=sync run // 开始测试,参数改为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
- Extra file open flags: 0
- 10 files, 102.4Mb each
- 1024Mb total file size
- Block size 4Kb
- Periodic FSYNC enabled, calling fsync() each 100 requests.
- Calling fsync() at the end of test, Enabled.
- Using synchronous I/O mode
- Doing sequential write (creation) test
- Threads started!
- Operations performed: 0 reads, 10000 writes, 1000 Other = 11000 Total
- Read 0b Written 39.062Mb Total transferred 39.062Mb (8.3495Mb/sec)
- 2137.47 Requests/sec executed
- General statistics:
- total time: 4.6784s
- total number of events: 10000
- total time taken by event execution: 0.0767s
- response time:
- min: 0.00ms
- avg: 0.01ms
- max: 0.08ms
- approx. 95 percentile: 0.01ms
- Threads fairness:
- events (avg/stddev): 10000.0000/0.00
- execution time (avg/stddev): 0.0767/0.00
- $ sysbench --test=fileio --file-num=10 --file-total-size=1G --file-block-size=4096 --file-test-mode=seqwr --file-io-mode=sync cleanup // 参数为cleanup 清除测试文件
- sysbench 0.5: multi-threaded system evaluation benchmark
- Removing test files...
三. CPU test
指定--test=cpu即可。
cpu options:
--cpu-max-prime=N upper limit for primes generator [10000]
// 设置素数最大上限值,缺省为10000
测试例子:
- $ sysbench --test=cpu --cpu-max-prime=1024 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: 1024
- Threads started!
- General statistics:
- total time: 0.4622s
- total number of events: 10000
- total time taken by event execution: 0.4561s
- response time:
- min: 0.04ms
- avg: 0.05ms
- max: 0.15ms
- approx. 95 percentile: 0.05ms
- Threads fairness:
- events (avg/stddev): 10000.0000/0.00
- execution time (avg/stddev): 0.4561/0.00
四. memory test
指定--test=memory即可。
memory options:
--memory-block-size=SIZE size of memory block for test [1K]
// 内存块的大小,缺省为1K
--memory-total-size=SIZE total size of data to transfer [100G]
// 总共需要传输的大小,缺省为100G
--memory-scope=STRING memory access scope {global,local} [global]
// 内存访问是全局还是本地,缺省为全局
--memory-hugetlb=[on|off] allocate memory from HugeTLB pool [off]
// 是否从HugeTLB中分配内存,缺省为否
--memory-oper=STRING type of memory operations {read, write, none} [write]
// 内存的操作方式,读,写,或none,缺省为写
--memory-access-mode=STRING memory access mode {seq,rnd} [seq]
// 内存访问模式,顺序或随机,默认为序列
测试例子:
- $ sysbench --test=memory --memory-block-size=4096 --memory-total-size=50G --memory-oper=read --memory-access-mode=rnd 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
- Threads started!
- Operations performed: 13107200 (950195.57 ops/sec)
- 51200.00 MB transferred (3711.70 MB/sec)
- General statistics:
- total time: 13.7942s
- total number of events: 13107200
- total time taken by event execution: 5.8543s
- response time:
- min: 0.00ms
- avg: 0.00ms
- max: 0.06ms
- approx. 95 percentile: 0.00ms
- Threads fairness:
- events (avg/stddev): 13107200.0000/0.00
- execution time (avg/stddev): 5.8543/0.00
五. threads test
指定--test=threads即可。
threads options:
--thread-yields=N number of yields to do per request [1000]
--thread-locks=N number of locks per thread [8]
// 每个线程锁的数目
测试例子:
- [op@sAno1y sysbench]$ sysbench --test=threads 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
- Threads started!
- General statistics:
- total time: 3.6699s
- total number of events: 10000
- total time taken by event execution: 3.6635s
- response time:
- min: 0.35ms
- avg: 0.37ms
- max: 0.74ms
- approx. 95 percentile: 0.37ms
- Threads fairness:
- events (avg/stddev): 10000.0000/0.00
- execution time (avg/stddev): 3.6635/0.00
六. mutex test
指定--test=mutex即可。
mutex options:
--mutex-num=N total size of mutex array [4096]
// 互斥体数据大小,缺省为4K
--mutex-locks=N number of mutex locks to do per thread [50000]
// 每个线程的互斥锁,缺省为50000
--mutex-loops=N number of empty loops to do inside mutex lock [10000]
// 互斥锁内空循环的数目,缺省为10000
测试例子:
- [op@sAno1y sysbench]$ sysbench --test=mutex --mutex-num=8192 --number-locks=102400 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
- Threads started!
- General statistics:
- total time: 0.0049s
- total number of events: 1
- total time taken by event execution: 0.0048s
- response time:
- min: 4.79ms
- avg: 4.79ms
- max: 4.79ms
- approx. 95 percentile: 4.79ms
- Threads fairness:
- events (avg/stddev): 1.0000/0.00
- execution time (avg/stddev): 0.0048/0.00
七. oltp test
oltp options:
General database options:
--db-driver=STRING specifies database driver to use ('help' to get list of available drivers)
--d b-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,ndbclu ster,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 []
创建测试数据:
--oltp-table- s ize为单表创建数据的数量
- sysbench --test=oltp --mysql-table-engine=innodb --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root --mysql-db=test --oltp-table-size=50000000 prepare
开始run:其中--num-threads为并发数,--max-time为测试的时长(秒)
- sysbench --test=oltp --mysql-table-engine=innodb --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root --mysql-db=test --oltp-table-size=5000000 --num-threads=1000 --max-time=60 --max-requests=0 --report-interval=10 run
在sysbench 0.5的版本中,则可以使用一个lua脚本来创建表,并且可以指定多张表,比如:
其中 oltp_tables_count为指定prepare几张 表 ,--rand-init打开则表示随机写数:
- sysbench --test=/opt/app/sysbench-0.5/sysbench/tests/db/oltp.lua --mysql-table-engine=innodb --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-host=localhost --mysql-password=root --mysql-db=test \
- --oltp-table-size=50000000 --oltp_tables_count=10 --rand-init=on prepare
生成的测试表的数据样例:
*************************** 1. row ***************************
id: 1
k: 50206885
c: 08566691963-88624912351-16662227201-46648573979-64646226163-77505759394-75470094713-41097360717-15161106334-50535565977
pad: 63188288836-92351140030-06390587585-66802097351-49282961843
*************************** 2. row ***************************
id: 2
k: 49910688
c: 95969429576-20587925969-20202408199-67602281819-18293380360-38184587501-73192830026-41693404212-56705243222-89212376805
pad: 09512 147864-77936258834-40901700703-13541171421-15205431759
*************************** 3. row ***************************
id: 3
k: 50204693
c: 26283585383-48610978532-72166636310-67148386979-89643583984-06169170732-23477134062-17788128188-73465768032-24619558652
pad: 21979564480-87492594656-60524686334-78820761788-57684966682
*************************** 4. row ***************************
id: 4
k: 52180295
c: 72200234338-75748118569-08939863650-01688814841-36798767826-71560494483-89421079440-11810718401-29133837777-68338627243
pad: 80945118876-33522718290-51523426562-15979384524-91541356971
********* ****************** 5. row ***************************
id: 5
k: 41395699
c: 29279855805-99348203463-85191104223-39587263726-81794340135-73817557808-54578801760-64404111877-55434439976-37212880746
pad: 59222897263-22759023974-22020489960-93434521232-77981152534
5 rows in set (0.00 sec)
测试结果 说 明:
- No DB drivers specified, using mysql
- Running the test with following options:
- Number of threads: 1
- Random number generator seed is 0 and will be ignored
- 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 10000
- Using 1 test tables
- Threads started!
- Done.
- OLTP test statistics:
- queries performed:
- read: 140000 -- 读总数
- write: 50000 -- 写总数
- other: 20000 -- 其他操作总数(除了dml之外的操作)
- total: 210000 -- 全部总数
- transactions: 10000 (229.62 per sec.) -- 总事务数
- deadlocks: 0 (0.00 per sec.) -- 死锁数
- read/write requests: 190000 (4362.73 per sec.) -- 读写总数
- other operations: 20000 (459.23 per sec.) -- 其他操作总数
- General statistics:
- total time: 43.5507s -- 总耗时
- total number of events: 10000 -- 总共发生的事务数
- total time taken by event execution: 43.4491 -- 所有事务耗时相加(不考虑并行因素)
- response time:
- min: 3.75ms -- 最小耗时
- avg: 4.34ms -- 平均耗时
- max: 30.58ms -- 最大耗时
- approx. 95 percentile: 4.44ms -- 去掉5%的最大最小值,剩余95%平均耗时
- Threads fairness:
- events (avg/stddev): 10000.0000/0.00
- execution time (avg/stddev): 43.4491/0.00
附录: (通用选项)
- 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]
- --report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
- --report-checkpoints=[LIST,...]dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []
- --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,pareto} [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]
- --rand-pareto-h=N parameter h for pareto distibution [0.2]
- 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.
作者公众号(持续更新)
![](http://img.blog.itpub.net/blog/attachment/201805/23/29773961_1527064425HFqs.png?x-oss-process=style/bb)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29773961/viewspace-1849676/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29773961/viewspace-1849676/