GenweiWu / Blog

个人技术能力提升
MIT License
4 stars 0 forks source link

wrk性能测试 #78

Open GenweiWu opened 3 years ago

GenweiWu commented 3 years ago

安装

git clone https://github.com/wg/wrk.git  
cd wrk  
make  #编译后得到wrk执行文件
## 通过下面的方式,找出可用的path路径,然后将wrk放到任一路径下即可使用
## which wrk
/usr/bin/which: no wrk in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

lua构造请求

cat test.lua


wrk.method="GET"
wrk.path = "/test-service/menu/refresh"

function request()

local requestPath=wrk.path local resp = wrk.format(nil,requestPath) return resp end

response = function(status, headers, body) print("status is:",status) if status ~= 200 then print("body = ",body) -- token = headers["X-Token"] --path = "/resource" --wrk.headers["X-Token"] = token end end


```bash
wrk -t1 -c1 -d1s -s test.lua --latency https://abc.com
## t12表示12个线程,c200表示200个连接,d30s表示测试时间为30s
wrk -t12 -c200 -d30s -s test.lua --latency https://abc.com

参考