sysbench 基準測試簡介,sysbench基準測試

來源:互聯網
上載者:User

sysbench 基準測試簡介,sysbench基準測試

1.簡介

sysbench是一款開源的多線程效能測試工具,可以執行CPU/記憶體/線程/IO/資料庫等方面的效能測試。資料庫目前支援MySQL/Oracle/PostgreSQL。本文只是簡單示範一下幾種測試的用法,後續準備利用sysbench來對MySQL進行一系列的測試。具體的一些參數設定,需要根據不同的測試要求來進行調整。


2.安裝

#安裝yum包及配置環境變數yum -y install bzr libtool wget http://imysql.com/wp-content/uploads/2014/09/sysbench-0.4.12-1.1.tgzcat 'export LD_LIBRARY_PATH=/db/mysql/lib' >> /etc/profilesource /etc/profile# 安裝sysbenchmkdir -p /Data/apps/sysbenchmkdir -p /Data/apps/sysbench/logtar -zxvf sysbench-0.4.12-1.1.tgzcd sysbench-0.4.12-1.1./autogen.sh./configure --prefix=/Data/apps/sysbench --with-mysql-includes=/Data/apps/mysql/include --with-mysql-libs=/Data/apps/mysql/libmake && make installcp /Data/apps/sysbench/bin/sysbench /usr/local/bin/# /Data/package/sysbench-0.4.12-1.1為安裝包目錄cp -a /Data/package/sysbench-0.4.12-1.1/sysbench/tests /Data/apps/sysbench/


3.測試

  3.1 Mysql資料庫測試

mysql > create database sbtest;
sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password='' --test=/Data/apps/sysbench/tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=100000 --rand-init=on prepare

# --test=tests/db/oltp.lua 表示調用 tests/db/oltp.lua 指令碼進行 oltp 模式測試
# --oltp_tables_count=10 表示會產生 10 個測試表
# --oltp-table-size=100000 表示每個測試表資料行數
# --rand-init=on 表示每個測試表都是用隨機資料來填充的


sysbench --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password='' --test=/Data/apps/sysbench/tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=10000000 --num-threads=8 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=120 --max-requests=0 --percentile=99 run >> /Data/apps/sysbench/log/sysbench_oltp.log


# --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%裡取最大值


==========================測試結果解讀如下==========================sysbench 0.5:  multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 8Report intermediate results every 10 second(s)Random number generator seed is 0 and will be ignoredThreads started![  10s] threads: 8, tps: 26.60, reads/s: 410.22, writes/s: 115.11, response time: 1050.29ms (99%)[  20s] threads: 8, tps: 32.40, reads/s: 462.00, writes/s: 131.60, response time: 699.68ms (99%)[  30s] threads: 8, tps: 33.00, reads/s: 467.60, writes/s: 133.20, response time: 496.50ms (99%)[  40s] threads: 8, tps: 30.80, reads/s: 441.00, writes/s: 125.30, response time: 617.02ms (99%)[  50s] threads: 8, tps: 35.80, reads/s: 504.00, writes/s: 143.80, response time: 526.03ms (99%)[  60s] threads: 8, tps: 33.20, reads/s: 468.50, writes/s: 133.30, response time: 774.87ms (99%)                                        .........[3540s] threads: 8, tps: 41.90, reads/s: 602.00, writes/s: 170.90, response time: 483.88ms (99%)[3550s] threads: 8, tps: 43.40, reads/s: 616.00, writes/s: 175.40, response time: 383.69ms (99%)[3560s] threads: 8, tps: 38.00, reads/s: 543.20, writes/s: 154.40, response time: 475.41ms (99%)[3570s] threads: 8, tps: 39.60, reads/s: 560.00, writes/s: 159.60, response time: 425.82ms (99%)[3580s] threads: 8, tps: 42.10, reads/s: 600.60, writes/s: 170.80, response time: 384.04ms (99%)[3590s] threads: 8, tps: 38.10, reads/s: 547.40, writes/s: 155.40, response time: 542.17ms (99%)[3600s] threads: 8, tps: 40.40, reads/s: 574.00, writes/s: 163.40, response time: 459.05ms (99%)OLTP test statistics:    queries performed:        read:                            2068584    -- 讀總數        write:                           588759      -- 寫總數        other:                           293247-- 其他動作總數(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)        total:                           2950590-- 全部總數    transactions:                        145491 (40.41 per sec.)-- 總事務數(每秒事務數)    deadlocks:                           2265   (0.63 per sec.)-- 發生死結總數    read/write requests:                 2657343 (738.12 per sec.)-- 讀寫總數(每秒讀寫次數)    other operations:                    293247 (81.45 per sec.)-- 其他動作總數(每秒其他動作次數)General statistics:    total time:                          3600.1452s-- 總耗時    total number of events:              145491-- 共發生多少事務數    total time taken by event execution: 28800.5977s-- 所有事務耗時相加(不考慮並行因素)    response time:         min:                                 49.84ms-- 最小耗時         avg:                                197.95ms-- 平均耗時         max:                               1355.40ms-- 最長耗時         approx.  99 percentile:             433.54ms-- 超過99%平均耗時Threads fairness:    events (avg/stddev):           18186.3750/63.14    execution time (avg/stddev):   3600.0747/0.04

 3.2 CPU測試

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

shell> sysbench --test=cpu --cpu-max-prime=2000 runsysbench 0.5:  multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 1Random number generator seed is 0 and will be ignoredPrimer numbers limit: 2000Threads started!Test execution summary:    total time:                          2.2452s    total number of events:              10000    total time taken by event execution: 2.2347s    per-request statistics:         min:                                  0.20ms         avg:                                  0.22ms         max:                                  3.35ms         approx.  95 percentile:               0.27msThreads fairness:    events (avg/stddev):           10000.0000/0.00    execution time (avg/stddev):   2.2347/0.00補充:查看CPU資訊方法查看物理cpu個數 grep "physical id" /proc/cpuinfo | sort -u | wc -l查看核心數量 grep "core id" /proc/cpuinfo | sort -u | wc -l查看線程數量 grep "processor" /proc/cpuinfo | sort -u | wc -l在sysbench的測試中,--num-threads取值為"線程數量"即可



  3.3 線程(thread)測試

   測試線程調度器的效能。對於高負載情況下測試線程調度器的行為非常有用

shell> sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 runsysbench 0.5:  multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 64Random number generator seed is 0 and will be ignoredThreads started!Test execution summary:    total time:                          1.9581s    total number of events:              10000    total time taken by event execution: 124.8938s    per-request statistics:         min:                                  0.05ms         avg:                                 12.49ms         max:                                151.15ms         approx.  95 percentile:              50.83msThreads fairness:    events (avg/stddev):           156.2500/14.48    execution time (avg/stddev):   1.9515/0.00

  3.4 檔案IO效能測試
  • 產生需要的測試檔案,檔案總大小5G,16個並發線程。執行完後會在目前的目錄下產生一堆小檔案。
shell> sysbench --test=fileio --num-threads=16 --file-total-size=5G prepare
  • 執行測試,指定隨機讀寫入模式

指定讀寫入模式:

  1. seqwr 順序寫入
  2. seqrewr 順序重寫
  3. seqrd 順序讀取
  4. rndrd 隨機讀取
  5. rndwr 隨機寫入
  6. rndrw 混合隨機讀/寫
shell> sysbench --test=fileio --num-threads=16 --init-rng=on --file-total-size=5G --file-test-mode=rndrw runsysbench 0.5:  multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 16Random number generator seed is 0 and will be ignoredThreads started!Operations performed:  5999 reads, 4001 writes, 12800 Other = 22800 TotalRead 93.734Mb  Written 62.516Mb  Total transferred 156.25Mb  (9.2561Mb/sec)   ##輸送量  592.39 Requests/sec executedTest execution summary:    total time:                          16.8808s    total number of events:              10000    total time taken by event execution: 176.1816s    per-request statistics:         min:                                  0.01ms         avg:                                 17.62ms         max:                                416.73ms         approx.  95 percentile:             104.82msThreads fairness:    events (avg/stddev):           625.0000/62.39    execution time (avg/stddev):   11.0114/0.67
  • 清除測試檔案
shell> sysbench --test=fileio --num-threads=16 --file-total-size=5G cleanup
    3.5 互斥鎖(Mutex)測試

   測試互斥鎖的效能,方式是類比所有線程在同一時刻並發運行,並都短暫請求互斥鎖。

shell> sysbench --test=mutex --num-threads=16 --mutex-num=1024 --mutex-locks=10000 --mutex-loops=5000 runsysbench 0.5:  multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 16Random number generator seed is 0 and will be ignoredThreads started!Test execution summary:    total time:                          0.0135s    total number of events:              16    total time taken by event execution: 0.0411s    per-request statistics:         min:                                  0.70ms         avg:                                  2.57ms         max:                                  9.19ms         approx.  95 percentile:               9.16msThreads fairness:    events (avg/stddev):           1.0000/0.00    execution time (avg/stddev):   0.0026/0.00
    3.6 記憶體測試

   記憶體測試測試了記憶體的連續讀寫效能。

shell> sysbench --test=memory --num-threads=16 --memory-block-size=8192 --memory-total-size=1G runsysbench 0.5:  multi-threaded system evaluation benchmarkRunning the test with following options:Number of threads: 16Random number generator seed is 0 and will be ignoredThreads started!Operations performed: 131072 (381158.38 ops/sec)1024.00 MB transferred (2977.80 MB/sec)       ##輸送量Test execution summary:    total time:                          0.3439s    total number of events:              131072    total time taken by event execution: 3.9915s    per-request statistics:         min:                                  0.00ms         avg:                                  0.03ms         max:                                 51.02ms         approx.  95 percentile:               0.00ms  ##大約95%的時間分布Threads fairness:    events (avg/stddev):           8192.0000/1166.77    execution time (avg/stddev):   0.2495/0.02


相關參考:

  《sysbench安裝、使用、結果解讀》

  《sysbench 0.5 基準測試》 



相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.