基準測試工具之sysbench
它主要包括以下幾種方式的測試:
1、cpu性能
2、磁盤io性能
3、調度程序性能
4、內存分配及傳輸速度
5、POSIX線程性能
6、數據庫性能(OLTP基準測試)
目前sysbench主要支持 mysql,pgsql,oracle
這3種數據庫。
一 前期準備
1 下載 sysbench
http://sf.net/projects/sysbench/
2 安裝:
[root@rac3 ~]# tar zxvf sysbench-0.4.12.tar.gz
[root@rac3 ~]# cd sysbench-0.4.12
[root@rac3 sysbench-0.4.12]# ls
acinclude.m4 autogen.sh config configure.ac doc install-sh Makefile.in mkinstalldirs README-WIN.txt TODO
aclocal.m4 ChangeLog configure COPYING INSTALL Makefile.am missing README sysbench
[root@rac3 sysbench-0.4.12]# ./autogen.sh
[root@rac3 sysbench-0.4.12]#
[root@rac3 sysbench-0.4.12]# ./configure
--prefix=/usr/local/sysbench \ --指定sysbench的安裝目錄
--with-mysql-includes=/usr/include/mysql \ --mysql的頭文件
--with-mysql-libs=/var/lib/mysql --mysql 鏈接庫文件
默認是支持mysql的,如果要測試oracle或者pgsql 必須使用--with-oracle ,--with-pgsql 比如:
Note
如果是oracle,在.bash_profile文件中添加:
export CC=cc
export CXX=c++
export CFLAGS="-m64 -I /opt/oracle/11.2.0/alifpre/rdbms/public"
export CXXFLAGS="$CFLAGS"
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
編譯sysbench:
[oracle@rac3 sysbench-0.4.12]# ./autogen.sh
[oracle@rac3 sysbench-0.4.12]#
[oracle@rac3 sysbench-0.4.12]# ./configure
--prefix=/home/oracle/sysbench
--with-oracle-libs=/opt/oracle/11.2.0/alifpre/lib
--with-oracle
--without-mysql --可選
make ORA_LIBS=/opt/oracle/11.2.0/alifpre/lib/libclntsh.so && make install
3 用法
Usage:
sysbench [general-options]... --test=<test-name> [test-options]... command
General options:
--num-threads=N number of threads to use [1] 默認爲1
--max-requests=N limit for total number of requests [10000] 最大的請求數
--max-time=N limit for total execution time in seconds [0] 默認爲 0 爲無限制
--forced-shutdown=STRING 達到最大執行時間未結束,則強制關閉。默認是[off]
--thread-stack-size=SIZE size of stack per thread [32K]每個線程的stack的大小
--init-rng=[on|off] initialize random number generator [off]
--test=STRING 測試類型 cpu,fileio,oltp,mutex,memory
--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
二 測試
前面介紹了sysbench 是一個可以測試 cpu性能,磁盤io性能,調度程序性能,內存分配及傳輸速度,POSIX線程性能,數據庫性能.下面依次介紹
2.1 測試cup,cpu測試主要是進行素數的加法運算,例子中指定了最大的素數爲 80000
[root@rac3 kernel]# sysbench --test=cpu --cpu-max-prime=80000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Doing CPU performance benchmark
Threads started!
Done.
Maximum prime number checked in CPU test: 80000
Test execution summary:
total time: 172.6663s
total number of events: 10000
total time taken by event execution: 172.6490
per-request statistics:
min: 17.07ms
avg: 17.26ms
max: 73.72ms
approx. 95 percentile: 17.62ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 172.6490/0.00
2.2 測試fileio
選項 描述
--file-num Number of files to create默認爲128
--file-block-size讀寫操作是I/O的操作單位默認爲16K
--file-total-size測試文件的總大小 默認爲2G
--file-io-mode I/O mode. Possible values: sync, async, fastmmap, slowmmap (only if supported
by the platform, see above).sync
--file-async-backlogNumber of asynchronous operations to queue per thread (only for --file-io-mode=async,
see above)128
--file-extra-flagsAdditional flags to use with open(2)
--file-fsync-freqDo fsync() after this number of requests (0 - don not use fsync())100
--file-fsync-allDo fsync() after each write operationno
--file-fsync-endDo fsync() at the end of the testyes
--file-fsync-modeWhich method to use for synchronization. Possible values: fsync, fdatasync (see
above)fsync
--file-merged-requestsMerge at most this number of I/O requests if possible (0 - don not merge)0
--file-rw-ratio reads/writes ration for combined random read/write test1.5
--file-test-mode 指定文件測試類型:
seqwr sequential write
seqrewr sequential rewrite
seqrd sequential read
rndrd random read
rndwr random write
rndrw combined random read/write
下面的例子 prepare 命令創建了128個文件總共大小爲10G ,文件讀寫模式爲隨機讀寫混合方式。run 命令則進行測試,並返回結果,cleanup 刪除測試產生的文件!
[root@rac3 ~]# sysbench --num-threads=16 --test=fileio --file-total-size=10G --file-test-mode=rndrw prepare
sysbench 0.4.12: multi-threaded system evaluation benchmark
128 files, 81920Kb each, 10240Mb total
Creating files for the test...
[root@rac3 ~]# sysbench --num-threads=16 --test=fileio --file-total-size=10G --file-test-mode=rndrw run
Operations performed: 6006 Read, 3994 Write, 12800 ther = 22800 Total
Read 93.844Mb Written 62.406Mb Total transferred 156.25Mb (9.4882Mb/sec)
607.24 Requests/sec executed
Test execution summary:
total time: 16.4678s
total number of events: 10000
total time taken by event execution: 225.4641
per-request statistics:
min: 0.01ms
avg: 22.55ms
max: 498.74ms
approx. 95 percentile: 101.48ms
Threads fairness:
events (avg/stddev): 625.0000/29.59
execution time (avg/stddev): 14.0915/0.30
[root@rac3 ~]# sysbench --num-threads=16 --test=fileio --file-total-size=10G --file-test-mode=rndrw cleanup
sysbench 0.4.12: multi-threaded system evaluation benchmark
Removing test files...
[root@rac3 ~]#
2.3 memory 內存測試
sysbench 測試memory的時候是順序讀或寫內存的。根據選項的不同,每次操作過程中,每個線程可以獲取global或本地的數據塊
[root@rac3 ~]# sysbench --test=memory --memory-block-size=1k --memory-total-size=0.5G run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Doing memory operations speed test
Memory block size: 0K
Memory transfer size: 0M
Memory operations type: write
Memory scope type: global
Threads started!
Done.
Operations performed: 0 ( 0.00 ops/sec)
0.00 MB transferred (0.00 MB/sec)
Test execution summary:
total time: 0.0002s
total number of events: 0
total time taken by event execution: 0.0000
per-request statistics:
min: 18446744073709.55ms
avg: 0.00ms
max: 0.00ms
Threads fairness:
events (avg/stddev): 0.0000/0.00
execution time (avg/stddev): 0.0000/0.00
2.4 thread 測試
[root@rac3 ~]# sysbench --num-threads=64 --test=threads --thread-yields=100 --thread-locks=2 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 64
Doing thread subsystem performance test
Thread yields per test: 100 Locks used: 2
Threads started!
Done.
Test execution summary:
total time: 2.0199s
total number of events: 10000
total time taken by event execution: 128.6847
per-request statistics:
min: 0.38ms
avg: 12.87ms
max: 2016.38ms
approx. 95 percentile: 0.42ms
Threads fairness:
events (avg/stddev): 156.2500/262.89
execution time (avg/stddev): 2.0107/0.00
2.5 mutex 測試
所有線程同時執行,獲取短時間的mutex lock,以便測試mutex的實現!
[root@rac3 ~]# sysbench --test=mutex --mutex-num=4096 --mutex-locks=50000 --mutex-loops=20000 run
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Doing mutex performance test
Threads started!
Done.
Test execution summary:
total time: 0.0053s
total number of events: 1
total time taken by event execution: 0.0051
per-request statistics:
min: 5.11ms
avg: 5.11ms
max: 5.11ms
approx. 95 percentile: 10000000.00ms
Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 0.0051/0.00
2.6 oltp測試
sysbench 進行oltp 測試的之前,必須創建一個--mysql-db 指定的或者默認的sbtest 數據庫,進行prepare的時候,sysbench自動創建一個sbtest表。
[root@rac3 ~]# sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-user=root --mysql-host=127.0.0.1 --mysql-db=test 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'... --創建了一個1000000行的表sbtest
進行測試 三種不同的測試模式:semple,complex,nontrx
[root@rac3 ~]# sysbench --test=oltp \
--mysql-table-engine=innodb \
--oltp-table-size=1000000 \
--mysql-user=root \
--mysql-host=127.0.0.1 \
--mysql-db=test run
OLTP test statistics:
queries performed:
read: 140000
write: 50000
other: 20000
total: 210000
transactions: 10000 (292.09 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 190000 (5549.78 per sec.)
other operations: 20000 (584.19 per sec.)
Test execution summary:
total time: 34.2356s
total number of events: 10000
total time taken by event execution: 34.1541
per-request statistics:
min: 2.80ms
avg: 3.42ms
max: 128.54ms
approx. 95 percentile: 3.60ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 34.1541/0.00
[root@rac3 ~]# sysbench --test=oltp --mysql-table-engine=innodb \
--oltp-table-size=1000000 \
--mysql-user=root \
--mysql-host=127.0.0.1 \
--mysql-db=test \
--oltp-test-mode=complex run
sysbench 0.4.12: multi-threaded system evaluation benchmark
OLTP test statistics:
queries performed:
read: 140000
write: 50000
other: 20000
total: 210000
transactions: 10000 (294.07 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 190000 (5587.40 per sec.)
other operations: 20000 (588.15 per sec.)
Test execution summary:
total time: 34.0051s
total number of events: 10000
total time taken by event execution: 33.9249
per-request statistics:
min: 2.78ms
avg: 3.39ms
max: 114.85ms
approx. 95 percentile: 3.57ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 33.9249/0.00
若進行mode爲nontrx 的測試之前,已經進行了其他兩種模式的測試,先執行cleanup 或者prepare
[root@rac3 ~]# sysbench --test=oltp \
--mysql-table-engine=innodb \
--oltp-table-size=1000000 \
--mysql-user=root \
--mysql-host=127.0.0.1 \
--mysql-db=test \
--oltp-test-mode=nontrx run
OLTP test statistics:
queries performed:
read: 10000
write: 0
other: 0
total: 10000
transactions: 10000 (12276.25 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 10000 (12276.25 per sec.)
other operations: 0 (0.00 per sec.)
Test execution summary:
total time: 0.8146s
total number of events: 10000
total time taken by event execution: 0.7892
per-request statistics:
min: 0.07ms
avg: 0.08ms
max: 0.41ms
approx. 95 percentile: 0.09ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 0.7892/0.00
[root@rac3 ~]# sysbench --test=oltp --mysql-table-engine=innodb --oltp-table-size=1000000 --mysql-user=root --mysql-host=127.0.0.1 --mysql-db=test --oltp-test-mode=nontrx cleanup
sysbench 0.4.12: multi-threaded system evaluation benchmark
No DB drivers specified, using mysql
Dropping table 'sbtest'...
Done.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.