# How to hold load?

**URL:** <https://community.gatling.io/t/how-to-hold-load/491>\
**Category:** Gatling (Open-Source)\
**Created:** [July 12, 2013, 10:13am UTC](https://community.gatling.io/t/how-to-hold-load/491 "2013-07-12T10:13:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![user11](https://avatars.discourse-cdn.com/v4/letter/u/dfb087/32.png) [@user11](https://community.gatling.io/u/user11)\
**Post date:** [July 12, 2013, 10:13am UTC](https://community.gatling.io/t/how-to-hold-load/491/1 "2013-07-12T10:13:24Z")

</div>

setUp(scn.inject(ramp(100 users) over (100 seconds) )).protocols(httpProtocol)

How to hold load for several minutes when all users are active?

---

<div class="post-metadata">

**Author:** ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)\
**Post date:** [July 12, 2013, 11:23am UTC](https://community.gatling.io/t/how-to-hold-load/491/2 "2013-07-12T11:23:19Z")

</div>

Well, the injection API is only there to control the injection.  
If you want to alter the comportment of the users, why not using the .during() element? [https://github.com/excilys/gatling/wiki/Structure-Elements#wiki-during](https://github.com/excilys/gatling/wiki/Structure-Elements#wiki-during)

---

<div class="post-metadata">

**Author:** ![user11](https://avatars.discourse-cdn.com/v4/letter/u/dfb087/32.png) [@user11](https://community.gatling.io/u/user11)\
**Post date:** [July 12, 2013, 1:54pm UTC](https://community.gatling.io/t/how-to-hold-load/491/3 "2013-07-12T13:54:21Z")

</div>

Is it possible to apply .during() to the whole scenario, and not to the single user?

---

<div class="post-metadata">

**Author:** ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)\
**Post date:** [July 12, 2013, 2:05pm UTC](https://community.gatling.io/t/how-to-hold-load/491/4 "2013-07-12T14:05:43Z")

</div>

That question is confusing me.

All users are using the same scenario, so, yes, if you use the .during() keyword in the scenario DSL, it will apply for all users.

---

<div class="post-metadata">

**Author:** ![user11](https://avatars.discourse-cdn.com/v4/letter/u/dfb087/32.png) [@user11](https://community.gatling.io/u/user11)\
**Post date:** [July 15, 2013, 12:34pm UTC](https://community.gatling.io/t/how-to-hold-load/491/5 "2013-07-15T12:34:20Z")

</div>

I’m sorry. I wrote my question incorrectly. If I use .during(100) in chain descryption, and .ramp(100) in setUp it means that last user will start at 100 sec after beginning and will operate for 100sec. That’s why load will looks like:

[![](https://lh4.googleusercontent.com/-oi88puK2_Hk/UeE7aXZ9LuI/AAAAAAAAAAc/_hdCml0g83M/s200/%D0%9D%D0%BE%D0%B2%D1%8B%D0%B9+%D1%82%D0%BE%D1%87%D0%B5%D1%87%D0%BD%D1%8B%D0%B9+%D1%80%D0%B8%D1%81%D1%83%D0%BD%D0%BE%D0%BA.bmp)](https://lh4.googleusercontent.com/-oi88puK2_Hk/UeE7aXZ9LuI/AAAAAAAAAAc/_hdCml0g83M/s1600/%D0%9D%D0%BE%D0%B2%D1%8B%D0%B9+%D1%82%D0%BE%D1%87%D0%B5%D1%87%D0%BD%D1%8B%D0%B9+%D1%80%D0%B8%D1%81%D1%83%D0%BD%D0%BE%D0%BA.bmp)

But I try to limit all test and create load like:

[![](https://lh5.googleusercontent.com/--ZXAk3TBdp8/UeE8Y2OYxqI/AAAAAAAAAAs/Ps9oNd0XQw0/s200/%D0%9D%D0%BE%D0%B2%D1%8B%D0%B9+%D1%82%D0%BE%D1%87%D0%B5%D1%87%D0%BD%D1%8B%D0%B9+%D1%80%D0%B8%D1%81%D1%83%D0%BD%D0%BE%D0%BA.bmp)](https://lh5.googleusercontent.com/--ZXAk3TBdp8/UeE8Y2OYxqI/AAAAAAAAAAs/Ps9oNd0XQw0/s1600/%D0%9D%D0%BE%D0%B2%D1%8B%D0%B9+%D1%82%D0%BE%D1%87%D0%B5%D1%87%D0%BD%D1%8B%D0%B9+%D1%80%D0%B8%D1%81%D1%83%D0%BD%D0%BE%D0%BA.bmp)

all users will stop after 100 sec after beginning. So is there any way in gatling functions or need to use scala functions to parametrize worktime of every user (.during(param))  
Also Is it possible to create a stepped load like:

[![](https://lh4.googleusercontent.com/-gmnaoKPUAPE/UePsHU5bYoI/AAAAAAAAAA4/5k8Mq-Hbick/s200/%D0%9D%D0%BE%D0%B2%D1%8B%D0%B9+%D1%82%D0%BE%D1%87%D0%B5%D1%87%D0%BD%D1%8B%D0%B9+%D1%80%D0%B8%D1%81%D1%83%D0%BD%D0%BE%D0%BA.bmp)](https://lh4.googleusercontent.com/-gmnaoKPUAPE/UePsHU5bYoI/AAAAAAAAAA4/5k8Mq-Hbick/s1600/%D0%9D%D0%BE%D0%B2%D1%8B%D0%B9+%D1%82%D0%BE%D1%87%D0%B5%D1%87%D0%BD%D1%8B%D0%B9+%D1%80%D0%B8%D1%81%D1%83%D0%BD%D0%BE%D0%BA.bmp)

---

<div class="post-metadata">

**Author:** ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)\
**Post date:** [July 15, 2013, 3:04pm UTC](https://community.gatling.io/t/how-to-hold-load/491/6 "2013-07-15T15:04:45Z")

</div>

Hi,

Thanks for the sketches, I understand your problem now, but we don’t have such a functionnality in Gatling.

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [July 23, 2013, 11:49pm UTC](https://community.gatling.io/t/how-to-hold-load/491/7 "2013-07-23T23:49:06Z")

</div>

That’s something that you can easily implement yourself actually: just wrap your whole scenario into an asLongAs loop that would check the duration since simulation start.  
[https://github.com/excilys/gatling/wiki/Structure-Elements#wiki-asLongAs](https://github.com/excilys/gatling/wiki/Structure-Elements#wiki-asLongAs)

For example:

val start = System.currentTimeMillis

val scn = scenario(“foo”)  
.asLongAs(session =\> (System.currentTimeMillis - start) \< 3600000) { // have users exit 1h after simulation start  
… // place scenario content here  
}

Cheers,

Stéphane

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [July 24, 2013, 7:23pm UTC](https://community.gatling.io/t/how-to-hold-load/491/8 "2013-07-24T19:23:11Z")

</div>

I accidentally implemented it: [https://github.com/excilys/gatling/issues/1307](https://github.com/excilys/gatling/issues/1307)

---

<div class="post-metadata">

**Author:** ![Esteban\_Aguirre](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@Esteban\_Aguirre](https://community.gatling.io/u/Esteban_Aguirre)\
**Post date:** [April 25, 2019, 2:46am UTC](https://community.gatling.io/t/how-to-hold-load/491/9 "2019-04-25T02:46:10Z")

</div>

I am curious to know how this function(asLongas) helps to solve and generate a load pattern like the second image of the buddy post.could you give some examples?
