简体   繁体   English

Jmeter - 当有多个线程正在运行时,来自 JSON 提取器的变量有时不起作用

[英]Jmeter - when there are number of threads are running, the variable from JSON extractor is not working sometimes

I am now using Jmeter to run the test of APIs.我现在使用 Jmeter 来运行 API 测试。

The situation is that I have a login Api which will return a token inside response.情况是我有一个登录 API,它将在响应中返回一个令牌。 I use a JSON extractor to save the token as a variable.我使用 JSON 提取器将令牌保存为变量。 Then, I use the ${token} is the header of other requests.然后,我使用 ${token} 是其他请求的标头。

However, I found that when I was trying to run 40-50 threads, the ${token} in some threads would be empty, and caused a high error rate.但是,我发现当我尝试运行 40-50 个线程时,某些线程中的 ${token} 会为空,导致错误率很高。

Therefore, may I ask is there any method to solve it and why?因此,请问有什么方法可以解决它,为什么?

Thanks very much.非常感谢。

Try saving full response from the Login API, most probably your server gets overloaded and cannot return the token and returning some error message instead.尝试保存来自登录 API 的完整响应,很可能您的服务器过载并且无法返回令牌并返回一些错误消息。

There are following options:有以下选项:

  1. If you're running JMeter in command-line non-GUI mode you can amend JMeter's Results File Configuration to store the results in XML form and include the response data, add the next lines to user.properties file:如果您在 命令行非 GUI 模式下运行 JMeter,您可以修改 JMeter 的结果文件配置,以 XML 形式存储结果并包含响应数据,将下一行添加到user.properties文件:

     jmeter.save.saveservice.output_format=xml jmeter.save.saveservice.response_data=true

    and when you run your test next time the .jtl results file will contain response bodies for all the requests.并且当您下次运行测试时, .jtl 结果文件将包含所有请求的响应正文。

  2. Another option is using a Listener like Simple Data Writer configured like:另一种选择是使用像Simple Data Writer这样的监听器,配置如下:

    在此处输入图像描述

    and when you run the test the responses.xml file will contain the response data当您运行测试时, responses.xml文件将包含响应数据

Both .jtl results file and responses.xml can be inspected using View Results Tree listener .jtl 结果文件和response.xml 都可以使用查看结果树侦听器进行检查

More information: How to Save Response Data in JMeter更多信息: 如何在 JMeter 中保存响应数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM