sysbench是一个多线程性能测试工具,可以进行CPU、MEM、IO数据库等性能测试。
1,下载rpm包
http://www.lefred.be/?q=node/154
安装sysbench需要的mysql 相关包(因为这里我使用的是Percona 5.6.15版本的server)
rpm -ivh Percona-Server-client-56-5.6.15-rel63.0.519.rhel6.x86_64.rpm
rmp -ivh Percona-Server-shared-56-5.6.15-rel63.0.519.rhel6.x86_64.rpm
否则你会遇到Requires: libmysqlclient.so.18()(64bit) 这样的错误
,2,安装sysbenc包
sysbench-0.5-3.el6_.x86_64.rpm
注意输入sysbench命令后:
[root@VM-MYSQL-TEST-LiDan ~]# sysbench
Missing required command argument.
Usage:
sysbench [general-options]... --test=<test-name> [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} [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=<name> help' for a list of options for each test.
[root@VM-MYSQL-TEST-LiDan ~]# sysbench --test=oltp help
sysbench 0.5: multi-threaded system evaluation benchmark
PANIC: unprotected error in call to Lua API (cannot open oltp: No such file or directory)
这里和0.4版本不同,这里--test不再有
oltp - OLTP test这个项目,而是换成了对应的lua脚本路径(0.5版本rpm包安装的情况下,默认lua脚本放在/usr/share/doc/sysbench/tests/db下)
可以查看:
[root@VM-MYSQL-TEST-LiDan db]# ll /usr/share/doc/sysbench/tests/db
total 44
-rw-r--r-- 1 root root 3585 Sep 7 2012 common.lua
-rw-r--r-- 1 root root 340 Sep 7 2012 delete.lua
-rw-r--r-- 1 root root 830 Sep 7 2012 insert.lua
-rw-r--r-- 1 root root 2925 Sep 7 2012 oltp.lua
-rw-r--r-- 1 root root 342 Sep 7 2012 oltp_simple.lua
-rw-r--r-- 1 root root 425 Sep 7 2012 parallel_prepare.lua
-rw-r--r-- 1 root root 343 Sep 7 2012 select.lua
-rw-r--r-- 1 root root 3964 Sep 7 2012 select_random_points.lua
-rw-r--r-- 1 root root 4066 Sep 7 2012 select_random_ranges.lua
-rw-r--r-- 1 root root 343 Sep 7 2012 update_index.lua
-rw-r--r-- 1 root root 552 Sep 7 2012 update_non_index.lua
如果对lua熟悉也可以自行修改lua脚本来满足自己的测试需求。
4,参考测试脚本:
TABLE_SIZE=25000000
HOST="10.10.1.111"
USER_NAME="xxx"
PASS_WORD="xxx"
PORT=3306
TEST_ENGINE="INNODB"
OLTP_TABLES=4 #### the number of tables for testing
MAX_TIME=1200 #### seconds #####
MIN_THREAD=16 ### concurrent threads for testing
MAX_THREAD=64
TEST_GROUP=3
DELAY_TIME=10000 ####ms#####
TEST_DB="test"
SLEEP_TIME=120 ###SECONDS###
REPORT_INTERVAL=10 ###the time interval that print info every time
MIN_ENGINE_THREADS=64
MAX_ENGINE_THREADS=64,
TEST_MODE="/usr/share/doc/sysbench/tests/db/oltp.lua"
#初始化脚本
sysbench --test=${TEST_MODE} --oltp_tables_count=${OLTP_TABLES} --report-interval=${REPORT_INTERVAL}
--oltp-table-size=${TABLE_SIZE} --num-threads=${${OLTP_TABLES}} --mysql-user=${USER_NAME}
--mysql-password=${PASS_WORD} --mysql-table-engine=${TEST_ENGINE} --rand-init=on --mysql-host=${HOST}
--mysql-port=${PORT} --mysql-db=${TEST_DB} prepare
#压测脚本:
sysbench --test=${TEST_MODE} --oltp_tables_count=${OLTP_TABLES} --report-interval=${REPORT_INTERVAL}
--oltp-table-size=${TABLE_SIZE} --mysql-user=${USER_NAME} --mysql-password=${PASS_WORD} --oltp-connect-delay=${DELAY_TIME}
--oltp-dist-type=uniform --rand-init=on --mysql-table-engine=${TEST_ENGINE} --mysql-host=${HOST} --mysql-port=${PORT}
--mysql-db=${TEST_DB} --max-time=${MAX_TIME} --max-requests=0 --num-threads=${num} --thread-stack-size=256 run
#清理脚本:
sysbench --test=${TEST_MODE} --oltp_tables_count=${OLTP_TABLES} --report-interval=${REPORT_INTERVAL} --oltp-table-size=${TABLE_SIZE} --mysql-user=${USER_NAME} --mysql-password=${PASS_WORD} --mysql-table-engine=${TEST_ENGINE} --mysql-host=${HOST} --mysql-port=${PORT} --mysql-db=${TEST_DB} cleanup
5,常用参数简单说明:
--report-interval=10:每隔多久打印一次统计信息,单位秒,0.5版本新增
--rand-init=on:是否随机初始化数据,如果不随机化那么初始好的数据每行内容除了主键不同外其他完全相同。
--rand-type=special:数据分布模式,special表示存在热点数据,uniform表示非热点数据模式
sysbench 0.5: multi-threaded system evaluation benchmark
No help available for test '/usr/share/doc/sysbench/tests/db/oltp.lua'.
无法使用帮助信息来查看oltp下的参数,只有使用0.4版本才能查,不过还好都兼容
注意:
1,oltp的应用存在热点数据,所以除非测试特殊性否则尽量不用uniform这种非热点数据模式。
2,初始化数据方式最好随机--rand-init=on表的数量这个参数最好设置2以上但也不要太多,因为表的结构都一样。
参考:
https://code.launchpad.net/sysbench
http://www.linuxidc.com/Linux/2012-11/75054p2.htm
作为dba我们使用最多的还是做mysql的基准测试,以前使用sysbench都是0.4版本的。
据说0.5做了一些调整这里简单的试用一下并顺便做点记录。
1,下载rpm包
http://www.lefred.be/?q=node/154
安装sysbench需要的mysql 相关包(因为这里我使用的是Percona 5.6.15版本的server)
rpm -ivh Percona-Server-client-56-5.6.15-rel63.0.519.rhel6.x86_64.rpm
rmp -ivh Percona-Server-shared-56-5.6.15-rel63.0.519.rhel6.x86_64.rpm
否则你会遇到Requires: libmysqlclient.so.18()(64bit) 这样的错误
,2,安装sysbenc包
sysbench-0.5-3.el6_.x86_64.rpm
注意输入sysbench命令后:
[root@VM-MYSQL-TEST-LiDan ~]# sysbench
Missing required command argument.
Usage:
sysbench [general-options]... --test=<test-name> [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} [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=<name> help' for a list of options for each test.
[root@VM-MYSQL-TEST-LiDan ~]# sysbench --test=oltp help
sysbench 0.5: multi-threaded system evaluation benchmark
PANIC: unprotected error in call to Lua API (cannot open oltp: No such file or directory)
这里和0.4版本不同,这里--test不再有
oltp - OLTP test这个项目,而是换成了对应的lua脚本路径(0.5版本rpm包安装的情况下,默认lua脚本放在/usr/share/doc/sysbench/tests/db下)
可以查看:
[root@VM-MYSQL-TEST-LiDan db]# ll /usr/share/doc/sysbench/tests/db
total 44
-rw-r--r-- 1 root root 3585 Sep 7 2012 common.lua
-rw-r--r-- 1 root root 340 Sep 7 2012 delete.lua
-rw-r--r-- 1 root root 830 Sep 7 2012 insert.lua
-rw-r--r-- 1 root root 2925 Sep 7 2012 oltp.lua
-rw-r--r-- 1 root root 342 Sep 7 2012 oltp_simple.lua
-rw-r--r-- 1 root root 425 Sep 7 2012 parallel_prepare.lua
-rw-r--r-- 1 root root 343 Sep 7 2012 select.lua
-rw-r--r-- 1 root root 3964 Sep 7 2012 select_random_points.lua
-rw-r--r-- 1 root root 4066 Sep 7 2012 select_random_ranges.lua
-rw-r--r-- 1 root root 343 Sep 7 2012 update_index.lua
-rw-r--r-- 1 root root 552 Sep 7 2012 update_non_index.lua
如果对lua熟悉也可以自行修改lua脚本来满足自己的测试需求。
4,参考测试脚本:
TABLE_SIZE=25000000
HOST="10.10.1.111"
USER_NAME="xxx"
PASS_WORD="xxx"
PORT=3306
TEST_ENGINE="INNODB"
OLTP_TABLES=4 #### the number of tables for testing
MAX_TIME=1200 #### seconds #####
MIN_THREAD=16 ### concurrent threads for testing
MAX_THREAD=64
TEST_GROUP=3
DELAY_TIME=10000 ####ms#####
TEST_DB="test"
SLEEP_TIME=120 ###SECONDS###
REPORT_INTERVAL=10 ###the time interval that print info every time
MIN_ENGINE_THREADS=64
MAX_ENGINE_THREADS=64,
TEST_MODE="/usr/share/doc/sysbench/tests/db/oltp.lua"
#初始化脚本
sysbench --test=${TEST_MODE} --oltp_tables_count=${OLTP_TABLES} --report-interval=${REPORT_INTERVAL}
--oltp-table-size=${TABLE_SIZE} --num-threads=${${OLTP_TABLES}} --mysql-user=${USER_NAME}
--mysql-password=${PASS_WORD} --mysql-table-engine=${TEST_ENGINE} --rand-init=on --mysql-host=${HOST}
--mysql-port=${PORT} --mysql-db=${TEST_DB} prepare
#压测脚本:
sysbench --test=${TEST_MODE} --oltp_tables_count=${OLTP_TABLES} --report-interval=${REPORT_INTERVAL}
--oltp-table-size=${TABLE_SIZE} --mysql-user=${USER_NAME} --mysql-password=${PASS_WORD} --oltp-connect-delay=${DELAY_TIME}
--oltp-dist-type=uniform --rand-init=on --mysql-table-engine=${TEST_ENGINE} --mysql-host=${HOST} --mysql-port=${PORT}
--mysql-db=${TEST_DB} --max-time=${MAX_TIME} --max-requests=0 --num-threads=${num} --thread-stack-size=256 run
#清理脚本:
sysbench --test=${TEST_MODE} --oltp_tables_count=${OLTP_TABLES} --report-interval=${REPORT_INTERVAL} --oltp-table-size=${TABLE_SIZE} --mysql-user=${USER_NAME} --mysql-password=${PASS_WORD} --mysql-table-engine=${TEST_ENGINE} --mysql-host=${HOST} --mysql-port=${PORT} --mysql-db=${TEST_DB} cleanup
5,常用参数简单说明:
--report-interval=10:每隔多久打印一次统计信息,单位秒,0.5版本新增
--rand-init=on:是否随机初始化数据,如果不随机化那么初始好的数据每行内容除了主键不同外其他完全相同。
--rand-type=special:数据分布模式,special表示存在热点数据,uniform表示非热点数据模式
--mysql-table-engine=xxx:表的存储引擎类型,innodb、myisam、tokudb这些都可以
6,比较蛋疼的问题:
sysbench --test='/usr/share/doc/sysbench/tests/db/oltp.lua' helpsysbench 0.5: multi-threaded system evaluation benchmark
No help available for test '/usr/share/doc/sysbench/tests/db/oltp.lua'.
无法使用帮助信息来查看oltp下的参数,只有使用0.4版本才能查,不过还好都兼容
注意:
1,oltp的应用存在热点数据,所以除非测试特殊性否则尽量不用uniform这种非热点数据模式。
2,初始化数据方式最好随机--rand-init=on表的数量这个参数最好设置2以上但也不要太多,因为表的结构都一样。
参考:
https://code.launchpad.net/sysbench
http://www.linuxidc.com/Linux/2012-11/75054p2.htm