当前位置:网站首页>jmeter 性能测试用 csv,这个坑有些扯蛋
jmeter 性能测试用 csv,这个坑有些扯蛋
2022-06-12 01:03:00 【小梧敲代码】
很多人在使用 jmeter 做接口测试、自动化测试和性能测试时,都喜欢用 CSV 数据文件设置功能,来读取准备好的测试数据。虽然这种方法并不是最优方案,在我们的性能测试课程中,讲解了更优的方案,但是,没有上过我们的课的测试人员,还是很普遍的使用 CSV 方式。
今天,就来给大家讲一个用 CSV 准备测试数据的一个巨坑和解决办法。
jmeter 做测试,要想读取准备好的测试数据文件,如果你只想到 CSV 这一种方法,那就用‘CSV Data Set Config’这个元件,千万不要去用 csvRead 函数,用这个函数,你被坑死了,请别说我没提醒你。
但是,使用‘CSV Data Set Config’这个元件,每次只能从第 1 行数据开始读取,或忽略首行从第 2 行开始,没有办法从不定行开始。
每次从第 1 行开始取值,在日常低并发的性能测试中,是没有任何问题的,因为此时你只需要运行一个 jmeter 就可以, 但是,如果你想做高并发的性能测试,需要有多个 jmeter 同时运行,构成分布式来向服务器发起请求,这时候就有问题了。
因为,采用分布式,在多台机器上同时运行 jmeter,每台机器都会从第 1 行开始读取你准备的测试文件,那么,就会出现同时多个线程使用同一个测试数据向服务器发起请求,这很可能导致你们的被测试服务出现各种异常。
你是不是曾经出现使用分布式进行性能测试,出现很多 4xx 系列错误,而单机执行性能测试却没有;你是不是曾经出现,分布式时错误率升高,而单机时,同并发数,错误率要低很多;你是不是曾经出现,分布式请求,服务端日志,有大量锁冲突?
这些问题,如果你脚本中使用了‘CSV Data Set Config’,那么这些错误,很可能就是因为这个元件每次读数据只能从第 1 行开始读取的原因造成的。
这个坑,我曾经也遇到了,而且一度让我痛苦了几天,不过,后来我找到 4 种解决办法,今天,我就来给大家讲一种技术难度最低的方法。
️打开 jmeter 的插件管理,在 ‘available plugins’中搜索‘CSV’,勾选一个叫 ‘Random CSV Data Set’的插件,点击右下角的‘Apply Changes and Restart JMeter’下载安装这个插件。待下载成功自动重启之后,在 jmeter 的配置元件中,我们将找到‘bzm - Random CSV Data Set Config’元件。
你可以点击**下面的‘Test CSV Reading’来看下数据的顺序,你会发现,每次取的数据顺序都是不一样的。**这样,就很好解决了分布式时取数相同的问题了。方法非常简单。
接下来,我们来对比看下这个元件的性能。
首先添加 ‘CSV Data Set Config’元件,读取一份大于 10000 行的数据文件,定义一个变量接收,然后,用一个调试取样器,应用这个变量, 设在 1000 的并发用户,持续运行 120s,保存脚本,采用 CLI 模式运行,查看运行时资源使用情况。

从监控到数据看,1000 的并发,120 秒中内,总共执行了 59830295 次请求,平均每秒 498141.6 次/s,我本机 CPU 使用率上升到约 48.3%,内存使用率约为 26.8%。
现在,把元件换成 ‘bzm - Random CSV Data Set Config’,其他都不变了。采用 CLI 模式来运行,查看监控数据。

从监控到数据看,1000 的并发,120 秒中内,总共执行了 20860718 次请求,平均每秒 172912.8 次/s,我本机 CPU 使用率上升到约 66.5%,内存使用率约为 26.7%。
️从两个元件的测试结果来看,官方的 CSV Data Set Config 性能要优于 bzm - Random CSV Data Set Config,实际工作中,你可以根据你的实际情况来选择。
最后感谢每一个认真阅读我文章的人,下面这个网盘链接也是我费了几天时间整理的非常全面的,希望也能帮助到有需要的你!

这些资料,对于想转行做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。希望对大家有所帮助……
如果你不想一个人野蛮生长,找不到系统的资料,问题得不到帮助,坚持几天便放弃的感受的话,可以点击下方小卡片加入我们群,大家可以一起讨论交流,里面会有各种软件测试资料和技术交流。
| 点击文末小卡片领取 |
敲字不易,如果此文章对你有帮助的话,点个赞收个藏来个关注,给作者一个鼓励。也方便你下次能够快速查找。
自学推荐B站视频:
零基础转行软件测试:25天从零基础转行到入职软件测试岗,今天学完,明天就业。【包括功能/接口/自动化/python自动化测试/性能/测试开发】
边栏推荐
- [tools] spacing JS measurement spacing
- Jeecgboot 3.1.0 release, enterprise low code platform based on code generator
- be based on. NETCORE development blog project starblog - (11) access statistics
- The latest report of Xinsi technology shows that 97% of applications have vulnerabilities
- Comparison of OpenCV basic codes of ros2 foxy~galactic~humble
- 基于.NetCore开发博客项目 StarBlog - (11) 实现访问统计
- Some suggestions on writing code to reproduce the paper!
- Explore table component virtualization
- Lambda intermediate operation distinct
- Tencent programmer roast: 1kW real estate +1kw stock +300w cash, ready to retire at the age of 35
猜你喜欢

Enterprise wechat H5_ Integrated message decryption class, message push get and post callback processing

Inventory: more than 20 typical safety incidents occurred in February, with a loss of nearly $400million
![Article 7: Design of multifunctional intelligent trunk following control system | undergraduate graduation project - [module device selection, list and data]](/img/9f/4337d5064d9fc93da4c17784a3accc.jpg)
Article 7: Design of multifunctional intelligent trunk following control system | undergraduate graduation project - [module device selection, list and data]

Jeecgboot 3.1.0 release, enterprise low code platform based on code generator

Argodb 3.2 of star ring technology was officially released to comprehensively upgrade ease of use, performance and security

Ms-hgat: information diffusion prediction based on memory enhanced sequence hypergraph attention network

Flutter uses local pictures

Before applying data warehouse ODBC, you need to understand these problems first

1、 Getting started with flutter learn to write a simple client
![Is interface automation difficult? Take you from 0 to 1 to get started with interface automation test [0 basic can also understand series]](/img/78/f36cdc53b94dc7da576d114a3eb2a6.png)
Is interface automation difficult? Take you from 0 to 1 to get started with interface automation test [0 basic can also understand series]
随机推荐
Vscode - the problem of saving a file and automatically formatting the single quotation mark 'into a double quotation mark'
Henan Zhongchuang - from cloud to edge, how edge computing enables data centers
Lambda intermediate operation skip
At the digital data nextionbi online conference, traditional enterprises showed their in-depth understanding of data analysis
QApplication a (argc, argv) and exec() in the main function of QT getting started
Global and Chinese chromatographic silica gel resin industry research and investment direction forecast report 2022 Edition
LabVIEW Arduino电子称重系统(项目篇—1)
Building circuits on glass
如何优化PlantUML流程图(时序图)
[foreign enterprise test interview and written examination] share the whole process of 8 rounds of 30k+ foreign enterprise interview
Recurrent+Transformer 视频恢复领域的‘德艺双馨’
Weekly CTF 第一周:神奇的磁带
Lambda中间操作map
Tianjin Port coke wharf hand in hand map flapping software to visually unlock the smart coke port
Breadth first search depth first search dynamic programming leetcode topic: delivering information
Flutter 使用本地图片
验证码是自动化的天敌?看看阿里P7大神是怎么解决的
Why are the values of ordereddict not equal- Why are the values of an OrderedDict not equal?
How to make scripts executable anywhere
[tools] spacing JS measurement spacing