jmeterjmeter-5.0threadgroup

JMeter: passing quantity of threads as a property


I have the same problem as in the In Jmeter how do I set a variable number of threads using a beanshell sampler variable?, however it's not being solved by the same solution. I have the initial setUp Thread Group and Regular Thread Group (which performs actions)

1

In the Threads init JSR223 sampler I am putting the following code:

props.put("threads", 5);
props.put("rampup", 5); 

which works perfectly, as I see it in the Debug Sampler:

JMeterProperties:
<...>
jmeter.version=5.6.2
not_in_menu=org.apache.jmeter.protocol.mongodb.sampler.MongoScriptSampler,org.apache.jmeter.protocol.mongodb.config.MongoSourceElement,org.apache.jmeter.timers.BSFTimer,org.apache.jmeter.modifiers.BSFPreProcessor,org.apache.jmeter.extractor.BSFPostProcessor,org.apache.jmeter.assertions.BSFAssertion,org.apache.jmeter.visualizers.BSFListener,org.apache.jmeter.protocol.java.sampler.BSFSampler,org.apache.jmeter.protocol.http.control.gui.SoapSamplerGui
rampup=7
remote_hosts=127.0.0.1
sampleresult.timestamp.start=true
summariser.name=summary
system.properties=system.properties
threads=7
upgrade_properties=/bin/upgrade.properties
user.properties=user.properties
<...>

However when I put property to the thread group settings, it is not read:

1

It doesn't work neither as ${__P(threads)} nor as ${__Property(threads)}

What I see in log is:

2023-08-25 17:44:40,166 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=2 delayedStart=false
2023-08-25 17:44:40,167 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2023-08-25 17:44:40,167 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started

What am I doing wrong?

Update: Initial issue is easily solved by putting value in the quotation mark "7".

However next issue is when the value is pre-calculated:

String[] categories = (vars.get("categories")).split(",");
int qty = Math.round(categories.length/2);

log.info("!!!!qty variable is "+qty);

props.put("threads", qty);
props.put("rampup", qty);

Gives in the logs:

2023-08-26 10:00:14,006 INFO o.a.j.p.j.s.J.Threads init: !!!!qty variable is 5
2023-08-26 10:00:14,007 INFO o.a.j.t.JMeterThread: Thread is done: setup threads 1-1
2023-08-26 10:00:14,007 INFO o.a.j.t.JMeterThread: Thread finished: setup threads 1-1

Solution

  • The problem in the code is that JMeter doesn't allow to put integers into system properties. How logical, huh? Who would have though that.

    So the fix is to convert int to string:

    props.put("threads", String.valueOf(qty));
    props.put("rampup", String.valueOf(qty));