1. 程式人生 > >MySql效能測試工具-sysbench

MySql效能測試工具-sysbench

雖然mysql預設的有mysqlslap這個效能測試工具,但和sysbench比較來說,還遜色不少。

shell> wget https://github.com/akopytov/sysbench/archive/1.0.zip -O "sysbench-1.0.zip"
shell> unzip sysbench-1.0.zip
shell> cd sysbench-1.0
  1. 安裝依賴庫
shell> yum install automake libtool -y
  1. 開始安裝
shell> ./autogen.sh
shell> ./configure
#ERROR: cannot find MySQL libraries. If you want to compile with MySQL support 沒找到mysql庫 需要用引數指定下 --with-mysql-includes和--with-mysql-libs
shell> ./configure --with-mysql-includes=/alidata/server/mysql5.7/include/ --with-mysql-libs=/alidata/server/mysql5.7/lib/ shell> make
  1. 執行下命令:
shell> sysbench --help
#sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
#問題原因:sysbench無法找到mysql的庫檔案,可能是環境變數LD_LIBRARY_PATH沒有設定,設定後即可解決該問題:
shell> export LD_LIBRARY_PATH=/alidata/server/mysql5.7/lib/lib shell> sysbench --version sysbench 1.0
  1. 建立測試資料庫sbtest
shell> mysqladmin create sbtest -uroot -p
Enter password:
  1. 測試準備: 20個併發連線,20張表 每個表填充10W條資料 最大請求時間120s
#-test=tests/db/oltp.lua 表示呼叫 tests/db/oltp.lua 指令碼進行 oltp 模式測試
#--oltp_tables_count=10 表示會生成 10 個測試表
#--oltp-table-size=100000 表示每個測試表填充資料量為 100000 #--rand-init=on 表示每個測試表都是用隨機資料來填充的 #-num-threads=8 表示發起 8個併發連線 #--oltp-read-only=off 表示不要進行只讀測試,也就是會採用讀寫混合模式測試 #--report-interval=10 表示每10秒輸出一次測試進度報告 #--rand-type=uniform 表示隨機型別為固定模式,其他幾個可選隨機模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累託) #--max-time=120 表示最大執行時長為 120秒 #--max-requests=0 表示總請求數為 0,因為上面已經定義了總執行時長,所以總請求數可以設定為 0;也可以只設定總請求數,不設定最大執行時長 #--percentile=99 表示設定取樣比例,預設是 95%,即丟棄1%的長請求,在剩餘的99%裡取最大值 shell> sysbench --test=oltp --oltp_tables_count=10 --oltp-table-size=100000 --mysql-user=root --mysql-password=123456 --num-threads=20 --max-time=120 --max-requests=0 --oltp-test-mode=complex prepare sysbench 1.0: multi-threaded system evaluation benchmark Creating table 'sbtest1'... Inserting 100000 records into 'sbtest1' Creating secondary indexes on 'sbtest1'... Creating table 'sbtest2'... Inserting 100000 records into 'sbtest2' Creating secondary indexes on 'sbtest2'... Creating table 'sbtest3'... Inserting 100000 records into 'sbtest3' Creating secondary indexes on 'sbtest3'... Creating table 'sbtest4'... Inserting 100000 records into 'sbtest4' Creating secondary indexes on 'sbtest4'... Creating table 'sbtest5'... Inserting 100000 records into 'sbtest5' Creating secondary indexes on 'sbtest5'... Creating table 'sbtest6'... Inserting 100000 records into 'sbtest6' Creating secondary indexes on 'sbtest6'... Creating table 'sbtest7'... Inserting 100000 records into 'sbtest7' Creating secondary indexes on 'sbtest7'... Creating table 'sbtest8'... Inserting 100000 records into 'sbtest8' Creating secondary indexes on 'sbtest8'... Creating table 'sbtest9'... Inserting 100000 records into 'sbtest9' Creating secondary indexes on 'sbtest9'... Creating table 'sbtest10'... Inserting 100000 records into 'sbtest10' Creating secondary indexes on 'sbtest10'...

7.開始測試

shell> sysbench --test=oltp --oltp_tables_count=10 --oltp-table-size=100000 --mysql-user=root --mysql-password=123456 --num-threads=20 --max-time=120 --max-requests=0 --oltp-test-mode=complex run >> /tmp/log/sysbench_oltpx_20161121.log

#執行結束後檢視測試報告
shell> less /tmp/log/sysbench_oltpx_20161121.log
sysbench 1.0:  multi-threaded system evaluation benchmark

#報告內容如下:
Running the test with following options:
Number of threads: 20
Initializing random number generator from current time


Initializing worker threads...

Threads started!

OLTP test statistics:
    queries performed:
        read:                            935592 --讀總數
        write:                           267295 --寫總數
        other:                           133650 --其他操作(CURD之外的操作,例如COMMIT)
        total:                           1336537 --全部總數
    transactions:                        66822  (556.77 per sec.) --總事務數(每秒事務數)
    read/write requests:                 1202887 (10022.55 per sec.) --讀寫總數(每秒讀寫次數)
    other operations:                    133650 (1113.58 per sec.)  --其他操作總數(每秒其他操作次數)
    ignored errors:                      6      (0.05 per sec.)  --總忽略錯誤總數(每秒忽略錯誤次數)
    reconnects:                          0      (0.00 per sec.) --重連總數(每秒重連次數)

General statistics: --常規統計
    total time:                          120.0180s --總耗時
    total number of events:              66822 --共發生多少事務數
    total time taken by event execution: 2399.7900s  --所有事務耗時相加(不考慮並行因素)
    response time:
         min:                                  2.76ms --最小耗時
         avg:                                 35.91ms --平均耗時
         max:                               1435.19ms --最長耗時
         approx.  95 percentile:              84.22ms --超過95%平均耗時

Threads fairness: --併發統計
    events (avg/stddev):           3341.1000/37.54 --總處理事件數/標準偏差
    execution time (avg/stddev):   119.9895/0.02
--總執行時間/標準偏差