I’m working on performance testing a multi-tenant application using Apache JMeter. I want to simulate load coming from three different clients, where each client’s data is stored in a separate CSV file. The load should be distributed like this:
- Client 1: 60%
- Client 2: 30%
- Client 3: 10%
All CSV files have the same structure (columns), but contain different data per client.
My Goal:
I want each thread to randomly and proportionally pick data from the appropriate CSV file based on the percentages above and use it in the HTTP requests without data overlap or inconsistency.
What I Tried:
Approach 1: Dynamically set file path using a variable
My Jmeter Test Plan structure is,
Test Plan
|-- User Defined Variables
|-- CSV Data Set Config
|-- Stepping Thread Group
|-- |-- JSR223 PreProcessor
|-- |-- HTTP Request Sampler 1
|-- |-- HTTP Request Sampler 2
|-- |-- HTTP Request Sampler n
|-- View Result Tree
|-- Summary Report
In the Test Plan, I have a variable path
defined in User Defined Variables
as:
path = D:/jmeter/project
I then set the Filename
in CSV Data Set Config
to ${csvFile}
.
Inside a JSR223 PreProcessor
, I tried 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 issue is, even though csvFile
gets set correctly in the JSR223 PreProcessor
, the CSV Data Set Config
doesn’t pick up the value dynamically.
Approach 2: Dynamically set file path using a variable and place the CSV Data Set Config after the JSR223 PreProcessor
My Jmeter Test Plan structure is,
Test Plan
|-- User Defined Variables
|-- Stepping Thread Group
|-- |-- JSR223 PreProcessor
|-- |-- CSV Data Set Config
|-- |-- HTTP Request Sampler 1
|-- |-- HTTP Request Sampler 2
|-- |-- HTTP Request Sampler n
|-- View Result Tree
|-- Summary Report
Still the result is the same as in Approach 1.
I suspect it’s due to the execution order, as JMeter processes the CSV Data Set Config before the PreProcessor runs.
My Question:
What is the correct way in JMeter to:
- Dynamically and proportionally distribute threads across multiple CSV files
- Ensure clean separation of data per thread (no variable conflicts)
- Avoid data overlap or race conditions between threads
Note: I cannot share actual screenshots or project files due to employer restrictions, but I’m looking for a JMeter-safe and scalable way to simulate this kind of weighted load across clients using separate CSV files or anything other suggestion for tackling this issue.
Any ideas or recommendations for managing this effectively?
Source: Read More