libin123 发表于 2013-1-30 01:28:31

性能测试工具sysbench简介

sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。数据库目前支持MySQL/Oracle/PostgreSQL。本文只是简单演示一下几种测试的用法,后续准备利用sysbench来对MySQL进行一系列的测试。具体的一些参数设置,需要根据不同的测试要求来进行调整。
下载
http://sourceforge.net/projects/sysbench/

编译安装
默认支持MySQL,如果需要测试Oracle/PostgreSQL,则在configure时需要加上–with-oracle或者–with-pgsql参数
./configure --prefix=/u01/sysbench \--with-mysql-includes=/opt/mysql/include/mysql \--with-mysql-libs=/opt/mysql/lib/mysqlmake && make install参数
NinGoo:/u01/sysbench/bin>$sysbenchMissing required command argument.Usage:sysbench ... --test= ... commandGeneral options:--num-threads=N            number of threads to use --max-requests=N         limit for total number of requests --max-time=N               limit for total execution time in seconds --forced-shutdown=STRING   amount of time to wait after --max-time before forcing shutdown --thread-stack-size=SIZE   size of stack per thread --init-rng=      initialize random number generator --test=STRING            test to run--debug=         print more debugging info --validate=      perform validation checks where possible --help=            print help and exit--version=         print version and exitCompiled-in tests:fileio - File I/O testcpu - CPU performance testmemory - Memory functions speed testthreads - Threads subsystem performance testmutex - Mutex performance testoltp - OLTP testCommands: prepare run cleanup help versionSee 'sysbench --test= help' for a list of options for each test. 
CPU测试
sysbench采用寻找最大素数的方式来测试CPU的性能
NinGoo:/u01/sysbench/bin>$sysbench --test=cpu --cpu-max-prime=2000 runsysbench 0.4.12:multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 1Doing CPU performance benchmarkThreads started!Done.Maximum prime number checked in CPU test: 2000Test execution summary:    total time:                        2.3996s    total number of events:            10000    total time taken by event execution: 2.3917    per-request statistics:         min:                                  0.23ms         avg:                                  0.24ms         max:                                 27.44ms         approx.95 percentile:               0.24msThreads fairness:    events (avg/stddev):         10000.0000/0.00    execution time (avg/stddev):   2.3917/0.00线程测试
NinGoo:/u01/sysbench/bin>$sysbench --test=threads --num-threads=64 --thread-yields=100 \--thread-locks=2 runsysbench 0.4.12:multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 64Doing thread subsystem performance testThread yields per test: 100 Locks used: 2Threads started!Done.Test execution summary:    total time:                        4.3925s    total number of events:            10000    total time taken by event execution: 280.4418    per-request statistics:         min:                                  0.04ms         avg:                                 28.04ms         max:                                 72.81ms         approx.95 percentile:            52.29msThreads fairness:    events (avg/stddev):         156.2500/1.43    execution time (avg/stddev):   4.3819/0.01
文件IO性能测试
首先生成需要的测试文件,文件总大小300M,16个并发线程,随机读写模式。执行完后会在当前目录下生成一堆小文件。
NinGoo:/u01/sysbench/bin>$sysbench --test=fileio --num-threads=16\--file-total-size=300M --file-test-mode=rndrw preparesysbench 0.4.12:multi-threaded system evaluation benchmark128 files, 2400Kb each, 300Mb totalCreating files for the test...执行测试
NinGoo:/u01/sysbench/bin>$sysbench --test=fileio --num-threads=16\--file-total-size=300M --file-test-mode=rndrw runsysbench 0.4.12:multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 16Extra file open flags: 0128 files, 2.3438Mb each300Mb total file sizeBlock size 16KbNumber of random requests for random IO: 10000Read/Write ratio for combined random IO test: 1.50Periodic FSYNC enabled, calling fsync() each 100 requests.Calling fsync() at the end of test, Enabled.Using synchronous I/O modeDoing random r/w testThreads started!Done.Operations performed:5996 Read, 4004 Write, 12800 Other = 22800 TotalRead 93.688MbWritten 62.562MbTotal transferred 156.25Mb(26.713Mb/sec) 1709.66 Requests/sec executedTest execution summary:    total time:                        5.8491s    total number of events:            10000    total time taken by event execution: 12.5045    per-request statistics:         min:                                  0.01ms         avg:                                  1.25ms         max:                              373.28ms         approx.95 percentile:               0.03msThreads fairness:    events (avg/stddev):         625.0000/109.60    execution time (avg/stddev):   0.7815/0.29清理现场
NinGoo:/u01/sysbench/bin>$sysbench --test=fileio --num-threads=16\--file-total-size=300M --file-test-mode=rndrw cleanupsysbench 0.4.12:multi-threaded system evaluation benchmarkRemoving test files...Mutex测试
NinGoo:/u01/sysbench/bin>$sysbench --test=mutex --num-threads=16 \--mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 runsysbench 0.4.12:multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 16Doing mutex performance testThreads started!Done.Test execution summary:    total time:                        1.1561s    total number of events:            16    total time taken by event execution: 18.3831    per-request statistics:         min:                               1084.60ms         avg:                               1148.94ms         max:                               1153.52ms         approx.95 percentile:         10000000.00msThreads fairness:    events (avg/stddev):         1.0000/0.00    execution time (avg/stddev):   1.1489/0.02内存测试
NinGoo:/u01/sysbench/bin>$sysbench --test=memory --num-threads=16 \--memory-block-size=8192 --memory-total-size=1G runsysbench 0.4.12:multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 16Doing memory operations speed testMemory block size: 8KMemory transfer size: 1024MMemory operations type: writeMemory scope type: globalThreads started!WARNING: Operation time (0.000000) is less than minimal counted value, counting as 1.000000WARNING: Percentile statistics will be inaccurateDone.Operations performed: 131072 (114162.68 ops/sec)1024.00 MB transferred (891.90 MB/sec)Test execution summary:    total time:                        1.1481s    total number of events:            131072    total time taken by event execution: 16.0448    per-request statistics:         min:                                  0.00ms         avg:                                  0.12ms         max:                                  3.60ms         approx.95 percentile:               0.01msThreads fairness:    events (avg/stddev):         8192.0000/192.89    execution time (avg/stddev):   1.0028/0.00MySQL数据库测试
首先需要创建默认的sbtest数据库,或者使用–mysql-db指定一个已经存在的数据库
生成测试数据,引擎为myisam,表大小为1000000条记录
NinGoo:/u01/sysbench/bin>$sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 \--mysql-user=root --mysql-socket=/opt/mysql/run/mysql.sock preparesysbench 0.4.12:multi-threaded system evaluation benchmarkNo DB drivers specified, using mysqlCreating table 'sbtest'...Creating 1000000 records in table 'sbtest'...root@sbtest 11:42:18>desc sbtest.sbtest;+-------+------------------+------+-----+---------+----------------+| Field | Type             | Null | Key | Default | Extra          |+-------+------------------+------+-----+---------+----------------+| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment || k   | int(10) unsigned | NO   | MUL | 0       |                || c   | char(120)      | NO   |   |         |                || pad   | char(60)         | NO   |   |         |                |+-------+------------------+------+-----+---------+----------------+执行测试
NinGoo:/u01/sysbench/bin>$sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 \--mysql-user=root --mysql-socket=/opt/mysql/run/mysql.sock runsysbench 0.4.12:multi-threaded system evaluation benchmarkNo DB drivers specified, using mysqlRunning the test with following options:Number of threads: 1Doing OLTP test.Running mixed OLTP testUsing Special distribution (12 iterations,1 pct of values are returned in 75 pct cases)Using "LOCK TABLES WRITE" for starting transactionsUsing auto_inc on the id columnMaximum number of requests for OLTP test is limited to 10000Threads started!Done.OLTP test statistics:    queries performed:      read:                            140000      write:                           50000      other:                           20000      total:                           210000    transactions:                        10000(336.64 per sec.)    deadlocks:                           0      (0.00 per sec.)    read/write requests:               190000 (6396.11 per sec.)    other operations:                  20000(673.27 per sec.)Test execution summary:    total time:                        29.7056s    total number of events:            10000    total time taken by event execution: 29.6301    per-request statistics:         min:                                  2.27ms         avg:                                  2.96ms         max:                                 43.88ms         approx.95 percentile:               3.36msThreads fairness:    events (avg/stddev):         10000.0000/0.00    execution time (avg/stddev):   29.6301/0.00清理现场
NinGoo:/u01/sysbench/bin>$sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 \--mysql-user=root --mysql-socket=/opt/mysql/run/mysql.sock cleanupsysbench 0.4.12:multi-threaded system evaluation benchmarkNo DB drivers specified, using mysqlDropping table 'sbtest'...Done.
页: [1]
查看完整版本: 性能测试工具sysbench简介