JMeter性能测试优化:数据迭代方式实现多线程独立取值,提高测试场景真实性

403 阅读1分钟

取值的迭代方式

csv data set config对于数据的迭代方式,官网是这样解释的:

By default, the file is only opened once, and each thread will use a different line from the file. However the order in which lines are passed to threads depends on the order in which they execute, which may vary between iterations. Lines are read at the start of each test iteration. The file name and mode are resolved in the first iteration.

也就是说,csv文件在整个脚本运行过程中是只打开一次的,每个线程的取值都是从文件开头开始的。线程之间的数据迭代顺序是互不影响的。

image.png

image.png

多个线程分别使用不同的数据

如果有这样的测试场景,修改一条记录的状态,但是不能将状态修改为当前状态,这个时候,你可以先把状态改成状态A,然后再将状态改成状态B,这样的话,就不能够发生不同的线程都去取同一个值的情况,可以为不同线程配置不同的迭代数据。

官网提供这样的做法,为不同的线程配置不同的csv文件:

See the description of the Share mode below for additional options. If you want each thread to have its own set of values, then you will need to create a set of files, one for each thread. For example test1.csv, test2.csv, …, testn.csv. Use the filename test${__threadNum}.csv and set the "Sharing mode" to "Current thread".

将文件命名为test1.csv, test2.csv

image.png

在填写csv data set config时,filename填写为 test${__threadNum}.csv,

image.png

如果是分布式测试,如何配置csv文件

将filename给定为绝对路径,然后将csv文件都放到每一台负载机这一个文件下。