从wrk到k6:等效参数和测试方法

问题描述 投票:0回答:1

我们正在将性能测试存储库从使用 wrk 迁移到 k6。但是,我们的目标是维持之前设置中使用的测试方法。

在我们当前的配置中,我们处理包含大约 300,000 个请求的大文件。这些请求在我们的 Lua 脚本中逐行读取,然后连接起来供 wrk 工具使用。目前使用的命令如下:

./wrk -d 1m -t 8 -c 256 --timeout 30s -R 16000 -q -s pipeline.lua http://localhost:8080 ./requests.reqs 

参考wrk文档:

-c, --connections: total number of HTTP connections to keep open with
                   each thread handling N = connections/threads

-d, --duration:    duration of the test, e.g. 2s, 2m, 2h

-t, --threads:     total number of threads to use

-r:  throughput argument, total requests per second

我的询问是关于 k6 中的等效参数。在 k6 测试期间可以在“选项”变量中指定这些吗?

wrk 中的 -c 概念与 k6 中的“vus”概念类似,但文档有些含糊。 k6 文档包含“batch”、“rps”和“iterations”等相关选项,但它们与 wrk 中的参数并不完全匹配。

如果有人可以提供一个使用 k6 模仿 wrk 方法的完整测试示例,我将不胜感激。

免责声明:我知道 k6 并不专注于实现 wrk 等工具的最高并发用户数或 RPS 性能。

testing load performance-testing k6 wrk
1个回答
0
投票

我认为使用 k6 可以获得的最接近结果如下:

export const options = {
  scenarios: {
    wrk: {
      exector: 'constant-arrival-rate', // we want to control "RPS" (rate)
      rate: 16000, // "RPS" (executions of default function)
      duration: '1m', // run scenario for 1 minute
      preAllocatedVUs: 256, // start with 256 VUs (not really threads, but somewhat close)
      maxVUs: 2048, // maximum number of VUs, started on-demand to maintain the requested RPS (value guesstimated by threads*connections)
    }
  }
};

export default function() {
  http.get(...); // perform your request(s)
}

这将每秒执行默认函数 16000 次。如果它仅包含单个请求,则等于 16000 rps。如果您的默认函数执行多个请求,您必须考虑到这一点。

k6 将根据需要启动 VU 以匹配您的目标 RPS。如果您有 1000 个 VU 并请求 10 RPS,该函数仍然每秒仅执行 10 次,所有其他 VU 将处于空闲状态。

大多数选项可以通过导出的

options
对象指定或作为命令行参数提供。有
--rps
选项
,但不鼓励使用它,您应该更喜欢具有到达率执行器的场景。

您可能需要查看

noConnectionReuse
选项,它控制连接是否保持活动状态。

© www.soinside.com 2019 - 2024. All rights reserved.