I'm a newcomer to Jmeter and want to be able to run some setup requests once only, in which some variables are setup, before I then run a set of further requests for as many users as I set in the Number of Users Thread Group. These users are passed the variables created in the Once Only Controller.

I've inherited a script as follows, using a Once Only Controller:

Script

If I set the Number of Threads as 10 to ramp up to 10 in one second and run for one minute, I expect the number of Samples (requests) made in the Once Only Controller to show as 1. I only want these requests to run once then subsequent requests to use the setup data.

Why then, when I run, do I see the samples as 10 in the requests that are set in the Once Only Controller:

aggregate report

Bear in mind there may be some fundamental misunderstandings given my I'm a newcomer to Jmeter.

Thanks

As per Once Only Controller documentation:

The Once Only Logic Controller tells JMeter to process the controller(s) inside it only once per Thread, and pass over any requests under it during further iterations through the test plan.

So each your Thread will execute Once Only Controller's children only once, no matter how many loops your thread group will have.

As you have 10 threads each of 10 threads will execute the requests once.

If you want to execute the request by only one thread - I would recommend going for If Controller instead

  1. Substitute Once Only Controller with an If Controller
  2. Use the following condition:

    ${__groovy(ctx.getThreadNum() == 0 &&  vars.getIteration() == 1,)}
    
  • thanks Dimitri. I understand a little better. Using your script, it appears now that the If Controller and its child requests do not get executed at all, using the same Thread number, ramp up and timeout. I just need it to run once as a setup job. Then all the subsequent requests to use the variables set in the If Controller – Steerpike Oct 10 at 11:48

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.