幾款經常使用壓測工具使用小結

ab

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

  • Failed requests:失敗的請求
  • Requests per second:也就是常說的QPS, 每秒查詢率,這是一個平均值
  • Time per request:完成一個請求所花費的時間
  • Transfer rate: 網絡傳輸速度。 對於大文件的請求測試,這個值很容易成爲系統瓶頸所在 要肯定該值是否是瓶頸,須要瞭解客戶端和被測服務器之間的網絡狀況,包括網絡帶寬和網卡速度等信息。
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

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

  • Requests/sec: QPS
  • Transfer/sec: 網絡傳輸速度
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

jmeter 是由java編寫的一個GUI測試工具,功能強大且結果多樣bash

安裝

安裝能夠去 apache jmeter 下載

使用

創建 Plan

創建Thread Group

創建好 Plan後就能夠創建 Thread Group 了, 創建方式

選中Plan 後, Edit > Add > Threads > Thread Group

Thread Group 能夠設置線程的一些參數,主要是 Number of Threads(users) 和 Loop Count

添加Listener

Listener主要生成一些結果報告,添加方式爲

選中Thread Group後 Edit > Add > Listener

能夠看到有不少結果報告,我平時主要用到如下幾個結果報告

  • View Results Tree
  • Aggregate Report
  • Graph Results
  • View Results Table

View Results Tree

這個報告會生成請求樹,點擊能夠查看每一個請求的信息

Aggregate Report

這個報告會生成請求的聚合統計信息, 主要參數就是QPS, 傳輸速度等

Graph Results

強大的圖形報告結果

圖形結果一些說明

  • No of Samples(樣本數): 表明向服務器發送的請求數目
  • Deviation(偏離):表明服務器相應時間變化的數據的分佈
  • Latest Sample(最新樣本): 表示服務器相應最後一個請求的時間
  • Throughtput(吞吐率):這裏是服務器每分鐘對數據的處理量
  • Average(平均值): 表示總運行的時間除以發送給服務器的請求數
  • Median(中間值): 表明有一半的服務器時間低於該值,而另外一半高於該值

根據圖形結果獲得的一些分析

  1. 吞吐率起步的時候比較低,隨着請求數量愈來愈多,吞吐率先增後減
  2. 偏離值還不錯,保持一個很平穩的狀態 若是偏離數量隨着請求數量愈來愈大, 說明服務器愈來愈不穩定
相關文章
相關標籤/搜索