Updating feeder file at before hook

Hello,

Im using JSON file as a Feeder for my simulation. At before() hook. I found that the content from feeder files was read and stored inside session API before code from `before()’ hook executed. At this stage (before hook) I’m updating the JSON file - and unfortunately those updates will be applied to second run of tests.

Is it possible to dynamically update feeder file during before() hook?

I found that the content from feeder files was read

true

and stored inside session API

false

The file is parsed when the Simulation is built. And the Simulation is built in the class’ constructor.

Please have a look at the doc: https://gatling.io/docs/gatling/reference/current/core/simulation/#hooks

The before hook is only called just after the constructor and before starting the test.

Thanks for update but still I have a doubts about the content of feeder file
I made a test where I change some details directly in the feeder file.
I want to update the content before the tests (that’s why I checked before hook). Unfortunately during simulation the session had default content of file, not the updates from before hook

Code for update was working fine, I can see that the file was updated

I’m also thinking about using Function for a feeder: Gatling - Feeders

And here inside the function read default content of my file, made some updates and returned updated content - will be fine? This time necessary to process feeders is somehow added to simulation time? And more important for every virtual user Function will be called? Or only once, globally for simulation?

And here inside the function read default content of my file, made some updates and returned updated content - will be fine? 

I don’t think so, every time when feed(feeder); will be called a file will be read - read from disk is slow and not efective.

This time necessary to process feeders is somehow added to simulation time?

@slandelle ? :slight_smile:

And more important for every virtual user Function will be called? Or only once, globally for simulation?

Every time when feed(feeder); is called so propably for every virtual user.

1 Like

Built-in CSV based feeders use an adaptive strategy by default, see gatling/gatling-defaults.conf at main · gatling/gatling · GitHub

  • files under 100MB are loaded eagerly before the Simulation starts
  • files above 100MB are read by chunks and hence can have a perf impact at runtime, in particular if you’re using slow disks

@slandelle
I tried with the CSV files and batch mode only but my feeder file contains only one record so all my tries failed, and it was not possible to dynamically change value inside feeder file during before hook.

Another question is about performance of transform() method: transform records

What If during transform I will update value of particular key using value stored at some let say Singleton class or any other class with the static field where my content will be updated once during before hook? It’s “heavy” task from simulation point of view?

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