【wrk】wrk压测工具入门
- 其他
- 2025-08-29 02:12:02

1. 简介
wrk 是我无意间发现的一款简单好用的 HTTP 接口性能测试工具,目前在 Github 上已经有 38k 的 star 数了!
⭐ Github地址: github /wg/wrk
2. 安装环境要求:
windows10 平台安装过 ubuntu 等 Linux 子系统在 windows 中通过 bash 进入 linux 环境依次执行以下命令:sudo apt-get install wrk
如上图所示,如果执行wrk命令能看到以下结果证明安装完成!
3. 使用wrk 工具的使用非常简单:只需要掌握以下这个命令:wrk -t2 -d10s -c100 -s ./script/login.lua http://172.24.0.1:8081/users/login,其中各个参数选项含义如下:
-t:启动线程的数量-d:持续时间,比如这里就是10s(也可以指定成1m表示1分钟)-c:并发请求数-s:运行脚本的路径❗ 注意:如果在 windows 中的 linux 子系统中,直接使用 localhost 访问是不可行的,需要先在 windows cmd 中使用 ipconfig 获取本机ip地址,然后替代 localhost,参考博客: blog.csdn.net/qq_41407687/article/details/142172220
测试结果如上图所示:我们可以调整参数寻找最优测试结果
4. 附:Lua 脚本 4.1 signup.lua wrk.method="POST" wrk.headers["Content-Type"] = "application/json" local random = math.random local function uuid() local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' return string.gsub(template, '[xy]', function (c) local v = (c == 'x') and random(0, 0xf) or random(8, 0xb) return string.format('%x', v) end) end -- 初始化 function init(args) -- 每个线程都有一个 cnt,所以是线程安全的 cnt = 0 prefix = uuid() end function request() body=string.format('{"email":"%s%d@qq ", "password":"hello#world123", "confirmPassword": "hello#world123"}', prefix, cnt) cnt = cnt + 1 return wrk.format('POST', wrk.path, wrk.headers, body) end function response() end 4.2 login.lua wrk.method="POST" wrk.headers["Content-Type"]="application/json" wrk.body='"{"email": "wjjbangbangbang@163 ","password": "hello#world123"}"'【wrk】wrk压测工具入门由讯客互联其他栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“【wrk】wrk压测工具入门”