WRK-HTTP压力测试工的下载安装与使用方法

天涯浪子 提交于 2020-03-05 15:05:11

 

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.html

  This runs a benchmark for 30 seconds, using 12 threads, and keeping
  400 HTTP connections open.

  Output:

  Running 30s test @ http://127.0.0.1:8080/index.html
    12 threads and 400 connections
    Thread Stats   Avg      Stdev     Max   +/- Stdev
      Latency   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 read
  Requests/sec: 748868.53
  Transfer/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还可以任意添加修改参数 
  1. 命令依然为./wrk -t8 -c100 -d1m --script = post.lua http://localhost:8088/v2
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!