mysqlslap是一個mysql官方提供的壓力測試工具,經過模擬多個併發客戶端訪問mysql來執行測試,使用起來很是的簡單。經過mysqlslap –help能夠得到可用的選項。
下面咱們就來看看一些比較重要的參數:
–defaults-file,配置文件存放位置
–create-schema,測試的schema,MySQL中schema也就是database
–concurrency,併發數
–engines,測試引擎,能夠有多個,用分隔符隔開。
–iterations,迭代的實驗次數
–socket,socket,文件位置
–debug-info,打印內存和CPU的信息
–only-print,只打印測試語句而不實際執行
–auto-generate-sql,自動產生測試SQL
–auto-generate-sql-load-type,測試SQL的類型。類型有mixed,update,write,key,read。
–number-of-queries,執行的SQL總數量
–number-int-cols,表內int列的數量
–number-char-cols,表內char列的數量
–query=name,使用自定義腳本執行測試,例如能夠調用自定義的一個存儲過程或者sql語句來執行測試。
測試例子以下:
[root@localhost ~]# /usr/local/mysql/bin/mysqlslap –defaults-file=/etc/my.cnf –concurrency=200 –iterations=1 –number-int-cols=1 –auto-generate-sql –auto-generate-sql-load-type=write –engine=myisam,innodb –number-of-queries=200 -S/tmp/mysql.sock –debug-info -uroot -p123
Benchmark
Running for engine myisam
Average number of seconds to run all queries: 0.087 seconds
Minimum number of seconds to run all queries: 0.087 seconds
Maximum number of seconds to run all queries: 0.087 seconds
Number of clients running queries: 200
Average number of queries per client: 1
Benchmark
Running for engine innodb
Average number of seconds to run all queries: 0.551 seconds
Minimum number of seconds to run all queries: 0.551 seconds
Maximum number of seconds to run all queries: 0.551 seconds
Number of clients running queries: 200
Average number of queries per client: 1
User time 0.03, System time 0.05
Maximum resident set size 0, Integral resident set size 0
Non-physical pagefaults 2826, Physical pagefaults 0, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 3340, Involuntary context switches 96
對於INNODB引擎,200個客戶端同時運行這些SQL語句平均要花0.551秒。相應的MYISAM爲0.087秒,測試結果也很簡明,就很少少說了。
指定數據庫的測試:
–create-schema,指定數據庫名稱
–query, 指定SQL語句,能夠定位到某個包含SQL的文件
[root@localhost ~]# /usr/local/mysql/bin/mysqlslap –defaults-file=/etc/my.cnf –concurrency=50 –iterations=1 –create-schema=test –query=/root/test.sql -S/tmp/mysql.sock -uroot -p123
Benchmark
Average number of seconds to run all queries: 0.021 seconds
Minimum number of seconds to run all queries: 0.021 seconds
Maximum number of seconds to run all queries: 0.021 seconds
Number of clients running queries: 50
Average number of queries per client: 1mysql