I have a Test which is running for 30 Thread groups and each thread needs a unique variable which will increment and used when the Test is running.I have used a counter in this case which will be used in the API request body.
Now every time I am using the Test I have to manually go and changed the Starting Value and the Number format in the Counter which is lot of manual work since I am using 30 thread groups
My question is Can I use a global variable which will have a way to get a unique number to each thread group which will be used by each API request
I am a beginner for Jmeter so any help will be appreciated.
There's unique number per thread using function ${
__threadNum}
thread number function simply returns the number of the thread currently being executed
Just parameterize it using __P() function like:
Once done you will be able to override the above properties values via -J command-line argument like:
jmeter -JstartingValue=100 -JnumberFormat=00000 -n -t test.jmx
To make the changes permanent you can add the next lines to user.properties file:
startingValue=100
numberFormat=00000
the values which you pass via the command-line will take over the values which are in the user.properties file.
You can also provide default values like:
${__P(startingValue,1)}
so in case if the startingValue property is not set the test will use 1 as the default value.
Related
Please tell me, is it possible to read data into Jmeter from a dynamically changing file? I have a file with parameters, which will be appended during the test itself. Is it possible to somehow define a global counter that will allow each thread to read its own line every iteration? User Defined Variables are reset every iteration as i understood.
In theory, I can read a specific line using File.readLines().get(counter) in JSR223 Sampler but problem is how to define correctly this counter.
I believe __counter() function is what you're looking for. If you invoke it like ${__counter(FALSE,)} it will return an incremented value each time it will be called.
Example usage:
More information: How to Use a Counter in a JMeter Test
Is it possible to specify programmatically the number of threads from within the Thread Group?
My scenario: I need to run two Thread Groups. Each group will read files that specify the number of threads for that group to run. The groups should run concurrently.
Thanks
You can use properties.
For ex:
In the number of threads field, you can set like this
$(__P(usercount)}
When you run the test through command line, you can pass the value as shown here
jmeter -n -t test.jmx -Jusercount=10
Now the test will run for 10 users.
You can also use $(__P(usercount,5)}
That is, if the property value is passed to the test, then it will use it, otherwise, it will take the default value which is 5.
Example:
Thread: 50,
Ramp-Period: 0,
Loop: 1.
I have to send different value with each thread. Is it possible to do it without changing the loop count?.
If you need to add something to an existing variable it may be done via __intSum() function
__counter() function generates incremented number each time it's being called either per-thread or global
Another candidate is __threadNum() function which is basically the number of current thread.
See How to Use JMeter Functions posts series for advanced information on above and other useful functions.
Your question looks like this - jmeter unique id per thread for http request
You can also use Beanshell to create an unique ID for every thread.
You can achieve this by adding a counter under the thread group.
In the counter it's possible to set the start, increase and maximum number you want to reach.
Then add reference name in counter, which will be used in your request as ${reference_name}
I've been trying to use JMeter to create some automated Performance Tests and I'm setting up a job in Jenkins so that people can run it and view the results there.
I'm trying to add a few parameters to the job that correspond to the options available in the Thread Group. They are:
Number of Users
Ramp-up Period
Loop count
Some people don't quite understand the concept of the 'Ramp-up Period' so instead I wanted to make refer to it as 'Delay' and use it to control how long each thread will wait before starting the test. This would mean that the 'Ramp-up Period' should be equal to (The Number of Users x Delay).
The command I'm using to run the test is below:
jmeter -n -t <myscript>.jmx -l results.jtl -j jmeter.log -JUSERS=10 -JDELAY=1 -JLOOPS=1
and the variables look like this:
USERS = ${__P(USERS)}
RAMPUP = ${USERS}*${__P(DELAY)}
LOOPS = ${__P(LOOPS)}
But unfortunately the value of the RAMPUP variable was not what I expected. It ended up being "${USERS}*1"
Is there a way to do this in JMeter?
JMeter variables and properties are Strings, you can not apply arithmetic operations to them. The behavior you're getting is absolutely expected. Also there is no possibility to dynamically change properties during runtime, you'll have to calculate ramp-up prior to passing it to JMeter.
You can add BSF PreProcessor before you test plan, calculate there values for user defined variables and put values into variables using putObject(String key,Object value)
In JMeter, I have a test plan with a thread group. The thread group has number of threads and a loop count which can be set in the gui.
Is there anyway I can figure out dynamically what they have being set so I can pass them to variable?
Thanks.
Use BeanShell PostProcessor with following code:
vars.put("threads", Integer.toString(prev.getAllThreads()));
Or maybe you just looking for this: http://code.google.com/p/jmeter-plugins/wiki/ActiveThreadsOverTime
You can parametrize the thread count defining a property like
${__P(users, 1)}
and if you run the test plan from command line, you can specify its value as -Jusers=XX. If, instead, you run the test from JMeter gui, to verify the text plan for example, the users property assume the default value of 1.
Don't forget to reference the property in the thread count, with ${users}.
You should parameterize your thread count at TestPlan level settings, then use that parameter (variable) both in ThreadGroup and Listener.
If the value varies and you want to pass it from command line use __P() function instead of variable.