美文网首页
wrk动态脚本压测

wrk动态脚本压测

作者: 伊丽莎白菜 | 来源:发表于2022-12-01 10:03 被阅读0次

压测工具

wrk是一个小巧的命令行http压测工具,支持lua脚本。

项目地址: https://github.com/wg/wrk

参数释义

Usage: wrk <options> <url>                            
  Options:                                            
    -c, --connections <N>  Connections to keep open   
    -d, --duration    <T>  Duration of test           
    -t, --threads     <N>  Number of threads to use   
                                                      
    -s, --script      <S>  Load Lua script file       
    -H, --header      <H>  Add header to request      
        --latency          Print latency statistics   
        --timeout     <T>  Socket/request timeout     
    -v, --version          Print version details      
                                                      
  Numeric arguments may include a SI unit (1k, 1M, 1G)
  Time arguments may include a time unit (2s, 2m, 2h)

脚本示例

createOrder.lua:

local bodyTemp = [[
{
    "id": "%s",
    "type": "order",
}
]]

local counter = 0

function setup(thread)
    thread:set("id", counter)
    counter = counter + 1
end

request = function()
    wrk.method = "POST"
    wrk.headers["Content-Type"] = "application/json"
    wrk.headers["authorization"] = "Bearer ".."your.access.token"
    local tid = wrk.thread:get("id")
    -- generate random id
    local orderId = "wrk"..os.time()..string.sub(math.random(),10)..tid
    --print(orderId)
    wrk.body = string.format(bodyTemp, orderId)
    return wrk.format(nil)
end

function response(status, headers, body)
    print(status)
    --print(body)
end

执行压测

wrk -c1 -t1 -d1s -s createOrder.lua http://your.url

查看报告

  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   275.57ms   45.84ms 319.61ms   66.67%
    Req/Sec     3.00      1.00     4.00    100.00%
  3 requests in 1.03s, 106.01KB read
Requests/sec:      2.91
Transfer/sec:    103.00KB

相关文章

  • 2020-08-24 华为ARM服务器编译wrk

    华为的认证需要跑压测脚本,那就安装wrk吧 先试下华为的yum源里有wrk不: 写本地yum源配置: 尝试安装 但...

  • 外挂docker工具镜像至某个运行中的container

    场景 开发环境需要进入pod内部压测代理的性能(压测工具选择wrk),但是容器内部没有wrk 方法一: 通过yum...

  • go 性能调优工具

    1 压测 http请求: https://github.com/wg/wrk 例子 wrk -t12 -c400 ...

  • 压测工具wrk

    在工作中经常用wrk对接口进行简单的压测,最近工作中测试接口需要对参数进行签名校验,借这个机会,打算仔细研究下wr...

  • HTTP压测工具之wrk

    wrk是一款简单的HTTP压测工具,托管在Github上,https://github.com/wg/wrk.wr...

  • wrk 压测工具使用

    wrk是一款简单的HTTP压测工具,托管在Github上,https://github.com/wg/wrk.wr...

  • HTTP压测工具wrk的使用

    wrk是一款简单的HTTP压测工具,托管在Github上,https://github.com/wg/wrk[ht...

  • linux压测脚本

    需要对linux进行压测,网上找了一些脚本,会报错。因此将好用的脚本整理记录一下。 cpu压测脚本 内存压测脚本

  • 压测过程中的KeepAlive

    使用wrk压测,待测服务多节点 通过域名访问nginx对比直连,压测时性能损耗很大的问题 1). 原因:经查询TC...

  • 服务流量限制

    性能测试 写个简单的web服务,再用工具进行压测。 使用wrk 工具进行压测: 常见限流手段 流量限制的手段有很多...

网友评论

      本文标题:wrk动态脚本压测

      本文链接:https://www.haomeiwen.com/subject/kmsefdtx.html