压测工具 sysbench安装及使用简介(0.4.12\0.5\1.0.x+版本)


--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

 
一. 安装
解压后:

  1. $ cd sysbench-0.5
  2. $ ./autogen.sh
  3. $ ./configure --prefix=(选择sysbench安装在哪) (如果需要测试oltp可以加后面的选项)--with-mysql-includes=/usr/local/mysql/include(换成你自己的) --with-mysql-libs=/usr/local/mysql/lib --with-mysql (还可以支持oracle和pgsql
  4. $ make && make install

可能需要安装一下环境:
  1. $ 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


置环境变量:
  1. $ vi ~/.bash_profile

sysbench --version 或者直接 sysbench 可以看到版本信息或者帮助信息
  1. $ source ~/.bash_profile
  2. $ sysbench --version
  3. 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



测试例子:

  1. $ 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 
  2. sysbench 0.5: multi-threaded system evaluation benchmark
  3. 10 files, 104857Kb each, 1023Mb total
  4. Creating files for the test...
  5. Extra file open flags: 0
  6. Creating file test_file.0
  7. Creating file test_file.1
  8. Creating file test_file.2
  9. Creating file test_file.3
  10. Creating file test_file.4
  11. Creating file test_file.5
  12. Creating file test_file.6
  13. Creating file test_file.7
  14. Creating file test_file.8
  15. Creating file test_file.9
  16. 1073766400 bytes written in 12.11 seconds (84.56 MB/sec).

  17. $ sysbench --test=fileio --file-num=10 --file-total-size=1G --file-block-size=4096 --file-test-mode=seqwr --file-io-mode=sync run    // 开始测试,参数改为run
  18. sysbench 0.5: multi-threaded system evaluation benchmark
  19. Running the test with following options:
  20. Number of threads: 1
  21. Random number generator seed is 0 and will be ignored
  22. Extra file open flags: 0
  23. 10 files, 102.4Mb each
  24. 1024Mb total file size
  25. Block size 4Kb
  26. Periodic FSYNC enabled, calling fsync() each 100 requests.
  27. Calling fsync() at the end of test, Enabled.
  28. Using synchronous I/O mode
  29. Doing sequential write (creation) test
  30. Threads started!
  31. Operations performed: 0 reads, 10000 writes, 1000 Other = 11000 Total
  32. Read 0b Written 39.062Mb Total transferred 39.062Mb (8.3495Mb/sec)
  33. 2137.47 Requests/sec executed
  34. General statistics:
  35. total time: 4.6784s
  36. total number of events: 10000
  37. total time taken by event execution: 0.0767s
  38. response time:
  39. min: 0.00ms
  40. avg: 0.01ms
  41. max: 0.08ms
  42. approx. 95 percentile: 0.01ms
  43. Threads fairness:
  44. events (avg/stddev): 10000.0000/0.00
  45. execution time (avg/stddev): 0.0767/0.00
  46. $ sysbench --test=fileio --file-num=10 --file-total-size=1G --file-block-size=4096 --file-test-mode=seqwr --file-io-mode=sync cleanup    // 参数为cleanup 清除测试文件
  47. sysbench 0.5: multi-threaded system evaluation benchmark
  48. Removing test files...


三. CPU test

指定--test=cpu即可

cpu options:
  --cpu-max-prime=N      upper limit for primes generator [10000]       
// 设置素数最大上限值,缺省为10000 



测试例子:

  1. $ sysbench --test=cpu --cpu-max-prime=1024 run
  2. sysbench 0.5: multi-threaded system evaluation benchmark
  3. Running the test with following options:
  4. Number of threads: 1
  5. Random number generator seed is 0 and will be ignored
  6. Primer numbers limit: 1024
  7. Threads started!
  8. General statistics:
  9. total time: 0.4622s
  10. total number of events: 10000
  11. total time taken by event execution: 0.4561s
  12. response time:
  13. min: 0.04ms
  14. avg: 0.05ms
  15. max: 0.15ms
  16. approx. 95 percentile: 0.05ms
  17. Threads fairness:
  18. events (avg/stddev): 10000.0000/0.00
  19. 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]
// 内存访问模式,顺序或随机,默认为序列



测试例子:

  1. $ sysbench --test=memory --memory-block-size=4096 --memory-total-size=50G --memory-oper=read --memory-access-mode=rnd run
  2. sysbench 0.5: multi-threaded system evaluation benchmark
  3. Running the test with following options:
  4. Number of threads: 1
  5. Random number generator seed is 0 and will be ignored
  6. Threads started!
  7. Operations performed: 13107200 (950195.57 ops/sec)
  8. 51200.00 MB transferred (3711.70 MB/sec)
  9. General statistics:
  10. total time: 13.7942s
  11. total number of events: 13107200
  12. total time taken by event execution: 5.8543s
  13. response time:
  14. min: 0.00ms
  15. avg: 0.00ms
  16. max: 0.06ms
  17. approx. 95 percentile: 0.00ms
  18. Threads fairness:
  19. events (avg/stddev): 13107200.0000/0.00
  20. 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]
// 每个线程锁的数目



测试例子:

  1. [op@sAno1y sysbench]$ sysbench --test=threads run
  2. sysbench 0.5: multi-threaded system evaluation benchmark
  3. Running the test with following options:
  4. Number of threads: 1
  5. Random number generator seed is 0 and will be ignored
  6. Threads started!
  7. General statistics:
  8. total time: 3.6699s
  9. total number of events: 10000
  10. total time taken by event execution: 3.6635s
  11. response time:
  12. min: 0.35ms
  13. avg: 0.37ms
  14. max: 0.74ms
  15. approx. 95 percentile: 0.37ms
  16. Threads fairness:
  17. events (avg/stddev): 10000.0000/0.00
  18. 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



测试例子:

  1. [op@sAno1y sysbench]$ sysbench --test=mutex --mutex-num=8192 --number-locks=102400 run
  2. sysbench 0.5: multi-threaded system evaluation benchmark
  3. Running the test with following options:
  4. Number of threads: 1
  5. Random number generator seed is 0 and will be ignored
  6. Threads started!
  7. General statistics:
  8. total time: 0.0049s
  9. total number of events: 1
  10. total time taken by event execution: 0.0048s
  11. response time:
  12. min: 4.79ms
  13. avg: 4.79ms
  14. max: 4.79ms
  15. approx. 95 percentile: 4.79ms
  16. Threads fairness:
  17. events (avg/stddev): 1.0000/0.00
  18. execution time (avg/stddev): 0.0048/0.00


七. oltp test
指定--test=oltp即可。

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为单表创建数据的数量

  1. 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为测试的时长(秒)

  1. 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打开则表示随机写数:

  1. 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 \
  2. --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)




测试结果 明:
  1. No DB drivers specified, using mysql
  2. Running the test with following options:
  3. Number of threads: 1
  4. Random number generator seed is 0 and will be ignored
  5. Doing OLTP test.
  6. Running mixed OLTP test
  7. Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
  8. Using "BEGIN" for starting transactions
  9. Using auto_inc on the id column
  10. Maximum number of requests for OLTP test is limited to 10000
  11. Using 1 test tables
  12. Threads started!
  13. Done.
  14. OLTP test statistics:
  15. queries performed:
  16. read: 140000 -- 读总数
  17. write: 50000 -- 写总数
  18. other: 20000 -- 其他操作总数(除了dml之外的操作)
  19. total: 210000 -- 全部总数
  20. transactions: 10000 (229.62 per sec.) -- 总事务数
  21. deadlocks: 0 (0.00 per sec.) -- 死锁数
  22. read/write requests: 190000 (4362.73 per sec.) -- 读写总数
  23. other operations: 20000 (459.23 per sec.) -- 其他操作总数
  24. General statistics:
  25. total time: 43.5507s -- 总耗时
  26. total number of events: 10000 -- 总共发生的事务数
  27. total time taken by event execution: 43.4491 -- 所有事务耗时相加(不考虑并行因素)
  28. response time:
  29. min: 3.75ms -- 最小耗时
  30. avg: 4.34ms -- 平均耗时
  31. max: 30.58ms -- 最大耗时
  32. approx. 95 percentile: 4.44ms -- 去掉5%的最大最小值,剩余95%平均耗时
  33. Threads fairness:
  34. events (avg/stddev): 10000.0000/0.00
  35. execution time (avg/stddev): 43.4491/0.00




附录: (通用选项)
  1. Usage:
  2. sysbench [general-options]... --test= [test-options]... command
  3. General options:
  4. --num-threads=N number of threads to use [1]
  5. --max-requests=N limit for total number of requests [10000]
  6. --max-time=N limit for total execution time in seconds [0]
  7. --forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off]
  8. --thread-stack-size=SIZE size of stack per thread [64K]
  9. --tx-rate=N target transaction rate (tps) [0]
  10. --report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]
  11. --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. []
  12. --test=STRING test to run
  13. --debug=[on|off] print more debugging info [off]
  14. --validate=[on|off] perform validation checks where possible [off]
  15. --help=[on|off] print help and exit
  16. --version=[on|off] print version and exit [off]
  17. --rand-init=[on|off] initialize random number generator [off]
  18. --rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]
  19. --rand-spec-iter=N number of iterations used for numbers generation [12]
  20. --rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1]
  21. --rand-spec-res=N percentage of 'special' values to use (for special distribution) [75]
  22. --rand-seed=N seed for random number generator, ignored when 0 [0]
  23. --rand-pareto-h=N parameter h for pareto distibution [0.2]
  24. Log options:
  25. --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]
  26. --percentile=N percentile rank of query response times to count [95]
  27. Compiled-in tests:
  28. fileio - File I/O test
  29. cpu - CPU performance test
  30. memory - Memory functions speed test
  31. threads - Threads subsystem performance test
  32. mutex - Mutex performance test
  33. Commands: prepare run cleanup help version
  34. See 'sysbench --test= help' for a list of options for each test.


作者公众号(持续更新)


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29773961/viewspace-1849676/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29773961/viewspace-1849676/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值