我正在尝试在 Gatling 2.2.0 中为服务器到服务器的 REST API 交互建模。有几种类型的交互“请求列表,然后并行请求列表中的所有项目”,但我似乎无法在 Gatling 中对此建模。到目前为止的代码:
def groupBy(dimensions: Seq[String], metric: String) = {
http("group by")
.post(endpoint)
.body(...).asJSON
.check(
...
.saveAs("events")
)
}
scenario("Dashboard scenario")
.exec(groupBy(dimensions, metric)
.resources(
// a http() for each item in session("events"), plz
)
)
我已经弄清楚并行请求是由 .resources() 执行的,但我不明白如何生成一个请求列表来提供它。感谢任何输入。
最佳答案
以下方法对我有用。 HttpRequestBuilder 的 Seq 会被并发执行:
val numberOfParallelReq = 1000
val scn = scenario("Some scenario")
.exec(
http("first request")
.post(url)
.resources(parallelRequests: _*)
.body(StringBody(firstReqBody))
.check(status.is(200))
)
def parallelRequests: Seq[HttpRequestBuilder] =
(0 until numberOfParallelReq).map(i => generatePageRequest(i))
def generatePageRequest(id: Int): HttpRequestBuilder = {
val body = "Your request body here...."
http("page")
.post(url)
.body(StringBody(body))
.check(status.is(200))
}
关于load-testing - 使用 Gatling 发出可变数量的并行 HTTP 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40324276/