Tuesday, June 17, 2025

efficiency – Learn how to configure JMeter to dynamically learn knowledge from considered one of a number of CSV recordsdata primarily based on load distribution?


I am engaged on efficiency testing a multi-tenant software utilizing Apache JMeter. I wish to simulate load coming from three completely different purchasers, the place every shopper’s knowledge is saved in a separate CSV file. The load ought to be distributed like this:

  • Shopper 1: 60%
  • Shopper 2: 30%
  • Shopper 3: 10%

All CSV recordsdata have the identical construction (columns), however include completely different knowledge per shopper.

My Purpose:
I need every thread to randomly and proportionally choose knowledge from the suitable CSV file primarily based on the odds above and use it within the HTTP requests with out knowledge overlap or inconsistency.

What I Tried:

Method 1: Dynamically set file path utilizing a variable
My Jmeter Take a look at Plan construction is,

Take a look at Plan
|-- Person Outlined Variables
|-- CSV Knowledge Set Config
|-- Stepping Thread Group
|-- |-- JSR223 PreProcessor
|-- |-- HTTP Request Sampler 1
|-- |-- HTTP Request Sampler 2
|-- |-- HTTP Request Sampler n
|-- View Outcome Tree
|-- Abstract Report

Within the Take a look at Plan, I’ve a variable path outlined in Person Outlined Variables as:

path = D:/jmeter/undertaking

I then set the Filename in CSV Knowledge Set Config to ${csvFile}.

Inside a JSR223 PreProcessor, I attempted setting the csvFile variable like this:

def randomValue = Math.random()
if (randomValue < 0.6) {
    vars.put('csvFile', "${path}/file1.csv")
} else if (randomValue < 0.9) {
    vars.put('csvFile', "${path}/file2.csv")
} else {
    vars.put('csvFile', "${path}/file3.csv")
}

The problem is, despite the fact that csvFile will get set accurately within the JSR223 PreProcessor, the CSV Knowledge Set Config does not choose up the worth dynamically.

Method 2: Dynamically set file path utilizing a variable and place the CSV Knowledge Set Config after the JSR223 PreProcessor

My Jmeter Take a look at Plan construction is,

Take a look at Plan
|-- Person Outlined Variables
|-- Stepping Thread Group
|-- |-- JSR223 PreProcessor
|-- |-- CSV Knowledge Set Config
|-- |-- HTTP Request Sampler 1
|-- |-- HTTP Request Sampler 2
|-- |-- HTTP Request Sampler n
|-- View Outcome Tree
|-- Abstract Report

Nonetheless the end result is similar as in Method 1.

I think it is as a result of execution order, as JMeter processes the CSV Knowledge Set Config earlier than the PreProcessor runs.

My Query:

What’s the appropriate method in JMeter to:

  • Dynamically and proportionally distribute threads throughout a number of CSV recordsdata
  • Guarantee clear separation of knowledge per thread (no variable conflicts)
  • Keep away from knowledge overlap or race circumstances between threads

Notice: I can not share precise screenshots or undertaking recordsdata because of employer restrictions, however I am searching for a JMeter-safe and scalable technique to simulate this type of weighted load throughout purchasers utilizing separate CSV recordsdata or something different suggestion for tackling this situation.

Any concepts or suggestions for managing this successfully?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

PHP Code Snippets Powered By : XYZScripts.com