您的位置:首页 > 其它

性能测试工具--SysBench

2013-11-29 11:52 417 查看
sysbench (System performance benchmark)

是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。



它主要包括以下几种方式的测试:

1. cpu 中央处理器

2. threads POSIX线程性能

3. mutex 互斥

4. memory 内存分配及传输速度

5. fileio 文件IO性能

6. oltp 数据库性能(OLTP基准测试)

目前sysbench主要支持 MySQL,pgsql,oracle 这3种数据库。



安装

http://sourceforge.net/ 查找sysbench
下载最新源码包。

CentOS release 5.4 (Final) 下 sysbench-0.4.8.tar.gz和 sysbench-0.4.10.tar.gz测试安装成功

编译安装

默认支持MySQL,如果需要测试Oracle/PostgreSQL,则在configure时需要加上--with-oracle或者--with-pgsql参数

./configure --prefix=/usr/local/sysbench --with-mysql-includes=/usr/local/mysql/include/mysql/ --with-mysql-libs=/usr/local/mysql/lib/mysql/



make && make install
说明:

--with-mysql-includes指定函数库位置

--with-mysql-libs指定头文件位置





公共选项


NinGoo:/u01/sysbench/bin>$sysbench

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 [32K]

--init-rng=[on|off] initialize random number generator [off]

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

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

oltp - OLTP test

Commands: prepare run cleanup help version

See 'sysbench --test= help' for a list of options for each test
CPU测试

sysbench采用寻找最大素数的方式来测试CPU的性能,测试例子:

sysbench --test=cpu --cpu-max-prime=20000 run



线程测试

线程测试私有选项:

threads options:

--thread-yields=N number of yields to do per request [1000]

--thread-locks=N number of locks per thread [8]

测试例子:sysbench --num-threads=64 --test=threads --thread-yields=100 --thread-locks=2 run

互斥测试

互斥测试私有选项:

--mutex-num=N total size of mutex array [4096]

--mutex-locks=N number of mutex locks to do per thread [50000]

--mutex-loops=N number of empty loops to do inside mutex lock [10000]

测试例子:sysbench --test=mutex run



内存测试

内存测试私有选项:

--memory-block-size=SIZE size of memory block for test [1K]

--memory-total-size=SIZE total size of data to transfer [100G]

--memory-scope=STRING memory access scope {global,local} [global]

--memory-hugetlb=[on|off] allocate memory from HugeTLB pool [off]

--memory-oper=STRING type of memory operations {read, write, none} [write]

--memory-access-mode=STRING memory access mode {seq,rnd} [seq]

测试例子:sysbench --test=memory --num-threads=16 --memory-block-size=8192 --memory-total-size=8G run





文件IO性能测试

文件IO测试私有选项:

fileio options:

--file-num=N number of files to create [128]

--file-block-size=N block size to use in all IO operations [16384]

--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,fastmmap,slowmmap} [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]

--file-fsync-all=[on|off] do fsync() after each write operation [off]

--file-fsync-end=[on|off] do fsync() at the end of test [on]

--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]

--file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]

--file-rw-ratio=N reads/writes ratio for combined test [1.5]

I/O操作的支持:

seqwr 顺序写

seqrewr 连续改写

seqrd 连续读

rndrd 随机读取

rndwr 随机写

rndrw 结合随机读/写

测试例子:

Usage example:

sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw prepare

说明:起草文件总大小为3G 16个并发线程 随机读写模式,会在当前目录下生成一堆小文件。

sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw run

说明:执行测试。

sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw cleanup

清理测试产生的所有东西。



MySQL测试:

查看数据库测试私有选项,每种数据库都不不一样,查看具体选项:

sysbench --test=oltp help

使用方法基本与IO测试相同,官方测试范例:

1 、准备数据

sysbench --debug=off --test=oltp --mysql-host=192.168.1.126 --mysql-user=root --mysql-password='password' --oltp-table-size=1000000 --mysql-db=sbtest --oltp-table-name=sbtest --num-threads=20 --max-requests=10000 --oltp-auto-inc=off --mysql-engine-trx=yes prepare

2、测试

sysbench --debug=off --test=oltp --mysql-host=192.168.1.126 --mysql-user=root --mysql-password='password' --oltp-table-size=1000000 --mysql-db=sbtest --oltp-table-name=sbtest --num-threads=20 --max-requests=10000 --oltp-auto-inc=off --mysql-engine-trx=yes run

3、删除数据

sysbench --debug=off --test=oltp --mysql-host=192.168.1.126 --mysql-user=root --mysql-password='password' --oltp-table-size=1000000 --mysql-db=sbtest --oltp-table-name=sbtest --num-threads=20 --max-requests=10000 --oltp-auto-inc=off --mysql-engine-trx=yes cleanup
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: