sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。数据库目前支持MySQL/Oracle/PostgreSQL。本文只是简单演示一下几种测试的用法,后续准备利用sysbench来对MySQL进行一系列的测试。具体的一些参数设置,需要根据不同的测试要求来进行调整. 编译安装# wget -c http://sourceforge.net/projects/sysbench/files/sysbench/0.4.12/sysbench-0.4.12.tar.gz/download #tar zxvf sysbench-0.4.12.tar.gz #cd sysbench-0.4.12 #./configure && make && make install 如果需要测试Oracle/PostgreSQL,则在configure时需要加上–with-oracle或者–with-pgsql参数 参数[root@localhost sysbench]# ./sysbench
测试用例:
通用选项:
测试项目: 指令: prepare(测试前准备工作) run(正式测试) cleanup(测试后删掉测试数据) help version See ‘sysbench –test=<name> help’ for a list of options for each test. 查看每个测试项目的更多选项列表。
[root@localhost bin]# ./sysbench –test=fileio help
[root@localhost bin]# ./sysbench –test=cpu help
[root@localhost bin]# ./sysbench –test=memory help
[root@localhost bin]# ./sysbench –test=threads help
[root@localhost bin]# ./sysbench –test=mutex help
[root@localhost bin]# ./sysbench –test=oltp help
General database options:
Compiled-in database drivers:
mysql options: 测试1、CPU测试 [root@localhost bin]# ./sysbench –test=cpu –cpu-max-prime=20000 run sysbench 0.4.12: multi-threaded system evaluation benchmark Number of threads: 1 Doing CPU performance benchmark
Threads started!
Maximum prime number checked in CPU test: 20000
Threads fairness: 2、线程数测试 thread-locks小于线程数除以2,lock越少,处理时间越长。 # ./sysbench –test=threads –num-threads=512 –thread-yields=100 –thread-locks=2 run
sysbench 0.4.12: multi-threaded system evaluation benchmark Thread yields per test: 100 Locks used: 2 Threads started! WARNING: Operation time (0.000000) is less than minimal counted value, counting as 1.000000 WARNING: Percentile statistics will be inaccurateDone. Test execution summary: total time: 4.1759s total number of events: 10000 total time taken by event execution: 2038.5959 per-request statistics: min: 0.00ms avg: 203.86ms max: 2735.47ms
approx. 95 percentile: 829.60ms events (avg/stddev): 19.5312/8.26 execution time (avg/stddev): 3.9816/0.04 3、磁盘IO性能测试 首先生成需要的测试文件,文件总大小3G,16个并发线程,随机读写模式。执行完后会在当前目录下生成一堆小文件。 # ./sysbench –test=fileio –num-threads=16 –file-total-size=3G –file-test-mode=rndrw prepare sysbench 0.4.12: multi-threaded system evaluation benchmark 128 files, 24576Kb each, 3072Mb total Creating files for the test… 开始测试: # ./sysbench –test=fileio –num-threads=16 –file-total-size=3G –file-test-mode=rndrw run sysbench 0.4.12: multi-threaded system evaluation benchmark Running the test with following options:Number of threads: 16 Extra file open flags: 0 128 files, 24Mb each 3Gb total file size Block size 16Kb Number of random requests for random IO: 10000 Read/Write ratio for combined random IO test: 1.50 Periodic FSYNC enabled, calling fsync() each 100 requests .Calling fsync() at the end of test, Enabled. Using synchronous I/O modeDoing random r/w test Threads started! WARNING: Operation time (0.000000) is less than minimal counted value, counting as 1.000000 WARNING: Percentile statistics will be inaccurateDone. Operations performed: 6004 Read, 3996 Write, 12800 Other = 22800 TotalRead 93.812Mb Written 62.438Mb Total transferred 156.25Mb (6.472Mb/sec) 414.21 Requests/sec executed Test execution summary: total time: 24.1426s total number of events: 10000 total time taken by event execution: 164.4243 per-request statistics: min: 0.00ms avg: 16.44ms
max: 821.08ms approx. 95 percentile: 102.40ms events (avg/stddev): 625.0000/63.99 e xecution time (avg/stddev): 10.2765/0.62 清理现场 # ./sysbench –test=fileio –num-threads=16 –file-total-size=3G –file-test-mode=rndrw cleanup sysbench 0.4.12: multi-threaded system evaluation benchmark Removing test files… 4、内存测试 下面的参数指定了本次测试整个过程是在内存中传输 1G 的数据量,每个 block 大小为 8K。 ./sysbench –test=memory –num-threads=64 –memory-block-size=8192 –memory-total-size=1G run sysbench 0.4.12: multi-threaded system evaluation benchmark Running the test with following options: Number of threads: 64 Doing memory operations speed test Memory block size: 8K Memory transfer size: 1024M Memory operations type: writeMemory scope type: globalThreads started!(last message repeated 1 times) WARNING: Operation time (0.000000) is less than minimal counted value, counting as 1.000000 WARNING: Percentile statistics will be inaccurate(last message repeated 1 times)Done. Operations performed: 131072 (416391.08 ops/sec) 1024.00 MB transferred (3253.06 MB/sec) Test execution summary: total time: 0.3148s total number of events: 131072 total time taken by event execution: 17.5553 per-request statistics: min: 0.00ms avg: 0.13ms max: 289.55ms
approx. 95 percentile: 0.00ms events (avg/stddev): 2048.0000/4854.85 execution time (avg/stddev): 0.2743/0.04 5、Mutex测试
测试mutex
–mutex-loops=15000 run
Running the test with following options:
Doing mutex performance test
Threads fairness: 6、MySQL数据库测试
生成测试数据,引擎为myisam,表大小为1000000条记录 [root@localhost ]# ./sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 \ --mysql-user=root --mysql-socket=/opt/mysql/run/mysql.sock prepare sysbench 0.4.12: multi-threaded system evaluation benchmark No DB drivers specified, using mysql Creating 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 | | | | +-------+------------------+------+-----+---------+----------------+ 执行测试 [root@localhost ]# ./sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 \ --mysql-user=root --mysql-socket=/opt/mysql/run/mysql.sock run sysbench 0.4.12: multi-threaded system evaluation benchmark No DB drivers specified, using mysql Running the test with following options: Number of threads: 1 Doing OLTP test. Running mixed OLTP test Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases) Using "LOCK TABLES WRITE" for starting transactions Using auto_inc on the id column Maximum number of requests for OLTP test is limited to 10000 Threads 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.36ms Threads fairness: events (avg/stddev): 10000.0000/0.00 execution time (avg/stddev): 29.6301/0.00 清理现场 [root@localhost ]# ./sysbench--test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 \ --mysql-user=root --mysql-socket=/opt/mysql/run/mysql.sock cleanup sysbench 0.4.12: multi-threaded system evaluation benchmark No DB drivers specified, using mysql Dropping table 'sbtest'... Done. (责任编辑:IT) |