JMeter - why only one controller works more than once

I added two queries: one for logging in to save the session ID and another for checking the load test, which requires a session ID.

I made a login request only once, adding it as a child of the controller only once.

But when I check this by adding about 100 or 200 threads, the login also takes so long. I want to execute a login request only for the initial thread. Is it possible? Below I have added a hierarchy of tests.

ThreadGroup: HTTP request default HTTP cookie manager once only controller login HTTP request HTTP request for number of users 
+9
source share
6 answers

The ONLY ONCE controller does not work as you think.

It runs "only once" PER THREAD. That way, if you have 100 threads, it will execute 100 times.

If you want it to run ONCE PER TEST, follow these steps:

 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 

Please note: if you need to share any variables between thread groups A and B, you need to set them as properties. Variables cannot be shared between stream groups, but properties can. To do this, you need to use the property function.

The __setProperty function automatically saves this value as a global variable. The easiest way to initiate __setProperty is to create a Beanshell script POST processor as a child of the sampler that creates the cookie in THREAD A. To get the value in THREAD B, you add the __property function as the VALUE value for the parameter that requires the cookie value.

The Beanshell script will 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 

The code above will always have the same meaning for COOKIENAME, which is less than an idea. So, we have to make sure that "COOKIEVALUE" is dynamic. I would recommend placing a POST-PROCESSOR regular expression to retrieve the cookie value and then passing it to 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 

And our beanshell script now looks like this:

 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 

User Manual Links:

+28
source

In newer versions of JMeter, you can add a setUp Thread Group, which does exactly what you need.

A special type of ThreadGroup that can be used to perform pre-test actions. The behavior of these threads is exactly like the usual element of a thread group. The difference is that these types of threads are executed before the test proceeds to execute regular topic groups.

http://jmeter.apache.org/usermanual/component_reference.html#setUp_Thread_Group

+4
source

You can put the “Login HTTP request” request in the Once Only controller and the regular “HTTP request” in the Loop controller. Now you can set the loop to execute the HTTP request 100 or 200 times. See: jmeter.apache.org/usermanual/component_reference.html#Loop_Controller

Use timers to make a more realistic test. Suppose you want 200 requests to be executed after 120 seconds, you can pause each request in 120/200 seconds. Most timers work with miliseconds, so you can make this number (120/200 * 1000) miliseconds. See: jmeter.apache.org/usermanual/component_reference.html#timers

You can also create a separate group of Setup threads in which you make your login and make 200 threads in another thread group. Check out this article: http://www.informit.com/guides/content.aspx?g=java&seqNum=520

All this information will help you in the right direction. Good luck

+2
source

Only one controller works as explained by BlackGaff.

What you are trying to do seems wrong, as it will mean that you are authenticating your 100 users with the same username / password.

But if you still want to do this, you can use setupThread with one user, it is usually useful for any init task when testing, but in no case does it answer your requirements, which seem wrong to me.

0
source

In Jmeter 2.9, you can use "Only one controller" and "Loop controller" for this.

It is wonderful!

Franky

0
source
 ${__groovy(${__threadNum} == 1 && vars.getIteration() == 1)} 
0
source

All Articles