1. 程式人生 > >sysbench 壓測 詳解

sysbench 壓測 詳解

文件的 localhost cif 大小 測試方法 libs lock 五個 none

下載sysbench(mysql官網就有)
解壓,進入解壓以後的目錄
./autogen.sh
./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib
make && make install
export LD_LIBRARY_PATH=/usr/local/mysql/lib

開始進行測試
通用配置
接下來我們來分別看一下各個模式的相關參數、測試方法和結果分析。
sysbench的基本命令格式為:
sysbench –test=< test-name> [options]… < command>

主要分為三個部分:

1、–test=< test-name>
這部分是指定測試類型,基本類型有fileio,cpu,memory,threads,mutex,oltp(或者指定lua腳本)

2、[options]…
這部分包括測試需要的各種選項,有全局的也有每個測試模式自由的選項
(每個測試模式的選項可以用./sysbench –test=< test-name> help來獲取)

3、< command>
控制命令,總共有五個
prepare #準備測試,主要是生成測試數據
run #執行測試,根據選項限制來執行測試
cleanup #清除準備階段生成的測試數據

help #獲取幫助文檔
version #獲取版本信息

幾個重要的全局參數:
–num-threads=N number of threads to use [1] #測試時使用的線程數
–max-requests=N limit for total number of requests [10000] #測試過程最多執行多少次請求
–max-time=N limit for total execution time in seconds [0] #測試過程總共執行多長時間(和–max-requests效果同樣,但是兩個同時限定的時候誰優先還沒有測試)
–report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0] #每隔多少秒輸出測試概況(這個過程你可以觀察到mysql redolog的切換情況)

–db-driver=STRING specifies database driver to use (‘help’ to get list of available drivers) #指定需求測試的數據庫類型,默認是mysql
#mysql鏈接選項
–mysql-host=[LIST,…] MySQL server host [localhost] #mysql主機地址
–mysql-port=N MySQL server port [3306] #mysql端口
–mysql-socket=[LIST,…] MySQL socket #mysql socket文件位置,指定這個之後 其他的鏈接選項均可以不指定
–mysql-user=STRING MySQL user [sbtest] #用來測試的mysql用戶名
–mysql-password=STRING MySQL password [] #密碼
–mysql-db=STRING MySQL database name [sbtest] #測試數據庫名 默認sbtest

1、測試磁盤IO性能

參數詳解: 
–file-num=N 代表生成測試文件的數量,默認為128。 
–file-block-size=N 測試時所使用文件塊的大小,如果想磁盤針對innodb存儲引擎進行測試,可以將其設置為16384,即innodb存儲引擎頁的大小。默認為16384。 
–file-total-size=SIZE 創建測試文件的總大小,默認為2G大小。 
–file-test-mode=STRING 文件測試模式,包含:seqwr(順序寫), seqrewr(順序讀寫), seqrd(順序讀), rndrd(隨機讀), rndwr(隨機寫), rndrw(隨機讀寫)。 
–file-io-mode=STRING 文件操作的模式,sync(同步),async(異步),fastmmap(快速mmap),slowmmap(慢速mmap),默認為sync同步模式。 
–file-async-backlog=N 對應每個線程隊列的異步操作數,默認為128。 
–file-extra-flags=STRING 打開文件時的選項,這是與API相關的參數。 
–file-fsync-freq=N 執行fsync()函數的頻率。fsync主要是同步磁盤文件,因為可能有系統和磁盤緩沖的關系。 0代表不使用fsync函數。默認值為100。 
–file-fsync-all=[on|off] 每執行完一次寫操作,就執行一次fsync。默認為off。 
–file-fsync-end=[on|off] 在測試結束時執行fsync函數。默認為on。 
–file-fsync-mode=STRING文件同步函數的選擇,同樣是和API相關的參數,由於多個操作系統對於fdatasync支持不同,因此不建議使用fdatasync。默認為fsync。 
–file-merged-requests=N 大多情況下,合並可能的IO的請求數,默認為0。 
–file-rw-ratio=N 測試時的讀寫比例,默認時為1.5,即可3:2。
1)生成測試文件
sysbench --test=fileio --file-num=10 --file-total-size=5G prepare
2)測試
sysbench --test=fileio --file-total-size=5G --file-test-mode=rndrw --max-time=180 --max-requests=100000000 --num-threads=16 --init-rng=on --file-num=10 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
3)結果如下
sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 16
Initializing random number generator from timer.

Random number generator seed is 0 and will be ignored

Extra file open flags: 4000
10 files, 512Mb each
5Gb total file size
Block size 16Kb
Number of random requests for random IO: 100000000
Read/Write ratio for combined random IO test: 1.50
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Threads started!

Time limit exceeded, exiting...
(last message repeated 15 times)
Done.

Operations performed:  17981 reads, 11990 writes, 0 Other = 29971 Total
Read 280.95Mb  Written 187.34Mb  Total transferred 468.3Mb  (2.6012Mb/sec)
  166.48 Requests/sec executed

General statistics:
    total time:                          180.0298s
    total number of events:              29971
    total time taken by event execution: 2880.3206
    response time:
         min:                                  0.38ms
         avg:                                 96.10ms
         max:                                390.42ms
         approx.  95 percentile:             209.91ms

Threads fairness:
    events (avg/stddev):           1873.1875/11.51
    execution time (avg/stddev):   180.0200/0.01

        ##註意:主要看這裏
        Read 280.95Mb  Written 187.34Mb  Total transferred 468.3Mb  (2.6012Mb/sec)  166.48 Requests/sec executed

        大概是在180秒裏面總共隨機讀取280.95MB ,寫入187.24MB ,平均每秒隨機讀寫的效率時2.6012MB ,IOPS為166.48 Requests/sec 

4)清楚測試數據
    sysbench --test=fileio --file-num=10 --file-total-size=5G cleanup

2、cpu測試
參數詳解:
–cpu-max-prime=N 用來選項指定最大的素數,具體參數可以根據CPU的性能來設置,默認為10000

sysbench --test=cpu --cpu-max-prime=20000 run

測試結果
    sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

    Running the test with following options:
    Number of threads: 1
    Random number generator seed is 0 and will be ignored

    Doing CPU performance benchmark

    Primer numbers limit: 20000

    Threads started!
    Done.

    General statistics:
        total time:                          20.8126s
        total number of events:              10000
        total time taken by event execution: 20.8006
        response time:
             min:                                  1.91ms
             avg:                                  2.08ms
             max:                                 13.94ms
             approx.  95 percentile:               2.71ms

    Threads fairness:
        events (avg/stddev):           10000.0000/0.00
        execution time (avg/stddev):   20.8006/0.00

       ##註意:測試的總時間(total time)即可(越小越憂)

3、內存分配及傳輸速度(測試了內存的連續讀寫性能)
參數詳解:
–memory-block-size=SIZE 測試內存塊的大小,默認為1K
–memory-total-size=SIZE 數據傳輸的總大小,默認為100G
–memory-scope=STRING 內存訪問的範圍,包括全局和本地範圍,默認為global
–memory-hugetlb=[on|off] 是否從HugeTLB池分配內存的開關,默認為off
–memory-oper=STRING 內存操作的類型,包括read, write, none,默認為write
–memory-access-mode=STRING 內存訪問模式,包括seq,rnd兩種模式,默認為seq

sysbench --test=memory --memory-block-size=8K --memory-total-size=1G  --num-threads=16 run

結果:
    sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

    Running the test with following options:
    Number of threads: 16
    Random number generator seed is 0 and will be ignored

    Doing memory operations speed test
    Memory block size: 8K

    Memory transfer size: 1024M

    Memory operations type: write
    Memory scope type: global
    Threads started!
    Done.

    Operations performed: 131072 (1223663.93 ops/sec)

    1024.00 MB transferred (9559.87 MB/sec)

    General statistics:
        total time:                          0.1071s
        total number of events:              131072
        total time taken by event execution: 0.3210
        response time:
             min:                                  0.00ms
             avg:                                  0.00ms
             max:                                 96.20ms
             approx.  95 percentile:               0.00ms

    Threads fairness:
        events (avg/stddev):           8192.0000/7510.93
        execution time (avg/stddev):   0.0201/0.03

4、oltp-數據庫性能測試
參數詳解:
–oltp-test-mode=STRING 執行模式{simple,complex(advanced transactional),nontrx(non-transactional),sp}。默認是complex
–oltp-reconnect-mode=STRING 重新連接模式{session(不使用重新連接。每個線程斷開只在測試結束),transaction(在每次事務結束後重新連接),query(在每個SQL語句執行完重新連接),random(對於每個事務隨機選擇以上重新連接模式)}。默認是session
–oltp-sp-name=STRING 存儲過程的名稱。默認為空
–oltp-read-only=[on|off] 只讀模式。Update,delete,insert語句不可執行。默認是off
–oltp-skip-trx=[on|off] 省略begin/commit語句。默認是off
–oltp-range-size=N 查詢範圍。默認是100
–oltp-point-selects=N number of point selects [10]
–oltp-simple-ranges=N number of simple ranges [1]
–oltp-sum-ranges=N number of sum ranges [1]
–oltp-order-ranges=N number of ordered ranges [1]
–oltp-distinct-ranges=N number of distinct ranges [1]
–oltp-index-updates=N number of index update [1]
–oltp-non-index-updates=N number of non-index updates [1]
–oltp-nontrx-mode=STRING 查詢類型對於非事務執行模式{select, update_key, update_nokey, insert, delete} [select]
–oltp-auto-inc=[on|off] AUTO_INCREMENT是否開啟。默認是on
–oltp-connect-delay=N 在多少微秒後連接數據庫。默認是10000
–oltp-user-delay-min=N 每個請求最短等待時間。單位是ms。默認是0
–oltp-user-delay-max=N 每個請求最長等待時間。單位是ms。默認是0
–oltp-table-name=STRING 測試時使用到的表名。默認是sbtest
–oltp-table-size=N 測試表的記錄數。默認是10000
–oltp-dist-type=STRING 分布的隨機數{uniform(均勻分布),Gaussian(高斯分布),special(空間分布)}。默認是special
–oltp-dist-iter=N 產生數的叠代次數。默認是12
–oltp-dist-pct=N 值的百分比被視為’special’ (for special distribution)。默認是1
–oltp-dist-res=N ‘special’的百分比值。默認是75

  1)創建測試用的數據
    sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 prepare
  2)開始測試
    sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 --max-time=60 --oltp-read-only=off --max-requests=0 --num-threads=8 run
  3)結果如下
        sysbench 0.4.12.10:  multi-threaded system evaluation benchmark

        No DB drivers specified, using mysql
        Running the test with following options:
        Number of threads: 8
        Random number generator seed is 0 and will be ignored

        Doing OLTP test.
        Running mixed OLTP test
        Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
        Using "BEGIN" for starting transactions
        Using auto_inc on the id column
        Using 1 test tables
        Threads started!
        Time limit exceeded, exiting...
        (last message repeated 7 times)
        Done.

        OLTP test statistics:
            queries performed:
                read:                            263046
                write:                           93934
                other:                           37574
                total:                           394554
            transactions:                        18785  (313.05 per sec.)
            deadlocks:                           4      (0.07 per sec.)
            read/write requests:                 356980 (5948.98 per sec.)
            other operations:                    37574  (626.16 per sec.)

        General statistics:
            total time:                          60.0069s
            total number of events:              18785
            total time taken by event execution: 479.9184
            response time:
                 min:                                  2.23ms
                 avg:                                 25.55ms
                 max:                               1696.98ms
                 approx.  95 percentile:              54.14ms

        Threads fairness:
            events (avg/stddev):           2348.1250/6.21
            execution time (avg/stddev):   59.9898/0.00

##主要註意這幾個參數 transactions: 18785 (313.05 per sec.)
read/write requests: 356980 (5948.98 per sec.)
other operations: 37574 (626.16 per sec.)

4)清除數據
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=sysbench --mysql-user=root --mysql-host=127.0.0.1 --mysql-password=123456 --max-time=60 --oltp-read-only=off --max-requests=0 --num-threads=8 cleanup

sysbench 壓測 詳解