【工具】基準測試工具之sysbench

楊奇龍發表於2013-03-31
sysbench是一個模組化的、跨平臺、多執行緒基準測試工具,主要用於評估測試各種不同系統引數下的資料庫負載情況
它主要包括以下幾種方式的測試:
1、cpu效能
2、磁碟io效能
3、排程程式效能
4、記憶體分配及傳輸速度
5、POSIX執行緒效能
6、資料庫效能(OLTP基準測試)
目前sysbench主要支援 mysql,pgsql,oracle 這3種資料庫。
一 前期準備
1 下載 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-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-backlog Number of asynchronous operations to queue per thread (only for --file-io-mode=async, see above) 128
--file-extra-flags Additional flags to use with open(2)  
--file-fsync-freq Do fsync() after this number of requests (0 - don not use fsync()) 100
--file-fsync-all Do fsync() after each write operation no
--file-fsync-end Do fsync() at the end of the test yes
--file-fsync-mode Which method to use for synchronization. Possible values: fsync, fdatasync (see above) fsync
--file-merged-requests Merge 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 test 1.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.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-713075/,如需轉載,請註明出處,否則將追究法律責任。

相關文章