sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQL、Oracle和PostgreSQL。当前功能允许测试的系统参数有:

  1. file I/O performance (文件I / O性能)
  2. scheduler performance (调度性能)
  3. memory allocation and transfer speed (内存分配和传输速度)
  4. POSIX threads implementation performance POSIX线程执行绩效)
  5. database server performance (OLTP benchmark) (数据库服务器性能)

安装:
      1):Ubuntu系统可以直接apt,如:

  1. apt-get install sysbench

2):其他系统的则可以编译安装[在/home/zhoujy/目录下]:(安装前先装automake,libtool)

  1. wget http://nchc.dl.sourceforge.net/project/sysbench/sysbench/0.4.12/sysbench-0.4.12.tar.gz
  2. tar zxvf sysbench-0.4.12.tar.gz
  1. 进入解压目录,并且创建安装目录:
  2. root@m2:/home/zhoujy# cd sysbench-0.4.12/
  3. root@m2:/home/zhoujy/sysbench-0.4.12# mkdir /usr/sysbench/
  1. 准备编译
  2. root@m2:/home/zhoujy/sysbench-0.4.12# apt-get install automake
  3. root@m2:/home/zhoujy/sysbench-0.4.12#apt-get install libtool
  4. root@m2:/home/zhoujy/sysbench-0.4.12# ./autogen.sh

要是出现:perl: warning: Falling back to the standard locale ("C")。则需要设置locale:

  1. echo "export LC_ALL=C" >> /root/.bashrc
  2. source /root/.bashrc

要是没有安装开发包,即/usr/include/ 目录下面没有mysql文件夹。则需要执行安装(版本为12.04):

  1. sudo apt-get install libmysqlclient-dev
  2. sudo apt-get install libmysqld-dev
  3. sudo apt-get install libmysqld-pic

执行configure操作:

  1. ./configure --prefix=/usr/sysbench/ --with-mysql-includes=/usr/include/mysql/ --with-mysql-libs=/usr/lib/mysql/ --with-mysql
  1. 说明:
  2. --prefix=/usr/sysbench/ :指定sysbench的安装目录。
  3. --with-mysql-includes=/usr/include/mysql/ :指定安装mysql时候的includes目录。
  4. --with-mysql-libs=/usr/lib/mysql/ :指定装mysql时候的lib目录。
  5. --with-mysql sysbench默认支持mysql,如果需要测试oracle或者pgsql则需要制定–with-oracle或者–with-pgsql

在这里需要先执行:

  1. cp /usr/bin/libtool /home/zhoujy/sysbench-0.4.12/libtool

再make和make install。否者会出现 libtool 报出的 Xsysbench: command not found  错误,则表示编译文件包的libtool版本太低,需要替换。

选项说明(通用):

  1. root@db2:~# sysbench
  2. Missing required command argument.
  3. Usage: #使用方法
  4. sysbench [general-options]... --test=<test-name> [test-options]... command
  5.  
  6. General options: #通用选项
  7. --num-threads=N number of threads to use [1] #创建测试线程的数目。默认为1.
  8. --max-requests=N limit for total number of requests [10000] #请求的最大数目。默认为10000,0代表不限制。
  9. --max-time=N limit for total execution time in seconds [0] #最大执行时间,单位是s。默认是0,不限制。
  10. --forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off] #超过max-time强制中断。默认是off。
  11. --thread-stack-size=SIZE size of stack per thread [32K] #每个线程的堆栈大小。默认是32K。
  12. --init-rng=[on|off] initialize random number generator [off] #在测试开始时是否初始化随机数发生器。默认是off。
  13. --test=STRING test to run #指定测试项目名称。
  14. --debug=[on|off] print more debugging info [off] #是否显示更多的调试信息。默认是off。
  15. --validate=[on|off] perform validation checks where possible [off] #在可能情况下执行验证检查。默认是off。
  16. --help=[on|off] print help and exit #帮助信息。
  17. --version=[on|off] print version and exit #版本信息。
  18.  
  19. Compiled-in tests: #测试项目
  20. fileio - File I/O test #IO
  21. cpu - CPU performance test #CPU
  22. memory - Memory functions speed test #内存
  23. threads - Threads subsystem performance test #线程
  24. mutex - Mutex performance test #互斥性能测试
  25. oltp - OLTP test # 数据库,事务处理
  26.  
  27. Commands: prepare:测试前准备工作; run:正式测试 cleanup:测试后删掉测试数据 help version
  28.  
  29. See 'sysbench --test=<name> help' for a list of options for each test. #查看每个测试项目的更多选项列表

更多选项:
1):sysbench  --test=fileio help

  1. root@db2:~# sysbench --test=fileio help
  2. sysbench 0.4.12: multi-threaded system evaluation benchmark
  3.  
  4. fileio options:
  5. --file-num=N 创建测试文件的数量。默认是128
  6. --file-block-size=N 测试时文件块的大小。默认是16384(16K)
  7. --file-total-size=SIZE 测试文件的总大小。默认是2G
  8. --file-test-mode=STRING 文件测试模式{seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)}
  9. --file-io-mode=STRING 文件操作模式{sync(同步),async(异步),fastmmap(快速map映射),slowmmap(慢map映射)}。默认是sync
  10. --file-extra-flags=STRING 使用额外的标志来打开文件{sync,dsync,direct} 。默认为空
  11. --file-fsync-freq=N 执行fsync()的频率。(0 不使用fsync())。默认是100
  12. --file-fsync-all=[on|off] 每执行完一次写操作就执行一次fsync。默认是off
  13. --file-fsync-end=[on|off] 在测试结束时才执行fsync。默认是on
  14. --file-fsync-mode=STRING 使用哪种方法进行同步{fsync, fdatasync}。默认是fsync
  15. --file-merged-requests=N 如果可以,合并最多的IO请求数(0 表示不合并)。默认是0
  16. --file-rw-ratio=N 测试时的读写比例。默认是1.5
  1. root@db2:~# sysbench --test=fileio help
  2. sysbench 0.4.12: multi-threaded system evaluation benchmark
  3.  
  4. fileio options:
  5. --file-num=N 创建测试文件的数量。默认是128
  6. --file-block-size=N 测试时文件块的大小。默认是16384(16K)
  7. --file-total-size=SIZE 测试文件的总大小。默认是2G
  8. --file-test-mode=STRING 文件测试模式{seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)}
  9. --file-io-mode=STRING 文件操作模式{sync(同步),async(异步),fastmmap(快速map映射),slowmmap(慢map映射)}。默认是sync
  10. --file-extra-flags=STRING 使用额外的标志来打开文件{sync,dsync,direct} 。默认为空
  11. --file-fsync-freq=N 执行fsync()的频率。(0 不使用fsync())。默认是100
  12. --file-fsync-all=[on|off] 每执行完一次写操作就执行一次fsync。默认是off
  13. --file-fsync-end=[on|off] 在测试结束时才执行fsync。默认是on
  14. --file-fsync-mode=STRING 使用哪种方法进行同步{fsync, fdatasync}。默认是fsync
  15. --file-merged-requests=N 如果可以,合并最多的IO请求数(0 表示不合并)。默认是0
  16. --file-rw-ratio=N 测试时的读写比例。默认是1.5

2):sysbench  --test=cpu help

  1. --cpu-max-prime=N 最大质数发生器数量。默认是10000
  1. --cpu-max-prime=N 最大质数发生器数量。默认是10000

3):sysbench  --test=memory help

  1. root@db2:~# sysbench --test=memory help
  2. sysbench 0.4.12: multi-threaded system evaluation benchmark
  3.  
  4. memory options:
  5. --memory-block-size=SIZE 测试时内存块大小。默认是1K
  6. --memory-total-size=SIZE 传输数据的总大小。默认是100G
  7. --memory-scope=STRING 内存访问范围{global,local}。默认是global
  8. --memory-hugetlb=[on|off] HugeTLB池内存分配。默认是off
  9. --memory-oper=STRING 内存操作类型。{read, write, none} 默认是write
  10. --memory-access-mode=STRING存储器存取方式{seq,rnd} 默认是seq
  1. root@db2:~# sysbench --test=memory help
  2. sysbench 0.4.12: multi-threaded system evaluation benchmark
  3.  
  4. memory options:
  5. --memory-block-size=SIZE 测试时内存块大小。默认是1K
  6. --memory-total-size=SIZE 传输数据的总大小。默认是100G
  7. --memory-scope=STRING 内存访问范围{global,local}。默认是global
  8. --memory-hugetlb=[on|off] HugeTLB池内存分配。默认是off
  9. --memory-oper=STRING 内存操作类型。{read, write, none} 默认是write
  10. --memory-access-mode=STRING存储器存取方式{seq,rnd} 默认是seq

4):sysbench  --test=threads help

  1. sysbench 0.4.12: multi-threaded system evaluation benchmark
  2.  
  3. threads options:
  4. --thread-yields=N 每个请求产生多少个线程。默认是1000
  5. --thread-locks=N 每个线程的锁的数量。默认是8
  1. sysbench 0.4.12: multi-threaded system evaluation benchmark
  2.  
  3. threads options:
  4. --thread-yields=N 每个请求产生多少个线程。默认是1000
  5. --thread-locks=N 每个线程的锁的数量。默认是8

5):sysbench  --test=mutex help

  1. root@db2:~# sysbench --test=mutex help
  2. sysbench 0.4.12: multi-threaded system evaluation benchmark
  3.  
  4. mutex options:
  5.  
  6. --mutex-num=N 数组互斥的总大小。默认是4096
  7. --mutex-locks=N 每个线程互斥锁的数量。默认是50000
  8. --mutex-loops=N 内部互斥锁的空循环数量。默认是10000
  1. root@db2:~# sysbench --test=mutex help
  2. sysbench 0.4.12: multi-threaded system evaluation benchmark
  3.  
  4. mutex options:
  5.  
  6. --mutex-num=N 数组互斥的总大小。默认是4096
  7. --mutex-locks=N 每个线程互斥锁的数量。默认是50000
  8. --mutex-loops=N 内部互斥锁的空循环数量。默认是10000

6): sysbench --test=oltp help

  1. root@db2:~# sysbench --test=oltp help
  2. sysbench 0.4.12: multi-threaded system evaluation benchmark
  3.  
  4. oltp options:
  5. --oltp-test-mode=STRING 执行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。默认是complex
  6. --oltp-reconnect-mode=STRING 重新连接模式{session(不使用重新连接。每个线程断开只在测试结束),transaction(在每次事务结束后重新连接),query(在每个SQL语句执行完重新连接),random(对于每个事务随机选择以上重新连接模式)}。默认是session
  7. --oltp-sp-name=STRING 存储过程的名称。默认为空
  8. --oltp-read-only=[on|off] 只读模式。Updatedeleteinsert语句不可执行。默认是off
  9. --oltp-skip-trx=[on|off] 省略begin/commit语句。默认是off
  10. --oltp-range-size=N 查询范围。默认是100
  11. --oltp-point-selects=N number of point selects [10]
  12. --oltp-simple-ranges=N number of simple ranges [1]
  13. --oltp-sum-ranges=N number of sum ranges [1]
  14. --oltp-order-ranges=N number of ordered ranges [1]
  15. --oltp-distinct-ranges=N number of distinct ranges [1]
  16. --oltp-index-updates=N number of index update [1]
  17. --oltp-non-index-updates=N number of non-index updates [1]
  18. --oltp-nontrx-mode=STRING 查询类型对于非事务执行模式{select, update_key, update_nokey, insert, delete} [select]
  19. --oltp-auto-inc=[on|off] AUTO_INCREMENT是否开启。默认是on
  20. --oltp-connect-delay=N 在多少微秒后连接数据库。默认是10000
  21. --oltp-user-delay-min=N 每个请求最短等待时间。单位是ms。默认是0
  22. --oltp-user-delay-max=N 每个请求最长等待时间。单位是ms。默认是0
  23. --oltp-table-name=STRING 测试时使用到的表名。默认是sbtest
  24. --oltp-table-size=N 测试表的记录数。默认是10000
  25. --oltp-dist-type=STRING 分布的随机数{uniform(均匀分布),Gaussian(高斯分布),special(空间分布)}。默认是special
  26. --oltp-dist-iter=N 产生数的迭代次数。默认是12
  27. --oltp-dist-pct=N 值的百分比被视为'special' (for special distribution)。默认是1
  28. --oltp-dist-res=N special’的百分比值。默认是75
  29.  
  30. General database options:
  31. --db-driver=STRING 指定数据库驱动程序('help' to get list of available drivers)
  32. --db-ps-mode=STRING编制报表使用模式{auto, disable} [auto]
  33. Compiled-in database drivers:
  34. mysql - MySQL driver
  35. mysql options:
  36. --mysql-host=[LIST,...] MySQL server host [localhost]
  37. --mysql-port=N MySQL server port [3306]
  38. --mysql-socket=STRING MySQL socket
  39. --mysql-user=STRING MySQL user [sbtest]
  40. --mysql-password=STRING MySQL password []
  41. --mysql-db=STRING MySQL database name [sbtest]
  42. --mysql-table-engine=STRING storage engine to use for the test table {myisam,innodb,bdb,heap,ndbcluster,federated} [innodb]
  43. --mysql-engine-trx=STRING whether storage engine used is transactional or not {yes,no,auto} [auto]
  44. --mysql-ssl=[on|off] use SSL connections, if available in the client library [off]
  45. --myisam-max-rows=N max-rows parameter for MyISAM tables [1000000]
  46. --mysql-create-options=STRING additional options passed to CREATE TABLE []

测试: 
1)测试CPU: sysbench --test=cpu --cpu-max-prime=2000 run

  1. root@db2:~# sysbench --test=cpu --cpu-max-prime=2000 run
  2. sysbench 0.4.12: multi-threaded system evaluation benchmark
  3.  
  4. Running the test with following options:
  5. Number of threads: 1
  6.  
  7. Doing CPU performance benchmark
  8.  
  9. Threads started!
  10. Done.
  11.  
  12. Maximum prime number checked in CPU test: 2000
  13.  
  14. Test execution summary:
  15. total time: 3.7155s
  16. total number of events: 10000
  17. total time taken by event execution: 3.7041
  18. per-request statistics:
  19. min: 0.36ms
  20. avg: 0.37ms
  21. max: 2.53ms
  22. approx. 95 percentile: 0.37ms
  23.  
  24. Threads fairness:
  25. events (avg/stddev): 10000.0000/0.00
  26. execution time (avg/stddev): 3.7041/0.00

2)测试线程:sysbench  --test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run

  1. root@db2:~# sysbench --test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run
  2. sysbench 0.4.12: multi-threaded system evaluation benchmark
  3.  
  4. Running the test with following options:
  5. Number of threads: 500
  6.  
  7. Doing thread subsystem performance test
  8. Thread yields per test: 100 Locks used: 4
  9. Threads started!
  10. Done.
  11.  
  12. Test execution summary:
  13. total time: 1.0644s
  14. total number of events: 10000
  15. total time taken by event execution: 501.3952
  16. per-request statistics:
  17. min: 0.05ms
  18. avg: 50.14ms
  19. max: 587.05ms
  20. approx. 95 percentile: 190.28ms
  21.  
  22. Threads fairness:
  23. events (avg/stddev): 20.0000/4.72
  24. execution time (avg/stddev): 1.0028/0.01

3)测试IO:--num-threads 开启的线程     --file-total-size 总的文件大小
1,prepare阶段,生成需要的测试文件,完成后会在当前目录下生成很多小文件。
sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw prepare     
2,run阶段
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run
3,清理测试时生成的文件
sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup

  1. root@db2:~/io# sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw prepare
  2. sysbench 0.4.12: multi-threaded system evaluation benchmark
  3.  
  4. 128 files, 16384Kb each, 2048Mb total
  5. Creating files for the test...
  6. root@db2:~/io# sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run
  7. sysbench 0.4.12: multi-threaded system evaluation benchmark
  8.  
  9. Running the test with following options:
  10. Number of threads: 20
  11.  
  12. Extra file open flags: 0
  13. 128 files, 16Mb each
  14. 2Gb total file size
  15. Block size 16Kb
  16. Number of random requests for random IO: 10000
  17. Read/Write ratio for combined random IO test: 1.50
  18. Periodic FSYNC enabled, calling fsync() each 100 requests.
  19. Calling fsync() at the end of test, Enabled.
  20. Using synchronous I/O mode
  21. Doing random r/w test
  22. Threads started!
  23. Done.
  24.  
  25. Operations performed: 6010 Read, 3997 Write, 12803 Other = 22810 Total
  26. Read 93.906Mb Written 62.453Mb Total transferred 156.36Mb (6.6668Mb/sec)
  27. 426.68 Requests/sec executed
  28.  
  29. Test execution summary:
  30. total time: 23.4534s
  31. total number of events: 10007
  32. total time taken by event execution: 111.5569
  33. per-request statistics:
  34. min: 0.01ms
  35. avg: 11.15ms
  36. max: 496.18ms
  37. approx. 95 percentile: 53.05ms
  38.  
  39. Threads fairness:
  40. events (avg/stddev): 500.3500/37.50
  41. execution time (avg/stddev): 5.5778/0.21
  42.  
  43. root@db2:~/io# sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup
  44. sysbench 0.4.12: multi-threaded system evaluation benchmark
  45.  
  46. Removing test files...

4)测试内存:sysbench --test=memory --memory-block-size=8k --memory-total-size=1G run

  1. sysbench 0.4.12: multi-threaded system evaluation benchmark
  2. Operations performed: 1310720 (396525.32 ops/sec)
  3. 10240.00 MB transferred (3097.85 MB/sec)
  4. Test execution summary:
  5. total time: 3.3055s
  6. total number of events: 1310720
  7. total time taken by event execution: 205.0560
  8. per-request statistics:
  9. min: 0.00ms
  10. avg: 0.16ms
  11. max: 1066.04ms
  12. approx. 95 percentile: 0.02ms
  13. Threads fairness:
  14. events (avg/stddev): 13107.2000/3870.38
  15. execution time (avg/stddev): 2.0506/0.28

5)测试mutex:sysbench –test=mutex –num-threads=100 –mutex-num=1000 –mutex-locks=100000 –mutex-loops=10000 run

  1. Test execution summary:
  2. total time: 12.5606s
  3. total number of events: 100
  4. total time taken by event execution: 1164.4236
  5. per-request statistics:
  6. min: 9551.87ms
  7. avg: 11644.24ms
  8. max: 12525.32ms
  9. approx. 95 percentile: 12326.25ms
  10. Threads fairness:
  11. events (avg/stddev): 1.0000/0.00
  12. execution time (avg/stddev): 11.6442/0.59

6)测试OLTP:
1,prepare阶段,生成需要的测试表
sysbench --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.X.X --mysql-db=test --oltp-table-size=500000 --mysql-user=root --mysql-password=123456 prepare
2,run阶段
sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=test --oltp-table-size=500000 --mysql-user=root --mysql-password=123456 run
3,清理测试时生成的测试表
sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=test --oltp-table-size=500000 --mysql-user=root --mysql-password=123456 cleanup

  1. root@db2:~# sysbench --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=rep_test --oltp-table-size=1000000 --mysql-user=root --mysql-password=123456 prepare
  2. sysbench 0.4.12: multi-threaded system evaluation benchmark
  3.  
  4. No DB drivers specified, using mysql
  5. Creating table 'sbtest'...
  6. Creating 1000000 records in table 'sbtest'...
  7. root@db2:~# sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=rep_test --oltp-table-size=1000000 --mysql-user=root --mysql-password=123456 run
  8. sysbench 0.4.12: multi-threaded system evaluation benchmark
  9.  
  10. No DB drivers specified, using mysql
  11. Running the test with following options:
  12. Number of threads: 16
  13.  
  14. Doing OLTP test.
  15. Running mixed OLTP test
  16. Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
  17. Using "BEGIN" for starting transactions
  18. Using auto_inc on the id column
  19. Maximum number of requests for OLTP test is limited to 10000
  20. Threads started!
  21. Done.
  22.  
  23. OLTP test statistics:
  24. queries performed:
  25. read: 140000
  26. write: 50000
  27. other: 20000
  28. total: 210000
  1. #—-事务数总计,每秒的事务处理量
  2. transactions: 10000 (356.98 per sec.)
  3. deadlocks: 0 (0.00 per sec.)
  4. read/write requests: 190000 (6782.56 per sec.)
  5. other operations: 20000 (713.95 per sec.)
  6.  
  7. Test execution summary:
  8. total time: 28.0130s
  9. total number of events: 10000
  10. total time taken by event execution: 447.7731
  11. per-request statistics:
  12. min: 3.91ms
  13. avg: 44.78ms
  14. max: 207.61ms
  15. approx. 95 percentile: 76.48ms
  16.  
  17. Threads fairness:
  18. events (avg/stddev): 625.0000/22.96
  19. execution time (avg/stddev): 27.9858/0.01
  20.  
  21. root@db2:~# sysbench --num-threads=16 --test=oltp --mysql-table-engine=innodb --mysql-host=192.168.x.x --mysql-db=rep_test --oltp-table-size=1000000 --mysql-user=root --mysql-password=123456 cleanup
  22. sysbench 0.4.12: multi-threaded system evaluation benchmark
  23.  
  24. No DB drivers specified, using mysql
  25. Dropping table 'sbtest'...
  26. Done.

测试表信息:

  1. mysql> desc sbtest;
  2. +-------+------------------+------+-----+---------+----------------+
  3. | Field | Type | Null | Key | Default | Extra |
  4. +-------+------------------+------+-----+---------+----------------+
  5. | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
  6. | k | int(10) unsigned | NO | MUL | 0 | |
  7. | c | char(120) | NO | | | |
  8. | pad | char(60) | NO | | | |
  9. +-------+------------------+------+-----+---------+----------------+
  10. 4 rows in set (0.01 sec)
  11.  
  12. mysql> show create table sbtest\G;
  13. *************************** 1. row ***************************
  14. Table: sbtest
  15. Create Table: CREATE TABLE `sbtest` (
  16. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  17. `k` int(10) unsigned NOT NULL DEFAULT '0',
  18. `c` char(120) NOT NULL DEFAULT '',
  19. `pad` char(60) NOT NULL DEFAULT '',
  20. PRIMARY KEY (`id`),
  21. KEY `k` (`k`)
  22. ) ENGINE=InnoDB AUTO_INCREMENT=1000001 DEFAULT CHARSET=utf8
  23. 1 row in set (0.01 sec)
  24.  
  25. ERROR:
  26. No query specified
  27.  
  28. mysql> select count(*) from sbtest;
  29. +----------+
  30. | count(*) |
  31. +----------+
  32. | 1000000 |
  33. +----------+
  34. 1 row in set (0.30 sec)
  35. mysql> desc sbtest;
  36. ERROR 1146 (42S02): Table 'rep_test.sbtest' doesn't exist

可以用这个测试:

  1. sysbench --num-threads=4 --test=oltp --oltp-reconnect-mode=random --mysql-table-engine=innodb --mysql-host=192.168.200.201 --mysql-db=rep_test --ol
  2. tp-table-size=500000 --mysql-user=zjy --mysql-password=1234#
  3.  
  4. 一. 安装
    解压后:
  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. 可能需要安装一下环境:
  1. $ sudo yum -y install libtool automake
  1. 源码来安装autoconfautomake

附带这两个源码包url
http://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz
http://mirrors.kernel.org/gnu/automake/automake-1.15.tar.gz

  1. 配置环境变量:
  1. $ vi ~/.bash_profile
  1. sysbench --version 或者直接 sysbench 可以看到版本信息或者帮助信息
  1. $ source ~/.bash_profile
  2. $ sysbench --version
  3. sysbench 0.5
  1. 如果报错:
    sysbench: error while loading shared libraries: libmysqlclient_r.so.15: cannot open shared object file: No such file or directory
    则有可能是lib路径不对
  1. $ sudo vi /etc/ld.so.conf
  2. 添加 /usr/local/mysql/lib 保存退出
  3. $ sudo /sbin/ldconfig -v
  1. 二. file IO 
    指定--test=fileio即可。
  2.  
  3. 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
  4.  
  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...
  1. 三. CPU test
    指定--test=cpu即可。
  2.  
  3. cpu options:
      --cpu-max-prime=N      upper limit for primes generator [10000]        
    // 设置素数最大上限值,缺省为10000 
  4.  
  5. 测试例子:
  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
  1. 四. memory test
    指定--test=memory即可。
  2.  
  3. 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]
    // 内存访问模式,顺序或随机,默认为序列
  4.  
  5. 测试例子:
  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
  1. 五. threads test
    指定--test=threads即可。
  2.  
  3. threads options:
      --thread-yields=N      number of yields to do per request [1000]
      --thread-locks=N       number of locks per thread [8]
    // 每个线程锁的数目
 
  1. 测试例子:
  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
  1. 六. mutex test
    指定--test=mutex即可。
  2.  
  3. 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

  1. 指定--test=oltp即可。
  2.  
  3. oltp options
    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]
  4.  
  5. Compiled-in database drivers:
      mysql - MySQL driver
  6.  
  7. 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 []
  8.  
  9. 创建测试数据:
    --oltp-table-size为单表创建数据的数量
  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
  1. 开始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
  1. 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. 生成的测试表的数据样例:
    *************************** 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: 09512147864-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.  
  2. 测试结果说明:
  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.  
  2. 附录: (通用选项)
    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.

MySQL性能测试工具sysbench的安装和使用的更多相关文章

  1. Linux 性能测试工具 sysbench 的安装与简单使用

    文章目录 Linux 性能测试工具 sysbench 的安装与简单使用        一 背景        二 实验环境            2.1 操作系统            2.2 其他配 ...

  2. MYSQL性能测试工具SYSBENCH

    [root@localhost ~]$ wget https://github.com/akopytov/sysbench/archive/1.0.zip -O "sysbench-1.0. ...

  3. MySQL性能测试工具之mysqlslap

    MySQL性能测试工具之mysqlslap [日期:2014-10-05] 来源:Linux社区  作者:tongcheng [字体:大 中 小]   --转自Linux社区:http://www.l ...

  4. Mysql多线程性能测试工具sysbench 安装、使用和测试

    From:http://www.cnblogs.com/zhoujinyi/archive/2013/04/19/3029134.html 摘要:      sysbench是一个开源的.模块化的.跨 ...

  5. 安装性能测试工具:sysbench和使用apache的ab

    一.软件的用途,它主要包括以下几种方式的测试:1.cpu性能2.磁盘io性能3.调度程序性能4.内存分配及传输速度5.POSIX线程性能6.数据库性能(OLTP基准测试) 这个软件为什么找不到官网呢? ...

  6. 开源多线程性能测试工具-sysbench

    导读 sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试.数据库目前支持MySQL/Oracle/PostgreSQL.本文主要演示Mysql测试 ...

  7. MySQL 常用工具sysbench/fio/tpcc等测试

    为什么要压力测试采购新设备,评估新设备性能开发新项目,评估数据库容量新系统上线前,预估/模拟数据库负载更换数据库版本,评估性能变化 关注指标  CPU %wait,%user,%sys 内存 只内存读 ...

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

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

  9. Web性能测试工具:http_load安装&使用简介

    除了siege,在Web性能测试工具中,http_load也是比较热门和常见的一款,有时因为种种原因,只能使用现成的工具,所以多了解和掌握一种Web性能测试工具是很有必要的. 1.下载安装包 略过 2 ...

随机推荐

  1. 遮罩层出现后不能滚动 添加事件@touchmove.prevent

    <div class="maskshow" @click="hidden_video" @touchmove.prevent></div> ...

  2. hash值重写,就是以自己定义的规则来显示hash值

    未重写hashCode值 重写hashCode后的值  

  3. 96A

    #include <iostream> #include <string> #include <cctype> using namespace std; int m ...

  4. Entity Framework(Fluent API)

    一.概述 Fluent API 可以理解为一种从POCO到数据库的映射约定,包括字段长度,类型,主外键等等,在EF Code First进行开发时候经常用到. 1.主键 modelBuilder.En ...

  5. Unittest + python

    Unittest简单应用 #_*_coding:utf8_*_ import unittest from selenium import webdriver import time class Tes ...

  6. ASP.Net Core 2.2 MVC入门到基本使用系列 (二)(转)

    本教程会对基本的.Net Core 进行一个大概的且不会太深入的讲解, 在您看完本系列之后, 能基本甚至熟练的使用.Net Core进行Web开发, 感受到.Net Core的魅力. 本教程知识点大体 ...

  7. shell基础:多命令顺序执行与管道符

    有些命令的前后关系正是需要这样的关系来实现. 如在软件包的安装中: 第三个是个简单的判断:

  8. 那种多空计算方法更正确呢?——从此图看应该是TEST005

    那种方法计算多空逆转更正确呢?——从此图1看应该是TEST005,但是实际上是ZCL_多空! TEST005具有滞后性!也就是说跌了一些在报警,可能已经跌了10%(如图2) ZCL_多空:当计算结果和 ...

  9. react-redux 使用后台数据初始化(渲染)界面

    注:首先在redux中改变state只能通过action操作,reducers改变state 在组件中 store.js import { createStore } from "redux ...

  10. top结果解释

    top结果解释 top命令功能类似Windows的任务管理器,但不如任务管理器的直观明了,下面对各项内容进行简单介绍. 信息行 top--命令/up-更新时间/users-用户数/load avera ...