如何在一个Jmeter线程组中使用多个CSV文件并对它们进行迭代

huangapple go评论54阅读模式
英文:

How to use multiple csv files in one Jmeter thread group and iterate over them

问题

我有以下情况:
我有四个CSV文件,每个文件包含20,000至30,000行。
它们都包含相同的行,例如:

userGroup1.csv - 包含用户名、密码、密钥

userGroup2.csv - 包含用户名、密码、密钥

当进行性能测试时,我需要从csv1发送请求1,从csv2发送请求2(使用那里的第一行),依此类推。

一个可能的解决方案是创建4个线程组,每个线程组拥有自己的CSV文件。
但如果我不想增加线程组,我有哪些选择?

我考虑将4个CSV文件合并成一个,但如果其中1个CSV文件发生更改,我也需要更改合并的文件。

英文:

I have the following case:
I have four csv files, which contains 2000-3000 thousands each.
All of them have identical rows, for examples:

userGroup1.csv - which contains username, password, secret

userGroup2.csv - which contains username, password, secret

And when I do the perf test I need to send request1 from csv1, request2 from csv2 (using row1 there) and so on.

One possible solution is to have 4 thread groups, each one having their own csv file.
But if I don't want to multiply the thread groups, what are my options?

I was thinking to merge 4 csv files into one, but then if 1 of the csv-files changes, I need to change the merged file as well.

答案1

得分: 0

如果您有1个请求,并希望在每次迭代中从下一个CSV文件中读取下一行 - 这不是您可以使用JMeter的CSV数据集配置来实现的

查看__CSVRead()函数

  1. 创建filenames.csv文件,内容如下:

    userGroup1.csv
    userGroup2.csv
    userGroup3.csv
    userGroup4.csv

  2. 将CSV数据集配置添加到您的线程组并进行如下配置:

    如何在一个Jmeter线程组中使用多个CSV文件并对它们进行迭代

    这意味着CSV数据集配置将在每个虚拟用户的每次迭代中读取下一行

  3. 每当您需要从CSV文件中读取值时,请使用以下构造:

    ${__CSVRead(${filename},0)}

    它将从CSV文件中的第一个“列”中读取值,如果要读取第二列 - 使用${__CSVRead(${filename},1)}

    当您需要切换到下一行时,请调用${__CSVRead(${filename},next)}

有关JMeter函数概念的更多信息:Apache JMeter函数 - 简介

英文:

If you have 1 request and want it to read the next line from the next CSV file on each iteration - this is not something you can achieve using JMeter's CSV Data Set Config

Take a look at __CSVRead() function

  1. Create filenames.csv file with the following contents:

    userGroup1.csv
    userGroup2.csv
    userGroup3.csv
    userGroup4.csv
    
  2. Add CSV Data Set Config to your Thread Group and configure it like:

    如何在一个Jmeter线程组中使用多个CSV文件并对它们进行迭代

    it means that the the CSV Data Set Config will read the next line on each iteration of each virtual user

  3. Whenever you need to read the value from the CSV file use the following construction:

    ${__CSVRead(${filename},0)}
    

    it will read value from the first "column" in the CSV file, if you want to read 2nd column - use ${__CSVRead(${filename},1)}

    when you want to switch to the next line - call ${__CSVRead(${filename},next)}

More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

答案2

得分: 0

处理你的问题的简单解决方案是创建4个CSV数据集配置并提供不同的变量名称,然后在线程组中创建不同的采样器来处理相应的CSV文件 - 类似于这样:

你可以看到每个采样器根据其变量名称处理CSV文件。

英文:

The easy solution to handle your problem is by creating 4 csv dataset configs and providing different variable names
如何在一个Jmeter线程组中使用多个CSV文件并对它们进行迭代

如何在一个Jmeter线程组中使用多个CSV文件并对它们进行迭代

and in the thread group create different samplers to process the respective csvs - something like
如何在一个Jmeter线程组中使用多个CSV文件并对它们进行迭代

you can see each sampler process the csv according to its variable names

如何在一个Jmeter线程组中使用多个CSV文件并对它们进行迭代

huangapple
  • 本文由 发表于 2023年3月9日 19:37:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75684072.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定