Can we generate one user -> multiple load in gatling?

Hello,

I have scenario like this -
I want to hit multiple data with one user using jdbcfeeder.
Is this achievable in gatling?

Hi @dbhombe1,

Do you consider calling feed multiple times?

  ScenarioBuilder scn = scenario("my scenario")
    .feed(feeder)
    .exec(http("get1").get("/1").queryParam("hello", "#{hello}"))
    .feed(feeder)
    .exec(http("get2").get("/2").queryParam("hello", "#{hello}"));

Or batch feed?

  ScenarioBuilder scn = scenario("my scenario")
    .feed(feeder, 2)
    .exec(http("get3").get("/3").queryParam("hello", "#{hello}"))

For more information, see the documentation: Gatling session scripting reference - feeders

Cheers!

hey thanks @sbrevet batch feed worked for me!
Still I have another doubt now.
I have a scenario like -
2 users & 4 records so for every user now I’m getting a list of 4 records by using batch feed.
Now I have to fetch one value at a time from this list & pass to rest of my api’s.
I’m unable to do it.
Kindly suggest.

Hi @dbhombe1,

Sorry, but it doesn’t make sense for me.

From my point of view, you asked to have a batch feed but you want to use it one at a time.

Can you write a step by step scenario (with dummy value) that I can understand what you mean?

What I can imagine from my hat: for a e-commerce website, you add 4 items at once in your basket (addAll(arrayWith4Items)), then you remove each item individually (remove(item1) then remove(item2), then remove(item3) and finally remove(item4))

Something like (warning: pseudocode):

  ScenarioBuilder scn = scenario("my e-commerce scenario")
  .feeder(feeder, 4)
  .exec(
    http("add all")
      .post("/basket")
      .formParam("items", "#{items}")
    ),
    foreach("#{items}", "item").on(
      http("delete one")
        .delete("/basket/#{item}")
    )
  );

Does that make sense in your use case?

Cheers!

sure @sbrevet

To clarify more giving an example -

ScenarioBuilder scn = scenario(“Simulation”)
.feed(jdbcFeeder(“url”,“username”,“pwd”,“select query”),numberOfRecords - consider 4);

        .exec(session -> {
            System.out.println("list per user : "+session.getList("value"));
            List<String> list=session.getList("value");
            for (int i=0;i<list.size();i++) {
                System.out.println("value in session - " + list.get(i));
            }
            return session;
        })
		
		 .exec(
                                http("Add data to system")
                                        .post("")
                                        .header("content-type", "application/json")
                                        .body(RawFileBody("data.json"))
                                        .body(StringBody(session -> "{\n" +
                                                "  \"Sr No\": 01,\n" +
                                                "  \"value\": list.get(i),\n" + ,\n" + "}")) -- I want to fetch data here from jdbcFeeder one by one for every user from value list fetched for every user
                        )
						
{
    setUp(scn.injectOpen(atOnceUsers(2))).protocols();

}

Let me know if I was able to clarify my scenario to you.
Thanks!

Hi @dbhombe1,

If you need to send a POST request by item in your list, foreach is the way to go.
If you need to format your body containing every item at once, perhaps you need a templating engine, did you give a try to PebbleStringBody?

Cheers!

I tried with foreach but its giving me only one user list of values here & not other users.I need values from all user lists & pass those to further post api’s.

.foreach(session → list, “value”).on(
exec(session → {
for (int i=0;i<list.size();i++) {
System.out.println("value is - " + list.get(i));
}
return session;
}
)
);

Sorry, I don’t understand (once again).

A scenario is defining the steps one virtual user will do. Hence, the session (associated with the virtual user in progress) knows only their own values.

Does your real user know the values for everyone? If yes, how?

Blind guess: they don’t know the values for other users, so, the application should know the values.
Which application (the application under test or your own code) is up to you.

Cheers!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.