Gatling csv weights

Hi,

My CSV looks like this

name, weight
apple,6
google,3
amazon,1

I want when I execute my simulation for 10 virtual user 6 will pick apple, 3 will pick google and 1 will pick amazon.

Can anyone help me out in solving this problem.

Hi @postmalone,

A feeder CSV based is specifically designed to load a line per virtual user.

So, either you change your CSV format, or you create your custom feeder.

Cheers!

if possible can you show me how? I am new to gatling and scala

suppose I did this

import scala.util.Random
val feeder = Iterator.continually {
  Map("apple" -> 6,"google" -> 3,"amazon" -> 1)
}

Then how can I put a logic so that once I execute my simulation for 10 virtual user 6 will pick apple, 3 will pick google and 1 will pick amazon.

Why choosing scala? Do you know you can use Gatling in Java or Kotlin?

We were working on Python Locust but in between team changes the framework to Gatling.
I am a python developer I don’t have any knowledge on Scala and Gatling.

We were working on Python Locust but in between team changes the framework to Gatling.

All the more! As a non Scala developer, you should use Gatling in Java, which is way more widely taught in CS than Scala.

but team picked Scala I can’t do anything now.

but team picked Scala I can’t do anything now.

:man_shrugging:

What you’re trying to achieve doesn’t look like a feeder to me. It looks like a word picker, either based on a random number generator (pick a number between 1 and 10) or on an incremental number and a modulo.
That would want the weights configured from a file in a CSV format has nothing to do with Gatling’s CSV feeder (not meant for this).

Trying writing it in Java and we can help you translate in Scala.

Instead of csv I am using map now

import scala.util.Random
val feeder = Iterator.continually {
  Map("apple" -> 6,"google" -> 3,"amazon" -> 1)
}

I can do this funtioanlity in python I have 0 knowledge of Java

I can do this funtioanlity in python I have 0 knowledge of Java

Then, I’m afraid that we from Gatling the company can’t help you without a consulting contract so we mentor and teach you.

You can also try to implement it in python, post it here and hope that some community member (not from Gatling the company) will help with translating to Java.

If we want to run for 60 sec:

import time

my_dict = {‘apple’: 6, ‘google’: 3, ‘amazon’: 1}

start_time = time.time()

while (time.time() - start_time) <= 60:
for key, value in my_dict.items():
for i in range(value):
print(key) // we can use this key and proceed with the code here I am printing it
time.sleep(1)

I have shared the python code can you help now with scala?

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