1.5.1 sysbench使用介紹(待整理成自己的環境的結果)


轉載:http://www.unixfbi.com/522.html

一、sysbench 介紹

sysbench 是一個模塊化、支持多平台安裝運行,多線程的基准測試工具,sysbench,不僅用來測試數據庫的性能,也可以測試運行數據庫的服務器的性能。
sysbench,不僅用來測試數據庫的性能,也可以測試運行數據庫的服務器的性能。
oltp 測試主要是結合了 lua 腳本,不需要修改源碼,通過自定義 lua 腳本就可以實現不同業務類型的測試。

主要有以下幾種方式的測試:
cpu 基准測試
磁盤 I/O 基准測試
內存連續讀寫性能測試
測試互斥鎖性能
測試順序讀寫性能
數據庫性能 OLTP 基准測試

什么是 OLTP?
On-Line Transaction Processing 聯機事務處理過程(OLTP)
也稱為面向交易的處理過程,其基本特征是前台接收的用戶數據可以立即傳送到計算中心進行處理,並在很短的時間內給出處理結果,是對用戶操作快速響應的方式之一。

二、sysbench 安裝和部分參數介紹

1.安裝 sysbench

在 centos7 上

# curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench

  

2.sysbench 參數介紹

$ sysbench --help
Usage:
  sysbench [options]... [testname] [command]

Commands implemented by most tests: prepare run cleanup help
sysbench 壓測需要 3 個步驟:
prepare(准備數據) -> run(運行測試) -> cleanup(清理數據)
General options:
  --threads=N        #創建測試線程的數量,默認值為 1
  --events=N           #限制事件的總數量,0 表示不限制,默認值為 0
  --time=N                #限制總共執行多長時間,單位是秒,默認是 10
  --forced-shutdown=STRING      #超過--time 后,等待多長時間強制關閉,單位是秒,默認 off
  --thread-stack-size=SIZE        #每個線程的堆大小,默認是 64k
  --rate=N                        #平均事務率,0 表示不限制
  --report-interval=N            #定期報告統計數據的時間間隔,單位秒,默認為 0,表示不顯示中間報告。
  --report-checkpoints=[LIST,...]  #轉儲完整的統計信息並在指定的時間點重置所有計數器。默認為關閉
  --config-file=FILENAME         #可以把命令參數寫到一個文件中,指定這個文件
  --tx-rate=N                         #該參數棄用,改為 --rate [0]
  --max-requests=N               #該參數棄用,改為--events [0]
  --max-time=N                     #該參數棄用,改為 --time [0]
  --num-threads=N                #該參數棄用,改為 --threads [1]

mysql options:
  --mysql-host=[LIST,...]        #  MySQL 服務器地址 ,默認 localhost
  --mysql-port=[LIST,...]        # MySQL 服務器端口 ,默認 3306
  --mysql-socket=[LIST,...]     # MySQL socket 文件
  --mysql-user=STRING              MySQL user 默認 sbtest
  --mysql-password=STRING          MySQL password 默認為空
  --mysql-db=STRING                MySQL database name 默認 sbtest

  --mysql-compression[=on|off]     #是否使用壓縮,默認為 off

Compiled-in tests:
  fileio - File I/O test
  cpu - CPU performance test
  memory - Memory functions speed test
  threads - Threads subsystem performance test
  mutex - Mutex performance test

  

三、sysbench 使用說明

sysbench 壓測 MySQL 有三個步驟:prepare --> run --> cleanup
我們都是使用 sysbench 自帶的 lua 腳本來壓測 MySQL

1.壓測 MySQL

使用 oltp_read_write.lua 腳本壓測 MySQL
准備階段:

mysql -uroot -pllill2018 -e "create database sbtest;" -S /tmp/mysql3308.sock
sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=172.16.17.123 --mysql-port=3308  --mysql-user=root --mysql-password='llill2018' --mysql-socket=/tmp/mysql3308.sock --mysql-db=sbtest --db-driver=mysql --tables=20 --table-size=5000000  --threads=32  prepare

  

測試階段:

sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=172.16.17.123 --mysql-port=3308  --mysql-user=root --mysql-password='llill2018' --mysql-socket=/tmp/mysql3308.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=10000  --threads=32  --report-interval=10 --time=120 run

  

輸出結果如下:

sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2) Running the test with following options: Number of threads: 32 Report intermediate results every 10 second(s) Initializing random number generator from current time Initializing worker threads... Threads started! [ 10s ] thds: 32 tps: 266.21 qps: 5355.17 (r/w/o: 3753.19/1066.56/535.43) lat (ms,95%): 186.54 err/s: 0.00 reconn/s: 0.00 [ 20s ] thds: 32 tps: 279.40 qps: 5590.16 (r/w/o: 3914.18/1116.99/559.00) lat (ms,95%): 127.81 err/s: 0.00 reconn/s: 0.00 [ 30s ] thds: 32 tps: 273.60 qps: 5470.54 (r/w/o: 3829.26/1094.09/547.19) lat (ms,95%): 144.97 err/s: 0.00 reconn/s: 0.00 [ 40s ] thds: 32 tps: 258.20 qps: 5169.85 (r/w/o: 3620.43/1033.01/516.40) lat (ms,95%): 248.83 err/s: 0.00 reconn/s: 0.00 [ 50s ] thds: 32 tps: 281.80 qps: 5627.48 (r/w/o: 3936.89/1127.20/563.40) lat (ms,95%): 127.81 err/s: 0.00 reconn/s: 0.00 [ 60s ] thds: 32 tps: 279.50 qps: 5595.15 (r/w/o: 3917.53/1118.41/559.20) lat (ms,95%): 127.81 err/s: 0.00 reconn/s: 0.00 [ 70s ] thds: 32 tps: 278.30 qps: 5565.72 (r/w/o: 3895.85/1113.38/556.49) lat (ms,95%): 132.49 err/s: 0.00 reconn/s: 0.00 [ 80s ] thds: 32 tps: 262.40 qps: 5254.69 (r/w/o: 3679.89/1049.90/524.90) lat (ms,95%): 223.34 err/s: 0.00 reconn/s: 0.00 [ 90s ] thds: 32 tps: 277.50 qps: 5541.91 (r/w/o: 3877.80/1109.20/554.90) lat (ms,95%): 139.85 err/s: 0.00 reconn/s: 0.00 [ 100s ] thds: 32 tps: 276.20 qps: 5522.59 (r/w/o: 3864.99/1105.50/552.10) lat (ms,95%): 137.35 err/s: 0.00 reconn/s: 0.00 [ 110s ] thds: 32 tps: 282.40 qps: 5643.40 (r/w/o: 3949.30/1128.90/565.20) lat (ms,95%): 123.28 err/s: 0.00 reconn/s: 0.00 [ 120s ] thds: 32 tps: 275.30 qps: 5514.88 (r/w/o: 3862.76/1101.62/550.51) lat (ms,95%): 153.02 err/s: 0.00 reconn/s: 0.00 SQL statistics: queries performed: read: 461174 #讀總數 write: 131764 #寫總數(update、insert、delete 語句數量) other: 65882 #其他操作總數(SELECT、INSERT、UPDATE、DELETE 之外的操作,例如 COMMIT 等) total: 658820 #全部總數 transactions: 32941 (274.10 per sec.) #TPS,總事務數(每秒事務數) queries: 658820 (5482.05 per sec.) #QPS,讀寫總數(每秒讀寫次數) ignored errors: 0 (0.00 per sec.) #忽略的錯誤數 reconnects: 0 (0.00 per sec.) General statistics: total time: 120.1753s #--time 指定的壓測時間; total number of events: 32941 #總發生事件數,一般與 transactions 相同; Latency (ms): min: 11.51 #最小耗時 avg: 116.63 #平均耗時 max: 515.65 #最大耗時 95th percentile: 144.97 # 95%平均耗時 sum: 3841840.74 #總響應時間 Threads fairness: events (avg/stddev): 1029.4062/5.26 execution time (avg/stddev): 120.0575/0.04 

清除數據:

$ sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=192.168.199.229 --mysql-port=3306 --mysql-user=root --mysql-password='unixfbi' --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=10000 --threads=32 prepare 

2.壓測磁盤 IO

$ sysbench fileio help  
sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2) fileio options: --file-num=N #創建文件數量,默認 [128] --file-block-size=N #文件塊大小,默認[16384]16k --file-total-size=SIZE #創建文件的總大小 [2G] --file-test-mode=STRING 文件測試模式 {seqwr(順序寫), seqrewr(順序讀寫), seqrd(順序讀), rndrd(隨機讀), rndwr(隨機寫), rndrw(隨機讀寫} --file-io-mode=STRING 文件操作模式同步、異步或者 mmap,{sync,async,mmap}默認 [sync] --file-async-backlog=N 每個線程對應的異步操作數,默認 [128] --file-extra-flags=[LIST,...] 打開文件時使用的標志列表,有 {sync,dsync,direct} [] --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 同步方法的選擇 {fsync, fdatasync} 默認為[fsync] --file-merged-requests=N 盡可能合並此數量的 io 請求。0 表示不合並,默認為 0 --file-rw-ratio=N 測試時的讀寫比例,默認 [1.5] 

sysbench 的 file 測試需要也是 prepare、run 和 cleanup 三個階段。 prepare 是准備階段,產生需要的測試文件,run 是測試階段,cleanup 是清理測試產生的文件。
例如,創建 4 個文件,總共大小 2G 的測試:
准備階段:

# sysbench fileio --file-num=4 --file-total-size=2G prepare 

執行完成后會在當前目錄下生成 test_file.0-4 總共 4 個文件。每個文件大小為 512M,總共 2G 大小。
輸出結果:

sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2) 4 files, 524288Kb each, 2048Mb total Creating files for the test... Extra file open flags: (none) Creating file test_file.0 Creating file test_file.1 Creating file test_file.2 Creating file test_file.3 2147483648 bytes written in 12.91 seconds (158.59 MiB/sec). 

下面進行 180 秒測試,線程數 1 個,隨機數請求 100000000 次,隨機讀性能。
執行測試:

# sysbench fileio --time=180 --events=100000000 --threads=1 --file-num=4 --file-total-size=2G --file-io-mode=sync --file-test-mode=rndrd --file-block-size=16384 run 

輸出結果:

sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2) Running the test with following options: Number of threads: 1 Initializing random number generator from current time Extra file open flags: (none) 4 files, 512MiB each 2GiB total file size Block size 16KiB Number of IO requests: 100000000 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 Initializing worker threads... Threads started! File operations: reads/s: 153.62 #每秒讀次數 writes/s: 102.41 #每秒寫次數 fsyncs/s: 10.23 #每秒從內存向磁盤同步的次數 Throughput: #吞吐量 read, MiB/s: 2.40 written, MiB/s: 1.60 General statistics: total time: 180.0377s total number of events: 47942 Latency (ms): min: 0.00 avg: 3.75 max: 362.37 95th percentile: 10.09 sum: 179980.36 Threads fairness: events (avg/stddev): 47942.0000/0.00 execution time (avg/stddev): 179.9804/0.00 

IOPS = reads/s + writes/s
清除測試產生的文件:

# sysbench fileio  --file-num=4 --file-total-size=2G cleanup 

3.對 CPU 壓測

查看壓測 CPU 都有哪些參數:

$ sysbench cpu help
sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2) cpu options: --cpu-max-prime=N 產生最大素數限制,默認為[10000] 

例如:

# sysbench cpu --time=300 --threads=4 run sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2) Running the test with following options: Number of threads: 4 Initializing random number generator from current time Prime numbers limit: 10000 Initializing worker threads... Threads started! CPU speed: events per second: 4500.61 #每秒創建 events 數量 General statistics: total time: 300.0009s # --time 執行測試的時間 total number of events: 1350193 #總共創建的 events 數量 Latency (ms): min: 0.86 #最小執行時間 avg: 0.89 #平均執行時間 max: 14.88 #最大執行時間 95th percentile: 0.89 #95% events 執行時間 sum: 1199686.48 #總時間 Threads fairness: events (avg/stddev): 337548.2500/360.93 execution time (avg/stddev): 299.9216/0.01 

4.內存壓測

$ sysbench memory help
sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2) memory options: --memory-block-size=SIZE #內存塊大小,默認 [1K] --memory-total-size=SIZE 傳輸數據的總大小[100G] --memory-scope=STRING 內存訪問范圍,參數{global,local},默認為 [global] --memory-hugetlb[=on|off] 是否從 HugeTLB pool 分配內存,默認為 [off] --memory-oper=STRING 內存操作類型 {read, write, none} 默認為[write] --memory-access-mode=STRING 內存訪問模式 {seq,rnd} 默認為[seq] 

參考文檔:

https://github.com/akopytov/sysbench
http://www.cnblogs.com/Aiapple/p/5705415.html
http://www.ywnds.com/?p=10111
https://blog.csdn.net/zyzzxycj/article/details/79555660
https://blog.csdn.net/qq_42000667/article/details/79949291
https://baike.baidu.com/item/OLTP/5019563?fr=aladdin
https://www.jianshu.com/p/9823b4aa445a
https://baike.baidu.com/item/IOPS/3105194
http://www.cnblogs.com/muahao/p/6340343.html
http://www.cnblogs.com/muahao/p/6340343.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM