# Gatling pause function usage - before or/And after exec

**URL:** <https://community.gatling.io/t/gatling-pause-function-usage-before-or-and-after-exec/3528>\
**Category:** Gatling (Open-Source)\
**Created:** [January 30, 2017, 11:23am UTC](https://community.gatling.io/t/gatling-pause-function-usage-before-or-and-after-exec/3528 "2017-01-30T11:23:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayush\_Anand](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Ayush\_Anand](https://community.gatling.io/u/Ayush_Anand)\
**Post date:** [January 30, 2017, 11:23am UTC](https://community.gatling.io/t/gatling-pause-function-usage-before-or-and-after-exec/3528/1 "2017-01-30T11:23:59Z")

</div>

Anyone,  
What is the current way to introduce pause before & after a request.  
Below is how I have written the code but I am sure it doesn’t work as expected. I am expecting the requests to be 4s apart. See the diagram at bottom:  
If I place pause inside exec code block, I get errors:

_Desktop/gatling-charts-highcharts-bundle-2.2.3/user-files/simulations/computerdatabase/simulation.scala:47: value http is not a member of io.gatling.core.structure.ChainBuilder_  
_possible cause: maybe a semicolon is missing before `value http’?_  
_16:35:23.284 [ERROR] i.g.c.ZincCompiler$ - http(requestName)_  
_16:35:23.285 [ERROR] i.g.c.ZincCompiler$ - ^_  
_16:35:23.285 [ERROR] i.g.c.ZincCompiler$ - /Users/z0019cb/Desktop/gatling-charts-highcharts-bundle-2.2.3/user-files/simulations/computerdatabase/simulation.scala:48: type mismatch;_  
_found : String("${url}")_  
_required: Int_

_**val scn = scenario(scenarioName)**_  
_**.feed(csvFeeder)**_  
_**.pause(2 seconds)**_  
_**.during(testTimeSecs) {**_  
_**exec(**_  
_**http(requestName)**_  
_**.get("${url}")**_  
_**.headers(http\_headers)**_  
_**)**_  
_**.pause(2 seconds)**_  
_ **}** _

[![](https://lh3.googleusercontent.com/-nXTwG_oPGqQ/WI8iBHmljlI/AAAAAAAAK_E/iD-TJJCkJBYYOf6jhJvWtx78WmezIOAPwCLcB/s320/Screen%2BShot%2B2017-01-30%2Bat%2B4.51.53%2BPM.png)](https://lh3.googleusercontent.com/-nXTwG_oPGqQ/WI8iBHmljlI/AAAAAAAAK_E/iD-TJJCkJBYYOf6jhJvWtx78WmezIOAPwCLcB/s1600/Screen%2BShot%2B2017-01-30%2Bat%2B4.51.53%2BPM.png)

---

<div class="post-metadata">

**Author:** ![Stephen](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@Stephen](https://community.gatling.io/u/Stephen)\
**Post date:** [January 30, 2017, 1:24pm UTC](https://community.gatling.io/t/gatling-pause-function-usage-before-or-and-after-exec/3528/2 "2017-01-30T13:24:04Z")

</div>

Base on the code you posted, you are waiting 2s before the “during” loop start and 2s after each request in the loop.

If you want to wait 2s before each request present in the loop, move the first “.pause(2 seconds)” inside the loop:

`  
_**val scn = scenario(scenarioName)**_  
_**.feed(csvFeeder)**_  
_**.during(testTimeSecs) {**_  
_**pause(2 seconds)**_

_**.exec(**_  
_**http(requestName)**_  
_**.get("${url}")**_  
_**.headers(http\_headers)**_  
_**)**_  
_**.pause(2 seconds)**_  
_ **}** _  
`

---

<div class="post-metadata">

**Author:** ![Ayush\_Anand](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Ayush\_Anand](https://community.gatling.io/u/Ayush_Anand)\
**Post date:** [February 1, 2017, 6:41am UTC](https://community.gatling.io/t/gatling-pause-function-usage-before-or-and-after-exec/3528/3 "2017-02-01T06:41:37Z")

</div>

Thanks a lot Stephen, much appreciated.

---

<div class="post-metadata">

**Author:** ![Ayush\_Anand](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Ayush\_Anand](https://community.gatling.io/u/Ayush_Anand)\
**Post date:** [February 1, 2017, 7:21am UTC](https://community.gatling.io/t/gatling-pause-function-usage-before-or-and-after-exec/3528/4 "2017-02-01T07:21:49Z")

</div>

Hi, I need one more clarification, I have used convert function to change the type of parameter “reltime” from string to int. This value I am trying to pass to pause function & it works. But I want to do mathematical operation on this “reltime”; something like below

_**val pauseduration = “${reltime}” - (System.currentTimeMillis / 1000 - teststarttime)**_

here teststarttime is constant.

**Error** = 12:50:45.219 [ERROR] i.g.c.ZincCompiler$ - /Users/\*\*\*\*\*\*/Desktop/gatling-charts-highcharts-bundle-2.2.3/user-files/simulations/computerdatabase/sample\_simulation.scala:43: value - is not a member of String

val csvFeeder = csv(“test.csv”)  
.queue  
.convert{case (“reltime”, string) =\> string.toInt}

---

<div class="post-metadata">

**Author:** ![Stephen](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@Stephen](https://community.gatling.io/u/Stephen)\
**Post date:** [February 10, 2017, 8:28am UTC](https://community.gatling.io/t/gatling-pause-function-usage-before-or-and-after-exec/3528/5 "2017-02-10T08:28:46Z")

</div>

I’m not sure you can do whant you want that way.

_ **"${reltime}"** _ is a String, that is why you get the error.

Since you get reltime from a feeder, you can retrieve the variable using the user session :

val reltime = session(“reltime”).as[Int]

Then you can do the math with that int variable :

_**val pauseduration = reltime - (System.currentTimeMillis / 1000 - teststarttime)**_

---

<div class="post-metadata">

**Author:** ![Ayush\_Anand](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Ayush\_Anand](https://community.gatling.io/u/Ayush_Anand)\
**Post date:** [February 23, 2017, 12:46pm UTC](https://community.gatling.io/t/gatling-pause-function-usage-before-or-and-after-exec/3528/6 "2017-02-23T12:46:48Z")

</div>

Thanks Stephen,  
but I am not sure I am doing the session thing right as I am getting not found: value session error while running.  
Below is my full code:

val scn = scenario(scenarioName)  
.feed(csvFeeder)  
val reltime = session(“reltime”).as[Int]  
val pauseduration = reltime - (System.currentTimeMillis / 1000 - teststarttime)  
.pause(pauseduration)  
.during(testTimeSecs) {  
exec(  
http(requestName)  
.get("${url}")  
.headers(http\_headers)  
)

}
