使用Sniper來測試Http站點

Sniper是一個功能強大、高性能的HTTP負載工具,採用Golang編寫。利用協程併發優點,實現海量併發、超低內存佔用、豐富圖表展現。是測試、分析、優化服務端性能的絕佳助手! html

功能 git

  • GET / POST
  • keep-alive模式
  • https
  • 圖表展現結果
  • 測試多個目標
  • 支持大文件負載
  • 跨平臺,支持Linux,FreeBSD,Darwin
  • 內存佔用低於Apache Benchmark(ab)等主流負載工具
  • 執行速度接近ab,高併發時超過ab
  • 支持10k以上併發
  • 支持超大文件測試

Alt text

使用說明

1. 安裝Golang

請參考astaxie的開源Golang書籍《Go Web 編程》一書,Go安裝一節。 github

2. 安裝Sniper

$ go get github.com/lubia/sniper
$ go install github.com/lubia/sniper
$ cp src/github.com/lubia/sniper/.sniperc ~

3. 參數說明

示例

GET golang

$sniper -c 10 -n 100 http://www.google.com

POST web

$sniper -c 10 -n 100 -p postData.txt http://www.google.com

參數

命令行參數
Usage: 
   sniper [options] http[s]://hostname[:port][/path]                 http或https,支持域名或ip
   sniper [options] -f urls.txt                                      測試多個服務端地址,文件格式:每一個url一行
Options: 
   -c, --concurrent     concurrent users, default is 1.              併發數(默認爲1)
   -n, --requests       number of requests to perform.               總請求數
   -r, --repetitions    number of times to run the test.             重複次數(n=c*r)
   -t, --time           testing time, 30 mean 30 seconds.            測試時間(單位秒)
   -R, --sniperc        specify an sniperc file to get config        配置文件地址(默認爲$HOME/.sniperc)
                        (default is $HOME/.sniperc).               
   -f, --urlfile        select a specific URLS file.                 多個測試目標的url文件
   -p, --post           select a specific file to POST.              POST模式
   -T, --content-type   set Content-Type in request                  POST的數據類型(默認爲text/plain)
                        (default is text/plain).
   -V, --Version        print the version number.                    打印sniper版本號
   -h, --help           print this section.                          輸出幫助信息
   -C, --config         show the current config.                     輸出當前配置文件的配置
   -s, --plot           plot detail transactions' info               是否輸出html展現測試結果(默認爲true) 
                        (true | false,default set true,              (注意:採用-t指定測試時間時,不會輸出html)
                        notice: set -t will not plot anyhow).
配置文件參數
說明:默認從$HOME/.sniperc讀取配置文件,配置文件設置與命令行設置互爲補充
可經過命令行 -R 指定配置文件地址,-C 查看默認配置。
[protocol]
version = HTTP/1.1                            HTTP協議版本,1.1或1.0
#connection = keep-alive                      connection模式,# 符號做爲註釋
connection = close
accept-encoding = gzip                        
user-agent = golang & sniper                  

[header]
#cookie = SSID=Abh_TYcDc6YSQh-GB              自定義消息頭,等號鏈接鍵值對

[process]
timeout = 30                                  socket超時時間 
failures = 64                                 最大失敗次數,socket錯誤超過此值則程序退出

[Authenticate]
login = jeff:supersecret                      HTTP基本認證

[ssl]
ssl-cert = /root/cert.pem                     ssl-cert文件地址
ssl-key = /root/key.pem                       ssl-key文件地址
ssl-timeout = 30                              https超時
結果輸出

圖表輸出到當前目錄下plot.html shell

Transactions:                   1000 hits           總請求數
Availability:                   100.00 %            完成百分百    
Elapsed time:                   0.15 secs           sniper執行時間
Document length:               1162 Bytes           服務端單個返回長度
TotalTransfer:                  1.11 MB             總傳輸數據量
Transaction rate:            6625.60 trans/sec      每秒事務數 
Throughput:                     7.34 MB/sec         吞吐量 
Successful:                     1000 hits           成功次數(結果碼不爲200也是成功)
Failed:                           0 hits            失敗次數(socket等鏈路錯誤) 
TransactionTime:               1.495 ms(mean)       單個請求總耗時(平均)
ConnectionTime:                0.596 ms(mean)       鏈路創建耗時(平均,tcp三次握手)
ProcessTime:                   0.900 ms(mean)       服務端執行時間+傳輸時間(TransactionTime = ConnectionTime + ProcessTime)
StateCode:                    1000(code 200)        結果碼爲200的數量

測試案例: 編程

[root@localhost bin]# pwd
/usr/local/go/sniper/bin
[root@localhost bin]# ./sniper -c 10 -n 100 http://202.200.82.60/WebGoat/attack
相關文章
相關標籤/搜索