sysbench工具手把手安裝配置及使用案例

ultradb發表於2016-10-21




sysbench是一款測試工具
主要包括以下幾種方式的測試:
1、cpu效能
2、磁碟io效能
3、排程程式效能
4、記憶體分配及傳輸速度
5、POSIX執行緒效能
6、資料庫效能(OLTP基準測試)現在sysbench主要支援 MySQL,pgsql,oracle 這3種資料庫
本文以實際的安裝和簡單的測試以做拋磚引玉,希望在泰嶽的效能測試中發揮應有的作用。
 


一:安裝mysql
先安裝
MySQL-client-5.5.32-1.rhel5.i386.rpm
MySQL-server-5.5.32-1.rhel5.i386.rpm
下面三個用於效能測試用
MySQL-shared-5.5.32-1.rhel5.i386.rpm
MySQL-devel-5.5.32-1.rhel5.i386.rpm
MySQL-shared-compat-5.5.32-1.rhel5.i386.rpm
二:安裝sysbench
    安裝sysbench因為是原始碼需要編譯及需要其他的包或工具,較為繁瑣,現做具體介紹
1.下載sysbench  sysbench-0.4.12.tar.gz,並上傳到/usr/local目錄下
[root@localhost local]# ls
bin                    etc       man                                          sbin
cmake-2.8.10.2         games     mysql-5.6.11.tar.gz                          share
cmake-2.8.10.2.tar.gz  include   MySQL-client-5.5.32-1.rhel5.i386.rpm         src
config                 lib       MySQL-devel-5.5.32-1.rhel5.i386.rpm         
config.log             libexec   MySQL-server-5.5.32-1.rhel5.i386.rpm         sysbench-0.4.12.tar.gz
config.status          libtool   MySQL-shared-5.5.32-1.rhel5.i386.rpm
doc                    Makefile  MySQL-shared-compat-5.5.32-1.rhel5.i386.rpm
 
2.解壓   tax -zxvf sysbench-0.4.12.tar.gz


[root@localhost local]# ls
bin                    etc       man                                          sbin
cmake-2.8.10.2         games     mysql-5.6.11.tar.gz                          share
cmake-2.8.10.2.tar.gz  include   MySQL-client-5.5.32-1.rhel5.i386.rpm         src
config                 lib       MySQL-devel-5.5.32-1.rhel5.i386.rpm          sysbench-0.4.12
config.log             libexec   MySQL-server-5.5.32-1.rhel5.i386.rpm         sysbench-0.4.12.tar.gz
config.status          libtool   MySQL-shared-5.5.32-1.rhel5.i386.rpm
doc                    Makefile  MySQL-shared-compat-5.5.32-1.rhel5.i386.rpm
3.編譯,安裝
/usr/local/sysbench-0.4.12/configure --with-mysql-includes=/usr/include/mysql --with-mysql-libs=/usr/lib && make && make install
....
test -z "/usr/local/share/doc/sysbench" || mkdir -p -- "/usr/local/share/doc/sysbench"
 /usr/bin/install -c -m 644 'manual.html' '/usr/local/share/doc/sysbench/manual.html'
make[3]: Leaving directory `/usr/local/sysbench-0.4.12/doc'
make[2]: Leaving directory `/usr/local/sysbench-0.4.12/doc'
make[1]: Leaving directory `/usr/local/sysbench-0.4.12/doc'
Making install in sysbench
make[1]: Entering directory `/usr/local/sysbench-0.4.12/sysbench'
Making install in drivers
make[2]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/drivers'
Making install in mysql
make[3]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/drivers/mysql'
make[4]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/drivers/mysql'
make[4]: Nothing to be done for `install-exec-am'.
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/drivers/mysql'
make[3]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/drivers/mysql'
make[3]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/drivers'
make[4]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/drivers'
make[4]: Nothing to be done for `install-exec-am'.
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/drivers'
make[3]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/drivers'
make[2]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/drivers'
Making install in tests
make[2]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests'
Making install in cpu
make[3]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/cpu'
make[4]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/cpu'
make[4]: Nothing to be done for `install-exec-am'.
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/cpu'
make[3]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/cpu'
Making install in fileio
make[3]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/fileio'
make[4]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/fileio'
make[4]: Nothing to be done for `install-exec-am'.
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/fileio'
make[3]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/fileio'
Making install in memory
make[3]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/memory'
make[4]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/memory'
make[4]: Nothing to be done for `install-exec-am'.
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/memory'
make[3]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/memory'
Making install in threads
make[3]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/threads'
make[4]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/threads'
make[4]: Nothing to be done for `install-exec-am'.
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/threads'
make[3]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/threads'
Making install in mutex
make[3]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/mutex'
make[4]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/mutex'
make[4]: Nothing to be done for `install-exec-am'.
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/mutex'
make[3]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/mutex'
Making install in oltp
make[3]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/oltp'
make[4]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests/oltp'
make[4]: Nothing to be done for `install-exec-am'.
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/oltp'
make[3]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests/oltp'
make[3]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests'
make[4]: Entering directory `/usr/local/sysbench-0.4.12/sysbench/tests'
make[4]: Nothing to be done for `install-exec-am'.
make[4]: Nothing to be done for `install-data-am'.
make[4]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests'
make[3]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests'
make[2]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench/tests'
Making install in .
make[2]: Entering directory `/usr/local/sysbench-0.4.12/sysbench'
make[3]: Entering directory `/usr/local/sysbench-0.4.12/sysbench'
test -z "/usr/local/bin" || mkdir -p -- "/usr/local/bin"
  /bin/sh ../libtool --mode=install /usr/bin/install -c 'sysbench' '/usr/local/bin/sysbench'
/usr/bin/install -c sysbench /usr/local/bin/sysbench
make[3]: Nothing to be done for `install-data-am'.
make[3]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench'
make[2]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench'
make[1]: Leaving directory `/usr/local/sysbench-0.4.12/sysbench'
make[1]: Entering directory `/usr/local/sysbench-0.4.12'
make[2]: Entering directory `/usr/local/sysbench-0.4.12'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/usr/local/sysbench-0.4.12'
make[1]: Leaving directory `/usr/local/sysbench-0.4.12'


三測試:
1.資料庫oltp測試,這個需要建立資料庫sbtest;以下見具體測試用例
[root@localhost local]# sysbench --num-threads=5 --max-requests=1000 --test=oltp --mysql-table-engine=myisam --oltp-table-size=4000000 --mysql-socket=/var/lib/mysql/mysql.sock --mysql-db=sbtest --mysql-user=root --mysql-host=127.0.0.1  --mysql-password=root 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: 5
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 1000
Threads started!
Done.
OLTP test statistics:
    queries performed:
        read:                            14000
        write:                           5000
        other:                           2000
        total:                           21000
    transactions:                        1000   (51.63 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 19000  (981.00 per sec.)
    other operations:                    2000   (103.26 per sec.)
Test execution summary:
    total time:                          19.3679s
    total number of events:              1000
    total time taken by event execution: 94.0158
    per-request statistics:
         min:                                 14.71ms
         avg:                                 94.02ms
         max:                               5708.77ms
         approx.  95 percentile:             113.91ms
Threads fairness:
    events (avg/stddev):           200.0000/72.46
    execution time (avg/stddev):   18.8032/0.26
[root@localhost local]# sysbench --num-threads=5 --max-requests=5000 --test=oltp --mysql-table-engine=myisam --oltp-table-size=4000000 --mysql-socket=/var/lib/mysql/mysql.sock --mysql-db=sbtest --mysql-user=root --mysql-host=127.0.0.1  --mysql-password=root 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: 5
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 5000
Threads started!
Done.
OLTP test statistics:
    queries performed:
        read:                            70000
        write:                           25000
        other:                           10000
        total:                           105000
    transactions:                        5000   (46.05 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 95000  (874.91 per sec.)
    other operations:                    10000  (92.10 per sec.)
Test execution summary:
    total time:                          108.5830s
    total number of events:              5000
    total time taken by event execution: 542.5105
    per-request statistics:
         min:                                 17.93ms
         avg:                                108.50ms
         max:                               7212.44ms
         approx.  95 percentile:             146.43ms
Threads fairness:
    events (avg/stddev):           1000.0000/96.35
    execution time (avg/stddev):   108.5021/0.03


2.cpu測試
cpu測試主要是進行素數的加法運算,在上面的例子中,指定了最大的素數為 20000,自己可以根據機器cpu的效能來適當調整數值。
sysbench --test=cpu --cpu-max-prime=200 run
[root@localhost ~]# sysbench --test=cpu --cpu-max-prime=200 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: 200


Test execution summary:
    total time:                          0.5087s
    total number of events:              10000
    total time taken by event execution: 0.4448
    per-request statistics:
         min:                                  0.03ms
         avg:                                  0.04ms
         max:                                 20.45ms
         approx.  95 percentile:               0.02ms
Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   0.4448/0.00
[root@localhost ~]# sysbench --test=cpu --cpu-max-prime=2000 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: 2000


Test execution summary:
    total time:                          3.3867s
    total number of events:              10000
    total time taken by event execution: 3.3185
    per-request statistics:
         min:                                  0.14ms
         avg:                                  0.33ms
         max:                                 14.34ms
         approx.  95 percentile:               0.36ms
Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   3.3185/0.00
[root@localhost ~]# sysbench --test=cpu --cpu-max-prime=20000 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: 20000


Test execution summary:
    total time:                          61.4178s
    total number of events:              10000
    total time taken by event execution: 61.3427
    per-request statistics:
         min:                                  1.13ms
         avg:                                  6.13ms
         max:                                 56.49ms
         approx.  95 percentile:               7.96ms
Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   61.3427/0.00
3、執行緒測試
sysbench --test=threads --num-threads=16 --thread-yields=100 --thread-locks=2 run
[root@localhost ~]# sysbench --test=cpu --cpu-max-prime=20000 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: 20000


Test execution summary:
    total time:                          61.4178s
    total number of events:              10000
    total time taken by event execution: 61.3427
    per-request statistics:
         min:                                  1.13ms
         avg:                                  6.13ms
         max:                                 56.49ms
         approx.  95 percentile:               7.96ms
Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   61.3427/0.00
[root@localhost ~]# sysbench --test=threads --num-threads=16 --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: 16
Doing thread subsystem performance test
Thread yields per test: 100 Locks used: 2
Threads started!
Done.


Test execution summary:
    total time:                          83.0173s
    total number of events:              10000
    total time taken by event execution: 1327.3256
    per-request statistics:
         min:                                 13.21ms
         avg:                                132.73ms
         max:                               7176.51ms
         approx.  95 percentile:             835.83ms
Threads fairness:
    events (avg/stddev):           625.0000/109.40
    execution time (avg/stddev):   82.9578/0.03
[root@localhost ~]#
4、磁碟IO效能測試
sysbench --test=fileio --num-threads=5 --file-total-size=100M --file-test-mode=rndrw prepare
sysbench --test=fileio --num-threads=5 --file-total-size=100M --file-test-mode=rndrw run
sysbench --test=fileio --num-threads=5 --file-total-size=100M --file-test-mode=rndrw  cleanup
[root@localhost ~]# sysbench --test=fileio --num-threads=5 --file-total-size=100M --file-test-mode=rndrw run
sysbench 0.4.12:  multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 5
Extra file open flags: 0
128 files, 800Kb each
100Mb 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 mode
Doing random r/w test
Threads started!
Done.
Operations performed:  5999 Read, 4001 Write, 12800 Other = 22800 Total
Read 93.734Mb  Written 62.516Mb  Total transferred 156.25Mb  (12.456Mb/sec)
  797.20 Requests/sec executed
Test execution summary:
    total time:                          12.5439s
    total number of events:              10000
    total time taken by event execution: 4.0691
    per-request statistics:
         min:                                  0.03ms
         avg:                                  0.41ms
         max:                                207.37ms
         approx.  95 percentile:               0.08ms
Threads fairness:
    events (avg/stddev):           2000.0000/247.35
    execution time (avg/stddev):   0.8138/0.22
root@localhost ~]# sysbench --test=fileio --num-threads=5 --file-total-size=100M --file-test-mode=rndrw  cleanup
sysbench 0.4.12:  multi-threaded system evaluation benchmark
Removing test files...
[root@localhost ~]#
上述引數指定了最大建立5個執行緒,建立的檔案總大小為100M,檔案讀寫模式為隨機讀。
4、記憶體測試
sysbench --test=memory --memory-block-size=8k --memory-total-size=100M run
上述引數指定了本次測試整個過程是在記憶體中傳輸 100M 的資料量,每個 block 大小為 8K。


四:實際過程中可能會遇到一些問題:
問題2. 出現configure: error: no acceptable C compiler found in $PATH
解決辦法:安裝gcc,命令為:yum install gcc。
問題2:出現../libtool: line 5172: : command not found
解決辦法   執行[root@localhost sysbench-0.4.12]# ./autogen.sh
問題3:source directory already configured, make distclean的錯誤解決 .
解決辦法:在sysbench目錄執行 make distclean
問題4:configure時候出現 i686-pc-linux' not recognized提示               
      在執行./configure 時如果出現下面的提示資訊:
      checking build system
      type... Invalid configuration `i686-pc-linux-': machine `i686-pc-linux' not
      recognized
      configure: error:
      /bin/sh ./config.sub i686-pc-linux- failed
解決辦法:就使用./configure --build=i686-pc-linux-gnu來設定

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

相關文章