Skip to content

Instantly share code, notes, and snippets.

@notsobad
Created July 27, 2017 06:09
Show Gist options
  • Save notsobad/8d08ee9041a8cffa7da902a0ead656b1 to your computer and use it in GitHub Desktop.
Save notsobad/8d08ee9041a8cffa7da902a0ead656b1 to your computer and use it in GitHub Desktop.

wrk 来构造http性能测试用例

https://gist.github.com/denji/8333630 HTTP(S) Benchmark Tools / Toolkit for testing/debugging HTTP(S) and restAPI (RESTful)

参考:https://github.com/wg/wrk/blob/master/scripts/counter.lua

ab发送的请求都是一样的,某些情况下我们需要构造不同的http请求来并发测试,可以用wrk,写lua脚本来针对每个请求定制请求头。

wxh-rmbp :: ~ » cat x.lua

counter = 0

request = function()
   path = "/index.html?r=" .. counter
   wrk.headers["Host"] = "www.demo-"..counter..".com"
   counter = counter + 1
   return wrk.format(nil, path)
end

wxh-rmbp :: ~ » wrk -s x.lua -t1 -c4 -d1s  http://127.0.0.1:8000/index.html
Running 1s test @ http://127.0.0.1:8000/index.html
  1 threads and 4 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.48ms  274.37us   4.38ms   84.05%
    Req/Sec     2.49k   193.78     2.72k    81.82%
  2725 requests in 1.10s, 620.04KB read
Requests/sec:   2478.73
Transfer/sec:    564.01KB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment