0%

windows上使用go-wrk进行接口压力测试

Go开发接口测试过程记录

压测工具准备

go install github.com/adjust/go-wrk

测试接口准备

将开发中的接口写一个简单的测试接口用例,方便wrk模拟调用

把参数提取加入

第一次测试接口,直接将参数写死,未能模拟最真实的场景-待研究

image-20220916170228589

开始压力测试

工具下载后,go-wrk.exe出现在GOPATH/bin/

在该路径下直接cmd,或者使用命令行到该路径下

开启Web服务

使用以下命令进行测试

# 8个线程,400个连接, 模拟1w次请求  -d替换-n表示连接时间
go-wrk -c=400 -t=8 -n=10000 http://localhost:8082/product/qrder
D:\goProject\bin>go-wrk -h
Usage of go-wrk:
  -CA string
        A PEM eoncoded CA's certificate file. (default "someCertCAFile")
  -H string
        the http headers sent separated by '\n' (default "User-Agent: go-wrk 0.1 benchmark\nContent-Type: text/html;")
  -b string
        the http request body
  -c int
        the max numbers of connections used (default 100)
  -cert string
        A PEM eoncoded certificate file. (default "someCertFile")
  -d string
        dist mode
  -f string
        json config file
  -i    TLS checks are disabled
  -k    if keep-alives are disabled (default true)
  -key string
        A PEM encoded private key file. (default "someKeyFile")
  -m string
        the http request method (default "GET")
  -n int
        the total number of calls processed (default 1000)
  -p string
        the http request body data file
  -r    in the case of having stream or file in the response,
         it reads all response body to calculate the response size
  -s string
        if specified, it counts how often the searched string s is contained in the responses
  -t int
        the numbers of threads used (default 1)

测试效果如下

image-20220921170806211

每秒 929.15次连接 也可以说 QPS为 929.15

因继续改进,出现连接错误与超卖现象

使用本地Windows10 16G内存 CPU i7-9750H 8核 进行测试

-------------本文结束感谢您的阅读-------------
打赏一瓶矿泉水