go get github.com/adeven/go-wrk
使用方法同wrk类似,基本格式如下:
go-wrk [flags] url
常用的参数:
-H="User-Agent: go-wrk 0.1 bechmark\nContent-Type: text/html;": 由'\n'分隔的请求头
-c=100: 使用的最大连接数
-k=true: 是否禁用keep-alives
-i=false: if TLS security checks are disabled
-m="GET": HTTP请求方法
-n=1000: 请求总数
-t=1: 使用的线程数
-b="" HTTP请求体
-s="" 如果指定,它将计算响应中包含搜索到的字符串s的频率
执行测试:
go-wrk -t=8 -c=100 -n=10000 "http://127.0.0.1:8080/api/v1/posts?size=10"
输出结果:
==========================BENCHMARK==========================
URL: http://127.0.0.1:8080/api/v1/posts?size=10
Used Connections: 100
Used Threads: 8
Total number of calls: 10000
===========================TIMINGS===========================
Total time passed: 2.74s
Avg time per request: 27.11ms
Requests per second: 3644.53
Median time per request: 26.88ms
99th percentile time: 39.16ms
Slowest time for request: 45.00ms
=============================DATA=============================
Total response body sizes: 340000
Avg response body per request: 34.00 Byte
Transfer rate per second: 123914.11 Byte/s (0.12 MByte/s)
==========================RESPONSES==========================
20X Responses: 10000 (100.00%)
30X Responses: 0 (0.00%)
40X Responses: 0 (0.00%)
50X Responses: 0 (0.00%)
Errors: 0 (0.00%)