2019独角兽企业重金招聘Python工程师标准>>>
wrk 是一款采用异步并发模型的HTTP基准测试工具:采用异步并发模型,能够发送更大且可控的压力;内置 LuaJIT,能够通过 lua 脚本模拟常见的业务行为,模拟更加真实的场景;相比常见的HTTP基准测试工具,占用更少CPU、更少内存;
支持 HTTP、 HTTPS,能够动态修改头、修改Body方法等;支持混合场景
编译安装
- 1.sudo yum groupinstall ‘Development Tools’
- 2.sudo yum install openssl-devel
- 3.sudo yum install git #下载安装git,并下载wrk
- 4.git clone https://github.com/wg/wrk.git
- 5.cd wrk
- 6.make
基本测试方法:
wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.htmlThis runs a benchmark for 30 seconds, using 12 threads, and keeping400 HTTP connections open.Output:Running 30s test @ http://127.0.0.1:8080/index.html12 threads and 400 connectionsThread Stats Avg Stdev Max +/- StdevLatency 635.91us 0.89ms 12.92ms 93.69%Req/Sec 56.20k 8.07k 62.00k 86.54%22464657 requests in 30.00s, 17.76GB readRequests/sec: 748868.53Transfer/sec: 606.33MB
- latency:延时;
- req/sec:每秒钟处理的请求量
- stdev:标准差
7.wrk以post方式或header方式压测
首先创建一个 post.lua 的文件:
- wrk.method = "POST"
- wrk.body = "a=3&b=4" #post所放参数
- wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
当然header还可以任意添加修改参数
./wrk -t8 -c100 -d1m --script = post.lua http://localhost:8088/v2
post.lua文件:
8.wrk以post方式或header方式压测
首先创建一个 post.lua 的文件:
- wrk.method = "POST"
- wrk.body = ""
- wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"
- wrk.headers["params1"] = "a"
- wrk.headers["params2"] = "b" #header参数可以任意添加
当然header还可以任意添加修改参数
- 命令依然为./wrk -t8 -c100 -d1m --script = post.lua http://localhost:8088/v2