3

I am trying to model a server-to-server REST API interaction in Gatling 2.2.0. There are several interactions of the type "request a list and then request all items on the list at in parallel", but I can't seem to model this in Gatling. Code so far:

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 
    )
  )

I have gotten as far as figuring out that parallel requests are performed by .resources(), but I don't understand how to generate a list of requests to feed it. Any input is appreciated.

2 Answers 2

2

Below approach is working for me. Seq of HttpRequestBuilder will be executed concurrently:

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))
}
Sign up to request clarification or add additional context in comments.

4 Comments

While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. Please read this how-to-answer for providing quality answer.
Is it possible to get access to session("events") inside parallelRequests ?
is there any way we can pass feeder data into these request?
What feeder data do you mean?
0

Not very sure of your query but seems like you need to send parallel request which can be done by setUp(scenorio.inject(atOnceUsers(NO_OF_USERS)));

Refer this https://docs.gatling.io/reference/script/core/simulation/#setup

1 Comment

This will not perform requests depending on data as retrieved from the API, but simply run an unrelated, fix-rate set of queries. As far as I understand, there is no way to parametrize scenarios from other scenarios.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.