程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> MySQL 壓力性能測試(Mysqlslap)工具

MySQL 壓力性能測試(Mysqlslap)工具

編輯:MySQL綜合教程

本文章介紹一個mysql官方提供的Mysqlslap工具對mysql性能進行測試,有需要的朋友可以參考本文章來測試你的mysql性能與負載哦。

Mysqlslap是從5.1.4版開始的一個MySQL官方提供的壓力測試工具。通過模擬多個並發客戶端訪問MySQL來執行壓力測試,同時詳細的提供了“高負荷攻擊MySQL”的數據性能報告。並且能很好的對比多個存儲引擎在相同環境下的並發壓力性能差別。

它的使用語法如下:
shell>/usr/local/mysql/bin/mysqlslap [options]

常用參數【options】詳細介紹:
--concurrency代表並發數量,多個可以用逗號隔開。例如:--concurrency=50,200,500
--engines代表要測試的引擎,可以有多個,用分隔符隔開。例如:--engines=myisam,innodb,memory
--iterations代表要在不同並發環境下,各自運行測試多少次。
--auto-generate-sql 代表用mysqlslap工具自己生成的SQL腳本來測試並發壓力。
--auto-generate-sql-add-auto-increment 代表對生成的表自動添加auto_increment列,從5.1.18版本開始,
--auto-generate-sql-load-type 代表要測試的環境是讀操作還是寫操作還是兩者混合的(read,write,update,mixed)
--number-of-queries 代表總共要運行多少條查詢。
--debug-info 代表要額外輸出CPU以及內存的相關信息。
--number-int-cols 代表示例表中的INTEGER類型的屬性有幾個。
--number-char-cols代表示例表中的vachar類型的屬性有幾個。
--create-schema 代表自定義的測試庫名稱。
--query 代表自定義的測試SQL腳本。

說明:

測試的過程需要生成測試表,插入測試數據,這個mysqlslap可以自動生成,默認生成一個mysqlslap的schema,如果已經存在則先刪除。可以用-only-print來打印實際的測試過程,整個測試完成後不會在數據庫中留下痕跡。


實驗步驟:

練習一:
單線程測試。測試做了什麼。
>./bin/mysqlslap -a -uroot -p111111
多線程測試。使用--concurrency來模擬並發連接。
> ./bin/mysqlslap -a  -c 100 -uroot -p111111
迭代測試。用於需要多次執行測試得到平均值。
> ./bin/mysqlslap  -a -i 10 -uroot -p111111

練習二:
> ./bin/mysqlslap -auto-generate-sql-add-autoincrement -a -uroot -p111111
> ./bin/mysqlslap -a -auto-generate-sql-load-type=read -uroot -p111111
> ./bin/mysqlslap -a -auto-generate-secondary-indexes=3 -uroot -p111111
> ./bin/mysqlslap -a -auto-generate-sql-write-number=1000 -uroot -p111111

> ./bin/mysqlslap --create-schema world -q "select count(*) from City" -uroot -p111111
> ./bin/mysqlslap -a -e innodb -uroot -p111111
> ./bin/mysqlslap -a --number-of-queries=10 -uroot -p111111


練習三:
執行一次測試,分別50和100個並發,執行1000次總查詢:
> ./bin/mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --debug-info -uroot -p111111

50和100個並發分別得到一次測試結果(Benchmark),並發數越多,執行完所有查詢的時間越長。為了准確起見,可以多迭代測試幾次:
> ./bin/mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --debug-info -uroot -p111111

測試同時不同的存儲引擎的性能進行對比:
>./bin/mysqlslap -a --concurrency=50,100 --number-of-queries 1000 --iterations=5 --engine=myisam,innodb --debug-info -uroot -p111111

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved