Sniper是一个功能强大、高性能的HTTP负载工具,采用Golang编写。利用协程并发优点,实现海量并发、超低内存占用、丰富图表展现。是测试、分析、优化服务端性能的绝佳助手! html
功能 git
请参考astaxie的开源Golang书籍《Go Web 编程》一书,Go安装一节。 github
$ go get github.com/lubia/sniper $ go install github.com/lubia/sniper $ cp src/github.com/lubia/sniper/.sniperc ~
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