# How to include loop and run in parallel  in Gatling

**URL:** <https://community.gatling.io/t/how-to-include-loop-and-run-in-parallel-in-gatling/5588>\
**Category:** Gatling (Open-Source)\
**Created:** [April 23, 2020, 12:00pm UTC](https://community.gatling.io/t/how-to-include-loop-and-run-in-parallel-in-gatling/5588 "2020-04-23T12:00:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jupiter\_sailormoon](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jupiter\_sailormoon](https://community.gatling.io/u/jupiter_sailormoon)\
**Post date:** [April 23, 2020, 12:00pm UTC](https://community.gatling.io/t/how-to-include-loop-and-run-in-parallel-in-gatling/5588/1 "2020-04-23T12:00:29Z")

</div>

Hi  
I am doing a comparison using JMeter and Gatling.  
Can someone help how I would create the 3 following scenarios in Gatling:

In JMeter:

1. Run thread groups in Parallel / Consecutively  
I need to run all 2 Gets and 2 Posts in parallel  
I also need to run each one after the other

2. Include loop of each threadgroup to 10

In Jmeter there is loop count, How can I include loop count of 10 in each request.

1. How to pass Json string in the body as ‘raw’ in the postWithContent , I am getting errors with the postwith Comment below

class BasicSimulation extends Simulation {

val httpProtocol = http  
.baseUrl(“[http://localhost:8063](http://localhost:8063)”) // Here is the root for all relative URLs  
.acceptHeader(“text/html,application/xhtml+xml,application/xml;q=0.9,_/_;q=0.8”) // Here are the common headers  
.doNotTrackHeader(“1”)  
.acceptLanguageHeader(“en-US,en;q=0.5”)  
.acceptEncodingHeader(“gzip, deflate”)  
.userAgentHeader(“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0”)

val scn = scenario(“4 threads”) // A scenario is a chain of requests and pauses  
.exec(  
http(“Get”)  
.get("/dummyGet")  
)

.pause(1) // Note that Gatling has recorded real time pauses  
.exec(  
http(“GetReponse”)  
.get("/GetReponse")  
)

.pause(1) // Note that Gatling has recorded real time pauses  
.exec(  
http(“Post”)  
.post("/Post")  
)

.pause(1) // Note that Gatling has recorded real time pauses  
.exec(  
http(“postWithContent”)  
.post("/postWithContent")  
.body(StringBody("""{“name”:“abc”, “add”:“231”, “tel”:“42322”}"""))  
)

setUp(scn.inject(rampUsers(10000) during (60 seconds)).protocols(httpProtocol))  
}

---

<div class="post-metadata">

**Author:** ![Naveen\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@Naveen\_Agarwal](https://community.gatling.io/u/Naveen_Agarwal)\
**Post date:** [April 24, 2020, 5:21am UTC](https://community.gatling.io/t/how-to-include-loop-and-run-in-parallel-in-gatling/5588/2 "2020-04-24T05:21:26Z")

</div>

regarding scenario : 2

val scn = scenario(“4 threads”) // A scenario is a chain of requests and pauses  
.repeat( times =10)(exec(  
http(“Get”)  
.get("/dummyGet")  
))

regarding scenario : 3

Save the body in json file on particular place.  
{“name”:“abc”, “add”:“231”, “tel”:“42322”}

.exec(  
http(“postWithContent”)  
.post("/postWithContent")  
.body(ElFileBody(“src/test/resources/bodies/\<jsonfile\_name\>.json”)).asJson  
)

---

<div class="post-metadata">

**Author:** ![jupiter\_sailormoon](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jupiter\_sailormoon](https://community.gatling.io/u/jupiter_sailormoon)\
**Post date:** [April 24, 2020, 10:50am UTC](https://community.gatling.io/t/how-to-include-loop-and-run-in-parallel-in-gatling/5588/3 "2020-04-24T10:50:50Z")

</div>

Thanks Naveen.

Do you have an idea how I can run test in parallel on 4 endpoints?
