高性能测试工具WRK的高级使用方法
2017-10-27 20:57
567 查看
WRK
github地址:https://github.com/wg/wrk简介:基于事件机制的高性能http压力测试工具,除了能针对单个url进行测试外,最重要的就是能够构造不同的url,不同的参数进行测试。或者发送携带body的POST请求,在有些场景下不要太帅。
说明
wrk高级的地方就是使用了luajit,在不同阶段抛出来几个回调函数,只需要针对这些函数操作即可构造想要请求。典型的回调函数有以下几个function setup(thread) 在创建线程时调用
function init(args) 在线程启动时调用
function request() 每个请求都会调用,特别说明,此函数调用频繁,所以不要在这里写入耗时的操作,如果复杂的请求,在init函数就构造好,这里直接引用。
function delay()
function response(status, headers, body) ,频繁调用。
举例
1 发送get 请求
如果想构造不同的请求比如/1?arg=1, /2?arg=2, /3?arg=3……,并且发送GET请求,创建文件为http_get.lua , 代码如下counter = 0 num = 0 request = function() path = "/" .. counter .. "?arg=" .. num counter = counter + 1 num = num + 1 return wrk.format("", path) end
执行命令为:
wrk -c 4 -t 4 -d 10s -s http_get.lua http://cool.test.net/v1.f4v[/code]
结果为:4 threads and 4 connections Thread Stats Avg Stdev Max +/- Stdev Latency 476.52us 306.27us 5.74ms 94.84% Req/Sec 2.12k 171.21 2.39k 65.12% 9085 requests in 1.10s, 1.49MB read Requests/sec: 8256.69 Transfer/sec: 1.35MB2 发送POST请求
文件名 http_post.luacounter = 0 request = function() path = "/" .. counter counter = counter + 1 headers = {TH= "httpheader"} body = "hello world " .. counter return wrk.format("POST", path, headers, body) end3 文件中指定uri
如果要测试的url在文件中呢,那么在init阶段把uri都读取到table中,在request中直接引用即可, 具体如下
uri文件为: uri.txt/1.txt /2.txt /3.txt /4.txt /5.txt
文件名 http_file_uri.lua,代码urimap = {} counter = 0 function init(args) for line in io.lines("uri.txt") do print(line) urimap[counter] = line counter = counter + 1 end counter = 0 end request = function() counter = counter + 1 path = urimap[counter%table.getn(urimap) + 1] return wrk.format(nil, path) end
效果如下:Thread Stats Avg Stdev Max +/- Stdev Latency 484.00us 335.83us 8.44ms 95.13% Req/Sec 2.14k 192.78 2.59k 71.50% 85400 requests in 10.00s, 14.00MB read Requests/sec: 8538.60 Transfer/sec: 1.40MB
服务器端收到请求
相关文章推荐
- webService测试工具及使用方法
- cobertura覆盖测试工具的使用方法
- Apache压力测试工具使用方法
- Android 测试工具Monkey & Monkeyrunner 使用方法
- 【转载】Apache自带压力测试工具AB的使用方法
- Android 测试工具Monkey & Monkeyrunner 使用方法
- 渗透测试工具Nmap从初级到高级使用教程(转)
- 软件测试工具MonkeyTalk使用方法
- 性能测试监控工具nmon安装及使用方法
- 嵌入式开发中网络性能测试工具iperf的使用方法和注意事项
- linux 性能测试工具Lmbench 使用方法
- 第4代白盒测试方法实践之“内存泄露检查工具VLD如何与VcTester配合使用”
- 免费APP在线测试工具以及其使用方法
- Apache自带压力测试工具AB的使用方法
- HTTP压力测试工具apache的ab的使用方法
- 页面静态化1 --- 概念(Apache内置压力测试工具使用方法)
- 软件测试工具MonkeyTalk使用方法
- 软件测试工具MonkeyTalk使用方法
- 性能测试监控工具nmon安装及使用方法
- 性能测试监控工具nmon安装及使用方法