安装命令
brew install siege
查看配置路径
siege -C
参数说明
siege --help
Usage: siege [options]
siege [options] URL
siege -g URL
Options:
-V, --version VERSION, prints the version number.
-h, --help HELP, prints this section.
-C, --config CONFIGURATION, show the current config.
#在屏幕上打印显示出当前的配置,配置是包括在他的配置文件$HOME/.siegerc中,
#可以编辑里面的参数,这样每次siege 都会按照它运行.
-v, --verbose VERBOSE, prints notification to screen.
#运行时能看到详细的运行信息
-q, --quiet QUIET turns verbose off and suppresses output.
-g, --get GET, pull down HTTP headers and display the
transaction. Great for application debugging.
-c, --concurrent=NUM CONCURRENT users, default is 10
#模拟有n个用户在同时访问,n不要设得太大,因为越大,siege 消耗本地机器的资源越多
-i, --internet INTERNET user simulation, hits URLs randomly.
#随机访问urls.txt中的url列表项,以此模拟真实的访问情况(随机性)
-b, --benchmark BENCHMARK: no delays between requests.
-t, --time=NUMm TIMED testing where "m" is modifier S, M, or H
ex: --time=1H, one hour test.
#持续运行siege ‘n’秒(如10S),分钟(10M),小时(10H)
-r, --reps=NUM REPS, number of times to run the test.
#重复运行测试n次,不能与 -t同时存在
-f, --file=FILE FILE, select a specific URLS FILE.
#指定用urls文件,默认为siege安装目录下的etc/urls.txt
#urls.txt文件:是很多行待测试URL的列表以换行符断开,格式为:
#[protocol://]host.domain.com[:port][path/to/file]
-R, --rc=FILE RC, specify an siegerc file
#指定用特定的siege配置文件来运行,默认的为$HOME/.siegerc
-l, --log[=FILE] LOG to FILE. If FILE is not specified, the
default is used: PREFIX/var/siege.log
#运行结束,将统计数据保存到日志文件siege.log中,可在.siegerc中自定义日志文件
-m, --mark="text" MARK, mark the log file with a string.
-d, --delay=NUM Time DELAY, random delay before each requst
between 1 and NUM. (NOT COUNTED IN STATS)
#hit每个url之间的延迟,在0-n之间
-H, --header="text" Add a header to request (can be many)
-A, --user-agent="text" Sets User-Agent in request
-T, --content-type="text" Sets Content-Type in request
增大系统端口限制
ulimit -a
# file descriptors 256
# 端口限制为256
# 临时增大端口,只在当前终生效
ulimit -n 10000
使用方式
//以100并发量重复执行100次
siege -c 100 -r 100 http://www.baidu.com
# 用POST发起100个并发重复执行100次
siege -H "Authorization:Bearer xxx" -c 100 -r 100 "http://localhost:8801/test POST k1=v1&k2=v2"
# 随机执行文件里面的URL
siege -H "Authorization:xxx" -T "application/json" -c 100 -t 30s -i -f ./urltest.txt
# urltest.txt 内容
server=localhost:8801
http://${server}/test1 POST k1=v1&k2=v2
http://${server}/test2 POST
http://${server}/test3
执行结果
Transactions: 53956 hits #完成53956次处理
Availability: 99.03 % #成功率
Elapsed time: 1075.11 secs #总共使用时间
Data transferred: 660.40 MB #共数据传输的数据大小
Response time: 1.15 secs #响应时间,显示网络连接的速度
Transaction rate: 50.19 trans/sec #平均每秒完成 50.19 次处理
Throughput: 0.61 MB/sec #平均每秒传送数据
Concurrency: 57.69 #实际最高并发连接数
Successful transactions: 54047 #成功处理次数
Failed transactions: 531 #失败处理次数
Longest transaction: 72.29 #每次传输所花最长时间
Shortest transaction: 0.01 #每次传输所花最短时间