天天看點

http性能測試工具wrk

wrk能用很少的線程壓出很大的并發量,原因它使用了一些作業系統特定的高性能I/O機制, 比如select, epoll, kqueue等。 其實它是複用redis的ae異步事件驅動架構。确切的說 ae 事件驅動架構并不是 redis 發明的,它來至于Tcl的解釋器 jim,這個小巧高效的架構,因為被 redis 采用而更多的被大家所熟知。

wrk GitHub 源碼: https://github.com/wg/wrk

wrk隻能運作于 Unix 類的系統上,linux下安裝

git clone https://github.com/wg/wrk
cd wrk-master
make
           

參數說明:

Usage: wrk <options> <url>                            
  Options:                                            
    -c, --connections <N>  Connections to keep open   
    -d, --duration    <T>  Duration of test           
    -t, --threads     <N>  Number of threads to use   
                                                      
    -s, --script      <S>  Load Lua script file       
    -H, --header      <H>  Add header to request      
        --latency          Print latency statistics   
        --timeout     <T>  Socket/request timeout     
    -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 -t30 -d30s http://www.baidu.com
30個線程,100個連接配接,執行30s,逾時時間預設1s
           

傳回:

Running 30s test @ http://www.baidu.com
  30 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    19.41ms   49.76ms   1.57s    95.20%
    Req/Sec   206.96     62.96   380.00     62.71%
  48899 requests in 30.05s, 726.27MB read
  Socket errors: connect 0, read 375176, write 0, timeout 0
Requests/sec:   1627.38
Transfer/sec:     24.17MB

           

其中:

說明
Latency 延遲時間
Req/Sec 單個線程每秒完成的請求數
avg stdev max 平均值 标準差 最大值
48899 requests in 30.05s, 726.27MB read 30秒内共有48899 個請求,總共讀取726.27MB資料
Socket errors: connect 0, read 375176, write 0, timeout 0 共0個連接配接錯誤,375176個讀錯誤,0個寫錯誤,0個逾時
Requests/sec 所有線程平均每秒完成請求數
Transfer/sec 所有線程平均每秒讀取資料量

除此之外,還可以操作lua腳本,豐富的設定header資訊等。

繼續閱讀