ab是apache自帶的壓力測試工具,使用起來很是方便.java
若是安裝了apache, 那麼ab已經安裝好了,若是不想安裝apache的話,能夠經過如下方式安裝abmysql
# ubuntu
sudo apt-get install apache2-utils
# centos
yum -y install httpd-tools
複製代碼
在壓測前,須要關注幾個選項,經過 ab -help
查看git
Options are:
-n requests 要執行的請求次數
-c concurrency 併發數量
-s timeout 響應時間
複製代碼
執行github
ab -n 1000 -c 100 -s 1 http://127.0.0.1:1080/event?config_name=mysql_config
# 總共100個併發執行1000此請求,超時時間爲1s
複製代碼
在執行上述測試命令後,獲得以下結果,主要關注如下幾個指標:sql
Server Software:
Server Hostname: 127.0.0.1
Server Port: 1080
Document Path: /event?config_name=mysql_config
Document Length: 0 bytes
Concurrency Level: 100
Time taken for tests: 0.137 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 75000 bytes
HTML transferred: 0 bytes
Requests per second: 7275.11 [#/sec] (mean)
Time per request: 13.745 [ms] (mean)
Time per request: 0.137 [ms] (mean, across all concurrent requests)
Transfer rate: 532.84 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.0 1 5
Processing: 1 12 5.9 11 30
Waiting: 1 11 5.9 11 29
Total: 1 13 6.1 13 30
Percentage of the requests served within a certain time (ms)
50% 13
66% 15
75% 17
80% 18
90% 22
95% 25
98% 28
99% 29
100% 30 (longest request)
複製代碼
wrk 是一款c語言開發的現代的http性能基準測試工具,使用簡單,功能強大。shell
安裝能夠從github上下載源碼編譯安裝 wrk github地址apache
wrk的命令選項並很少,很容易使用ubuntu
Usage: wrk <options> <url>
Options:
-c, --connections <N> 創建的鏈接
-d, --duration <T> 執行測試時間
-t, --threads <N> 線程數量
-s, --script <S> 使用lua腳本(很是強大的功能,有興趣能夠深刻研究)
-H, --header <H> 爲每個HTTP請求添加HTTP頭
--latency 在壓測結束後,打印延遲統計信息
--timeout <T> 超時時間
-v, --version Print version details
Numeric arguments may include a SI unit (1k, 1M, 1G)
Time arguments may include a time unit (2s, 2m, 2h)
複製代碼
wrk -c100 -t10 -d30s http://127.0.0.1:1080/event?config_name=mysql_config
# 10個線程100個鏈接壓測30s
複製代碼
wrk生成的結果報告比較簡潔,主要關注的點和ab差很少centos
Running 30s test @ http://127.0.0.1:1080/event?config_name=mysql_config
10 threads and 100 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 21.02ms 92.04ms 1.05s 97.79%
Req/Sec 1.22k 229.72 2.38k 75.47%
365483 requests in 30.07s, 26.14MB read
Requests/sec: 12152.63
Transfer/sec: 0.87MB
複製代碼
jmeter 是由java編寫的一個GUI測試工具,功能強大且結果多樣bash
安裝能夠去 apache jmeter 下載
創建好 Plan後就能夠創建 Thread Group 了, 創建方式
選中Plan 後, Edit > Add > Threads > Thread Group
Thread Group 能夠設置線程的一些參數,主要是 Number of Threads(users) 和 Loop Count
Listener主要生成一些結果報告,添加方式爲
選中Thread Group後 Edit > Add > Listener
能夠看到有不少結果報告,我平時主要用到如下幾個結果報告
這個報告會生成請求樹,點擊能夠查看每一個請求的信息
這個報告會生成請求的聚合統計信息, 主要參數就是QPS, 傳輸速度等
強大的圖形報告結果
圖形結果一些說明
根據圖形結果獲得的一些分析