# How to correct user injection?

**URL:** <https://community.gatling.io/t/how-to-correct-user-injection/6839>\
**Category:** Gatling (Open-Source)\
**Created:** [June 10, 2022, 2:26pm UTC](https://community.gatling.io/t/how-to-correct-user-injection/6839 "2022-06-10T14:26:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmytro](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@Dmytro](https://community.gatling.io/u/Dmytro)\
**Post date:** [June 10, 2022, 2:26pm UTC](https://community.gatling.io/t/how-to-correct-user-injection/6839/1 "2022-06-10T14:26:39Z")

</div>

Hello everyone, I’m not that proficient with user injections so I would like to ask for some help. We have a scenario by which users should be injected:  
30 minutes - stable load, then 30 minutes of spike with a big number of users and that repeats again.

```auto
setUp(TestScenario.scenario
                .injectOpen(
                        constantUsersPerSec(ConfigHelper.USERS_PER_SECOND).during(Duration.ofMinutes(ConfigHelper.CONSTANT_USER_RATE_DURATION)),
                        stressPeakUsers(ConfigHelper.SPIKE_USERS_NUMBER).during(Duration.ofMinutes(ConfigHelper.SPIKE_DURATION)),
                        constantUsersPerSec(ConfigHelper.USERS_PER_SECOND).during(Duration.ofMinutes(ConfigHelper.CONSTANT_USER_RATE_DURATION)),
                        stressPeakUsers(ConfigHelper.SPIKE_USERS_NUMBER).during(Duration.ofMinutes(ConfigHelper.SPIKE_DURATION)),
                        constantUsersPerSec(ConfigHelper.USERS_PER_SECOND).during(Duration.ofMinutes(ConfigHelper.CONSTANT_USER_RATE_DURATION))
                )
        ).maxDuration(Duration.ofMinutes(ConfigHelper.DURATION))
                .protocols(ConfigHelper.httpProtocol)
                .assertions(global().successfulRequests().percent().gt(ConfigHelper.SUCCESS_RATE));

```

We have executed this code with parameters such as:  
Users per second: 15  
Constant user rate duration: 30  
Spike users number: 400  
Spike duration: 30  
Test Duration: 150

But numbers of users were not like a would expect:

 ![Screenshot from 2022-06-10 17-24-44](https://europe1.discourse-cdn.com/flex013/uploads/gatling2/original/1X/e09cc7e794b22317828a5a1abe91498069f8ae2d.png)

I wanted to create a quite opposite picture from the one that I provided. Like 200 or so users during constant rate and big spike with 400 users during the spike.

So, I would like to have some guidance, thank you in advance 😄

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [June 10, 2022, 3:45pm UTC](https://community.gatling.io/t/how-to-correct-user-injection/6839/2 "2022-06-10T15:45:23Z")

</div>

You misunderstand `stressPeakUsers`. Quoting the [documentation](https://gatling.io/docs/gatling/reference/current/core/injection/#open-model):

> Injects a given number of users following a smooth approximation of the [heaviside step function](http://en.wikipedia.org/wiki/Heaviside_step_function) stretched to a given duration.

With your values, each peak will inject a **total** of 400 users. Over 30 minutes, that’s merely ~1 every 5 seconds.

---

<div class="post-metadata">

**Author:** ![Dmytro](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@Dmytro](https://community.gatling.io/u/Dmytro)\
**Post date:** [June 12, 2022, 10:34am UTC](https://community.gatling.io/t/how-to-correct-user-injection/6839/3 "2022-06-12T10:34:11Z")

</div>

Oh, so I was wondering why is it happening…would you suggest something different so that I can use it to simulate the scenario that we want? Or do we just need to increase the number of users?

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [June 12, 2022, 11:55am UTC](https://community.gatling.io/t/how-to-correct-user-injection/6839/4 "2022-06-12T11:55:54Z")

</div>

Just increase the number of users.  
A 30 min spike is really not a spike:slight\_smile:
