load-testing - 使用 Gatling 发出可变数量的并行 HTTP 请求?

标签 load-testing gatling

我正在尝试在 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/

相关文章:

performance - JMeter : How to record HTTPS traffic?

scala - 如何在没有sbt命令的情况下在IntelliJ IDEA中调试/运行单个加特林模拟?

scala - 如果使用 doIf 传递了上一个场景,则需要运行下一个场景

scala - 加特林负载测试和运行场景

json - GATLING JSON 保存和重用

testing - Loadrunner安装错误

jmeter - Jmeter 的响应时间因 Firebug 而异

visual-studio - Visual Studio Cloud 如何查看我的负载测试在云中运行时发生的错误和警告?

jmeter - Gattle vs Jmeter - 每个请求的响应时间存在巨大差异

scala - 发送授权 token |加特林