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

來源:互聯網
上載者:User

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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 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.