標籤:死結 擴充 次數 find web應用 star request 基準測試 讀寫分離
一、基準測試簡介
1、什麼是基準測試
資料庫的基準測試是對資料庫的效能指標進行定量的、可複現的、可對比的測試。
基準測試與壓力測試
基準測試可以理解為針對系統的一種壓力測試。但基準測試不關心商務邏輯,更加簡單、直接、易於測試,資料可以由工具產生,不要求真實;而壓力測試一般考慮商務邏輯(如購物車業務),要求真實的資料。
2、基準測試的作用
對於多數Web應用,整個系統的瓶頸在於資料庫;原因很簡單:Web應用中的其他因素,例如網路頻寬、負載平衡節點、應用伺服器(包括CPU、記憶體、硬碟燈、串連數等)、緩衝,都很容易通過水平的擴充(俗稱加機器)來實現效能的提高。而對於MySQL,由於資料一致性的要求,無法通過增加機器來分散向資料庫寫資料帶來的壓力;雖然可以通過前置緩衝(Redis等)、讀寫分離、分庫分表來減輕壓力,但是與系統其它組件的水平擴充相比,受到了太多的限制。
而對資料庫的基準測試的作用,就是分析在當前的配置下(包括硬體設定、OS、資料庫設定等),資料庫的效能表現,從而找出MySQL的效能閾值,並根據實際系統的要求調整配置。
3、基準測試的指標
常見的資料庫指標包括:
- TPS/QPS:衡量輸送量。
- 回應時間:包括平均回應時間、最小回應時間、最大回應時間、時間百分比等,其中時間百分比參考意義較大,如前95%的請求的最大回應時間。。
- 並發量:同時處理的查詢請求的數量。
二、sysbench
1、sysbench安裝(ubuntu系統)
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh |sudo bashsudo apt -y install sysbench
2、oltp測試
find / -name oltp.luasysbench --test=tests/db/oltp.lua(根據具體位置填寫) --mysql-host=databasehost --mysql-port=3306 --mysql-user=user --mysql-password=password --mysql-db=databasename --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=10000000 --rand-init=on prepare/run/cleanup
參數詳解:
--test=tests/db/oltp.lua 指定測試的指令碼
--oltp-test-mode=complex 執行模式,包括simple、nontrx和complex,預設是complex,complex模式下測試最全面,會測試增刪改查,而且會使用事務。可以根據自己的需要選擇測試模式。
--oltp-tables-count=10 測試的表數量,根據實際情況選擇
--oltp-table-size 測試的表的大小
--rand-init=on 表示每個測試表都是用隨機資料來填充的
prepare、run和cleanup,顧名思義,prepare是為測試提前準備資料,run是執行正式的測試,cleanup是在測試完成後對資料庫進行清理。
3、測試結果
sysbench 0.5: multi-threaded system evaluation benchmark Running the test with following options:Number of threads: 256Report intermediate results every 10 second(s)Random number generator seed is 0 and will be ignored -- 線程啟動Threads started! -- 每10秒鐘報告一次測試結果,tps、每秒讀、每秒寫、99%以上的響應時間長度統計[ 10s] threads: 256, tps: 524.19, reads/s: 7697.05, writes/s: 2143.56, response time: 1879.46ms (99%)[ 20s] threads: 256, tps: 96.50, reads/s: 1351.01, writes/s: 373.30, response time: 9853.49ms (99%)[ 30s] threads: 256, tps: 235.50, reads/s: 3297.01, writes/s: 946.90, response time: 2150.47ms (99%)[ 40s] threads: 256, tps: 115.50, reads/s: 1617.00, writes/s: 491.40, response time: 4562.75ms (99%)[ 50s] threads: 256, tps: 262.10, reads/s: 3669.41, writes/s: 1016.10, response time: 2049.90ms (99%)[ 60s] threads: 256, tps: 121.50, reads/s: 1701.00, writes/s: 499.10, response time: 3666.03ms (99%)[ 70s] threads: 256, tps: 201.40, reads/s: 2735.10, writes/s: 769.50, response time: 3867.82ms (99%)[ 80s] threads: 256, tps: 204.70, reads/s: 2950.29, writes/s: 838.10, response time: 2724.99ms (99%)[ 90s] threads: 256, tps: 118.40, reads/s: 1657.61, writes/s: 490.00, response time: 3835.53ms (99%) OLTP test statistics: queries performed: read: 8823206 -- 讀總數 write: 2520916 -- 寫總數 other: 1260458 -- 其他動作總數(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等) total: 12604580 -- 全部總數 查詢總數及qps transactions: 630229 (174.94 per sec.) -- 總事務數(每秒事務數) 事務總數及tps deadlocks: 0 (0.00 per sec.) -- 發生死結總數 read/write requests: 11344122 (3148.86 per sec.) -- 讀寫總數(每秒讀寫次數) other operations: 1260458 (349.87 per sec.) -- 其他動作總數(每秒其他動作次數) General statistics: -- 一些統計結果 total time: 3602.6152s -- 總耗時 total number of events: 630229 -- 共發生多少事務數 total time taken by event execution: 921887.7227s -- 所有事務耗時相加(不考慮並行因素) response time: -- 回應時間 min: 6.52ms -- 最小耗時 avg: 1462.78ms -- 平均耗時 max: 9918.51ms -- 最長耗時 approx. 99 percentile: 3265.01ms -- 超過99%平均耗時 Threads fairness: -- 線程的穩定性 events (avg/stddev): 2461.8320/34.60 -- 事件(平均值/偏差) execution time (avg/stddev): 3601.1239/0.63 -- 執行時間(平均值/偏差)
4、清理測試資料
sysbench --test=tests/db/oltp.lua(根據具體位置填寫) --mysql-host=databasehost --mysql-port=3306 --mysql-user=user --mysql-password=password --mysql-db=databasename --oltp-test-mode=complex --oltp-tables-count=10 --oltp-table-size=10000000 --rand-init=on cleanup
mysql基準測試與sysbench工具