I would like to inject random no. of users in Gatling. For example,
For first 10 secs, 100 users
For next 15 secs, 25 users,
For next 2 secs, 1000 users and so on..
random time with random number of users
One complex workaround I have found is as follows:
val r=new scala.util.Random
setUp(
scn.inject(
constantUsersPerSec(10) during(10 seconds) randomized,
constantUsersPerSec(10+r.nextInt(500)) during(15 seconds) randomized,
constantUsersPerSec(210+r.nextInt(500)) during(25 seconds) randomized,
constantUsersPerSec(510+r.nextInt(520)) during(55 seconds) randomized,
constantUsersPerSec(170+r.nextInt(100)) during(5 seconds) randomized,
constantUsersPerSec(270+r.nextInt(1010)) during(5 seconds) randomized,
constantUsersPerSec(710+r.nextInt(5100)) during(1 minute) randomized,
constantUsersPerSec(5+r.nextInt(40)) during(100 seconds) randomized,
constantUsersPerSec(710+r.nextInt(5200)) during(15 seconds) randomized,
constantUsersPerSec(0+r.nextInt(20)) during(10 seconds) randomized,
constantUsersPerSec(10) during(10 seconds) randomized,
constantUsersPerSec(10+r.nextInt(500)) during(15 seconds) randomized,
constantUsersPerSec(210+r.nextInt(500)) during(25 seconds) randomized,
constantUsersPerSec(510+r.nextInt(520)) during(55 seconds) randomized,
constantUsersPerSec(170+r.nextInt(100)) during(5 seconds) randomized,
constantUsersPerSec(270+r.nextInt(1010)) during(5 seconds) randomized,
constantUsersPerSec(710+r.nextInt(5100)) during(1 minute) randomized,
constantUsersPerSec(5+r.nextInt(40)) during(100 seconds) randomized,
constantUsersPerSec(710+r.nextInt(5200)) during(15 seconds) randomized,
constantUsersPerSec(1) during(10 seconds),
).protocols(kafkaConf))
Is there any simple way to do this?
In other words, is there any way to inject in a loop?
PS: I tried the repeat()
for a scenario, but that is a different thing altogether. Instead of calling once, it calls n times ie it does the action n
times for every user.
the .inject method can take an array of injection steps, so you can just use a function to generate that array
val r=new scala.util.Random
setUp(
scn.inject(
(1 to 10).map(i => constantUsersPerSec(r.nextInt(500)) during (r.nextInt(30) seconds) randomized)
)
).protocols
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.