sysbench使用筆記

項目地址 https://launchpad.net/sysbench (目前已遷移至https://github.com/akopytov/sysbench)html


下載源碼包,解壓,

執行autogen.sh, 可能會提示缺乏automake 和libtoolize  ,自行yum install automake  libtool 便可mysql

以後./configure git

mysql 自行編譯安裝的可能會提示 configure: error: mysql_config executable not found 須要添加以下參數github

--with-mysql-includes=/usr/local/mysql/include \
--with-mysql-libs=/usr/local/mysql/lib

以後make 便可...  make完以後會在源碼目錄的sysbench下生成一個sysbench二進制文件sql

直接執行便可看到相關的參數信息..數據庫

Q:  mysql 如果自行編譯安裝的話,執行sysbench可能會遇到錯誤提示緩存

error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file:
No such file or directory
服務器

A:export LD_LIBRARY_PATH=/usr/local/mysql/lib

  • CPU 性能測試 / CPU performance test

    CPU測試使用64位整數,測試計算素數直到某個最大值所須要的時間

    ./sysbench --test=cpu  --num-threads=2  --cpu-max-prime=20000   run 併發

    sysbench 0.5:  multi-threaded system evaluation benchmarkapp

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


    Prime numbers limit: 20000

    Threads started!


    General statistics:
        total time:                          29.3082s
        total number of events:              10000
        total time taken by event execution: 58.5971s
        response time:
             min:                                  2.86ms
             avg:                                  5.86ms
             max:                                107.92ms
             approx.  95 percentile:               3.10ms

    Threads fairness:
        events (avg/stddev):           5000.0000/7.00
        execution time (avg/stddev):   29.2985/0.00

     

    cpu測試主要是進行素數的加法運算,在上面的例子中,指定了最大的素數爲 20000,本身能夠根據機器cpu的性能來適當調整數值。

    其中 --num-threads The total number of worker threads to create

    默認爲1, 通常設置爲CPU核數(線程數)便可,設置過大也不會對性能帶來影響


    • cpu options:
        --cpu-max-prime=N      upper limit for primes generator [10000]

  • 線程(thread)測試  / Threads subsystem performance test

    測試線程調度器的性能。對於高負載狀況下測試線程調度器的行爲很是有用。

    多核性能,線程調度 線程併發執行,循環響應信號量花費的時間

    ./sysbench --test=threads --num-threads=2 run  

    sysbench 0.5:  multi-threaded system evaluation benchmark

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


    Threads started!


    General statistics:
        total time:                          3.9964s
        total number of events:              10000
        total time taken by event execution: 7.9829s
        response time:
             min:                                  0.76ms
             avg:                                  0.80ms
             max:                                  2.22ms
             approx.  95 percentile:               0.82ms

    Threads fairness:
        events (avg/stddev):           5000.0000/0.00
        execution time (avg/stddev):   3.9914/0.00

    threads options:
      --thread-yields=N      number of yields to do per request [1000]
      --thread-locks=N       number of locks per thread [8]

  • 互斥鎖(mutex) /Mutex performance test

    併發線程同時申請互斥鎖循環必定次數花費的時間 測試互斥鎖的性能

    方式是模擬全部線程在同一時刻併發運行,並都短暫請求互斥鎖。

    ./sysbench --test=mutex --num-threads=2 --mutex-locks=1000000 run

    sysbench 0.5:  multi-threaded system evaluation benchmark

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


    Threads started!


    General statistics:
        total time:                          0.0874s
        total number of events:              2
        total time taken by event execution: 0.1312s
        response time:
             min:                                 43.82ms
             avg:                                 65.60ms
             max:                                 87.37ms
             approx.  95 percentile:              87.38ms

    Threads fairness:
        events (avg/stddev):           1.0000/0.00
        execution time (avg/stddev):   0.0656/0.02

    mutex options:
      --mutex-num=N        total size of mutex array [4096]
      --mutex-locks=N      number of mutex locks to do per thread [50000]
      --mutex-loops=N      number of empty loops to do inside mutex lock [10000]

  • 內存測試 / Memory functions speed test

    以不一樣塊大小傳輸必定數量的數據,測試內存讀寫性能

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

    sysbench 0.5:  multi-threaded system evaluation benchmark

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


    Threads started!

    Operations performed: 262144 (743947.40 ops/sec)

    2048.00 MB transferred (5812.09 MB/sec)


    General statistics:
        total time:                          0.3524s
        total number of events:              262144
        total time taken by event execution: 0.4492s
        response time:
             min:                                  0.00ms
             avg:                                  0.00ms
             max:                                100.97ms
             approx.  95 percentile:               0.00ms

    Threads fairness:
        events (avg/stddev):           131072.0000/20186.00
        execution time (avg/stddev):   0.2246/0.02

    memory options:
      --memory-block-size=SIZE    size of memory block for test [1K]
      --memory-total-size=SIZE    total size of data to transfer [100G]
      --memory-scope=STRING       memory access scope {global,local} [global]
      --memory-hugetlb=[on|off]   allocate memory from HugeTLB pool [off]
      --memory-oper=STRING        type of memory operations {read, write, none} [write]
      --memory-access-mode=STRING memory access mode {seq,rnd} [seq]

  • 文件IO基準測試 / File I/O test

    測試系統在不一樣IO負載下的IOPS性能

    準備工做(建立測試文件)

    sysbench --test=fileio --num-threads=2 --file-total-size=4G --file-test-mode=rndrw prepare

    測試

    sysbench --test=fileio --num-threads=2 --file-total-size=4G --file-test-mode=rndrw run

    清理測試文件

    sysbench --test=fileio --num-threads=2 --file-total-size=4G --file-test-mode=rndrw cleanup

    ./sysbench --test=fileio --num-threads=2 --file-total-size=4G --file-test-mode=rndrw run
    sysbench 0.5:  multi-threaded system evaluation benchmark

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


    Extra file open flags: 0
    128 files, 32Mb each
    4Gb total file size
    Block size 16Kb
    Number of IO requests: 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!

    Operations performed:  5999 reads, 4001 writes, 12800 Other = 22800 Total
    Read 93.734Mb  Written 62.516Mb  Total transferred 156.25Mb  (9.1877Mb/sec)
      588.01 Requests/sec executed

    General statistics:
        total time:                          17.0064s
        total number of events:              10000
        total time taken by event execution: 0.6489s
        response time:
             min:                                  0.00ms
             avg:                                  0.06ms
             max:                                 97.59ms
             approx.  95 percentile:               0.03ms

    Threads fairness:
        events (avg/stddev):           5000.0000/618.00
        execution time (avg/stddev):   0.3245/0.06

    fileio options:
      --file-num=N                  number of files to create [128]
      --file-block-size=N           block size to use in all IO operations [16384]
      --file-total-size=SIZE        total size of files to create [2G]
      --file-test-mode=STRING       test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
      seqwr 順序寫入 seqrewr 順序重寫 seqrd 順序讀取 rndrd 隨機讀取 rndwr 隨機寫入 rndrw 混合隨機讀/寫

      --file-io-mode=STRING         file operations mode {sync,async,mmap} [sync]
      --file-extra-flags=STRING     additional flags to use on opening files {sync,dsync,direct} []
      --file-fsync-freq=N           do fsync() after this number of requests (0 - don't use fsync()) [100]
      --file-fsync-all=[on|off]     do fsync() after each write operation [off]
      --file-fsync-end=[on|off]     do fsync() at the end of test [on]
      --file-fsync-mode=STRING      which method to use for synchronization {fsync, fdatasync} [fsync]
      --file-merged-requests=N      merge at most this number of IO requests if possible (0 - don't merge) [0]
      --file-rw-ratio=N             reads/writes ratio for combined test [1.5]

    引用網上的一段總結

  • 性能測試【找範圍內最大素數{時間越短越好}】

  • 線程調度【線程併發執行,循環響應信號量花費的時間{越少越好}】

  • 互斥鎖【併發線程同時申請互斥鎖循環必定次數花費的時間{越少越好}】

  • 內存【以不一樣塊大小傳輸必定數量的數據吞吐量大小{越大越好}】

  • IO【不一樣場景下IOPS{越大越好}】

     

     

     

     

    • MySQL數據庫測試

    sysbench 0.5經過一系列LUA腳原本替換以前的oltp,來模擬更接近真實的基準測試環境。這些測試腳本包含:insert.lua、oltp.lua、 parallel_prepare.lua、select_random_points.lua、update_index.lua、 delete.lua oltp_simple.lua、select.lua、select_random_ranges.lua、 update_non_index.lua,腳本使用方式基本相似。

    sysbench 0.5默認使用sbtest庫,可是須要本身手工先建立好,也可使用--mysql-db指定,其餘非默認項指定選項:

    1. -mysql-host
    2. -mysql-port
    3. -mysql-socket
    4. -mysql-user
    5. -mysql-password
    6. -mysql-db
    7. -mysql-ssl
    • prepare
      生成表並插入數據,可以使用parallel_prepare.lua腳原本並行準備數據。
    1. –db-driver 服務器類型 mysql | drizzle,默認爲mysql
    2. –mysql-table-engine 表存數引擎
    3. –myisam-max-rows MyISAM表MAX_ROWS選項(用於大表)
    4. –oltp-tables-count 生成表數量[sbtest一、sbtest2...]
    5. –oltp-table-size 生成表的行數
    6. –oltp-secondary ID列生成二級索引而不是主鍵
    7. –oltp-auto-inc 設置ID列是否自增 on | off,默認爲on

       注意  -oltp-tables-count 和 –oltp-table-size之類的參數 ,sysbench 參數寫錯了不會提示出錯,會按原參數默認值執行

    ./sysbench --test=tests/db/oltp.lua --mysql-user=sysbench --oltp-tables-count=10 --oltp-table-size=100000 --mysql-password=sysbench --mysql-host=192.168.200.2 --report-interval=1 --num-threads=16 run
    sysbench 0.5:  multi-threaded system evaluation benchmark

    Running the test with following options:
    Number of threads: 16
    Report intermediate results every 1 second(s)
    Random number generator seed is 0 and will be ignored


    Threads started!

    OLTP test statistics:
        queries performed:
            read:                            140000
            write:                           40000
            other:                           20000
            total:                           200000
        transactions:                        10000  (375.41 per sec.)##(這就是你們評測的TPS,即每秒處理的事務數)
        read/write requests:                 180000 (6757.36 per sec.)###(每秒讀寫次數)
        other operations:                    20000  (750.82 per sec.)
        ignored errors:                      0      (0.00 per sec.)
        reconnects:                          0      (0.00 per sec.)

     
       

    General statistics:
        total time:                          26.6376s
        total number of events:              10000
        total time taken by event execution: 425.6943s
        response time:
             min:                                 11.18ms
             avg:                                 42.57ms
             max:                                194.44ms
             approx.  95 percentile:              78.24ms

    Threads fairness:
        events (avg/stddev):           625.0000/6.95
        execution time (avg/stddev):   26.6059/0.01


        execution time (avg/stddev):   46.9500/0.01

    如何避免壓測時受到緩存的影響  有2點建議
    a、填充測試數據比物理內存還要大,至少超過 innodb_buffer_pool_size 值,不能將數據所有裝載到內存中,除非你的本意就想測試全內存狀態下的MySQL性能。
    b、每輪測試完成後,都重啓mysqld實例,而且用下面的方法刪除系統cache,釋放swap(若是用到了swap的話),甚至能夠重啓整個OS。

    [root@imysql.com]# sync  -- 將髒數據刷新到磁盤
    [root@imysql.com]# echo 3 > /proc/sys/vm/drop_caches  -- 清除OS Cache
    [root@imysql.com]# swapoff -a && swapon -a
  • 相關文章
    相關標籤/搜索