JMeter-为什么只有一次控制器运行一次以上 [英] JMeter - Why once only controller runs more than once
问题描述
我添加了两个请求,一个用于登录以存储会话ID,另一个请求用于检查需要会话ID的负载测试.
I added two request one for login to store the session id and another request to check the load test which requires session id.
我通过将其添加为仅一次控制器的子代来发出一次登录请求.
I made login request as once only, by adding it as a child for once only controller.
但是,当我通过添加大约100或200个线程对其进行测试时,登录也会运行那么长时间.我只想为启动线程运行登录请求.是否有可能?在下面,我添加了我的测试用例层次结构.
But when I test it by adding about 100 or 200 thread the login is also running that much of time. I want to run login request for only starting thread. Is it possible? Below I added my test case hierarchy.
ThreadGroup:
HTTP request default
HTTP cookie manager
once only controller
login HTTP request
HTTP request for number of users
推荐答案
仅一次"控制器无法按您认为的方式工作.
The "ONLY ONCE" controller doesn't work the way you think it does.
按线程运行仅一次".因此,如果您有100个线程,它将运行100次.
It runs "only once" PER THREAD. Thus, if you have 100 threads, it will run 100 times.
如果您希望它一次运行一次,请执行以下操作:
If you want it to run ONCE PER TEST, do the following:
Test Plan (Set thread groups to "run consecutively"
- Cookie Manager
- Thread Group A (1 thread, 1 loop)
- - - Login Logic
- Thread Group B
- - - Rest of test
请注意,如果需要在线程组A和线程组B之间共享任何变量,则需要将它们设置为属性.变量不能在线程组之间共享,但是属性可以共享.您需要为此使用属性功能.
Please note, if you need to share any variables between threadgroups A and B, you need to set them as properties. Variables cannot be shared between thread groups, but properties can. You'll need to use the properties function for this.
函数__setProperty自动将值存储为全局变量.初始化__setProperty的最干净方法是创建一个POST处理器Beanshell脚本,作为在THREAD A中创建cookie的采样器的子级.要在THREAD B中检索值,请添加__property函数作为该参数的VALUE需要Cookie值.
The function __setProperty automatically stores the value as a global variable. The cleanest way to initiate __setProperty would be to create a POST-processor Beanshell script as a child to the sampler that creates the cookie in THREAD A. To retrieve the value in THREAD B, you add the __property function as the VALUE for the parameter that needs the cookie value.
Beanshell脚本如下所示:
The Beanshell script would look something like this:
props.put("COOKIENAME","COOKIEVALUE"); //creates a property "COOKIENAME" with value "COOKIEVALUE"
print(props.get("COOKIENAME")); //prints the value out to the console
上面的代码对于COOKIENAME总是具有相同的值,而不是想法.因此,我们需要确保"COOKIEVALUE"是动态的.我建议您放置一个POST-PROCESSOR正则表达式以提取cookie值,然后将其传递到beanshell脚本中.
The code above would always have the same value for COOKIENAME, less then idea. So, we need to make sure "COOKIEVALUE" is dynamic. I would recommend putting a POST-PROCESSOR regular expression to extract the cookie value, and then pass that into the beanshell script.
所以,我们的测试计划现在看起来像这样:
So, our test plan now looks like this:
Test Plan (Set thread groups to "run consecutively"
- Thread Group A (1 thread, 1 loop)
- - - Login Logic
- - - - - Regex to grab cookie, store as "regexCookie"
- - - - - Beanshell to set property
- Thread Group B
- - - Rest of test
我们的beanshell脚本现在看起来像:
And our beanshell script now looks like:
props.put("COOKIENAME",vars.get("regexCookie")); //creates a property "COOKIENAME" with value from "regexCookie"
print(props.get("COOKIENAME")); //prints the value out to the console
链接到用户手册:
- http://jmeter.apache.org/usermanual/functions.html#__setProperty
- http://jmeter.apache.org/usermanual/functions.html#__property
- http://jmeter.apache.org/usermanual/component_reference.html#BeanShell_PostProcessor
- http://jmeter.apache.org/usermanual/functions.html#__setProperty
- http://jmeter.apache.org/usermanual/functions.html#__property
- http://jmeter.apache.org/usermanual/component_reference.html#BeanShell_PostProcessor
这篇关于JMeter-为什么只有一次控制器运行一次以上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!