Jmeter random variable in several threads - random

I have a Jmeter thread group that uses the variable uuid several times throughout.
uuid is defined with 12345678-1234-4444-a123-${__Random(111111111111,999999999999)}
In other words, it starts with a fixed series 12345678-1234-4444-a123- and then randomizes the last twelve characters.
I want to run several threads at the same time, this gives the following problem.
When I define uuid as a user defined variable inside the thread group, it randomizes once and then uses that value for all my threads.
If I set it globaly, the same thing happens.
I will be running thousands of threads at the same time when I'm done, so I can't do manual solutions or read/write to disk.
Does anyone out there have experience with this?
I have been through the documentation and Google for quite a while, but can't seem to find a solution.
In short: I need to randomize a variable, use that variable throughout the thread group, and run this thread group in several simultaneous threads. The variable should have different randomized values in each different thread.

Suppose you can simply use Random Variable configuration element instead:
Variable Name: uuid
Output Format: 12345678-1234-4444-a123-000000000000
Minimum Value: 111111111111
Maximum Value: 999999999999
Per Thread (User): True
Generated value
can be accessed as ${uuid};
unique for each thread;
preserved between different samplers calls flow of each thread (not regenerated during each reference);
generated during each iteration of Thread Group.
Test Plan
Thread Group
Random Variable
...
Sampler 1
Sampler 2
...
e.g.
iteration: 1
thread: 1
sampler 1: VALUE_1-1
sampler 2: VALUE_1-1
...
thread: 2
sampler 1: VALUE_2-1
sampler 2: VALUE_2-1
...
...
iteration: 2
thread: 1
sampler 1: VALUE_1-2
sampler 2: VALUE_1-2
...
thread: 2
sampler 1: VALUE_2-2
sampler 2: VALUE_2-2
...
...
Sample script implemented for schema given above: rnd-var.jmx
As per Random Seed field description of Random Variable:
Default is the current time in milliseconds. If you use the same seed
value with Per Thread set to true, you will get the same value for
earch Thread as per Random class.
If two instances of Random are created with the same seed, and the
same sequence of method calls is made for each, they will generate and
return identical sequences of numbers.
Keep it in mind on implementing scenarios with high concurrency (as mentioned below in comments).
To overcome this issue you can use randomize seed with e.g. ${__Random(MIN,MAX)} as value of Seed for Random function field.

Just put
12345678-1234-4444-a123-${__Random(111111111111,999999999999)}
inline where you need.
If you put this in your UDV component, value is assigned once only, before threads are even started.
The behaviour is OK according to jmeter documentation. Please read it carefully.

Related

How to asssign one random variable to multiple threads in J-Meter?

I need a new "ROOMID " every time I run a test. I setup a random variable generator to give me a new ID each time the test is run. However, if I set the number of threads to 5 it gives a different ID for each one. I need it to use the same one for each thread. I only need it different each time I run the test.
I know it is occurring because I am calling the variable listed in the Random Variable Generator. Is there anyway to just get 1 random conference ID for all the threads?
Example
Random Variable Generator creates an ID.
Do an HTTP request and set it to run five threads:
1st gets 123456
2nd gets 234567
3rd gets 7451236
4th gets 4452189
5th gets 1254866
I need all of them to receive 123456.
Then the next time I run the test I need them to all get a different ID.
Please follow the below steps to generate random number to be constant across threads.
In the Test Plan, create a variable myVar and set the value as ${__Random(1,999999,)}. You can configure the maximum value in the random function.
In Thread Group enter the number of threads as 5 as shown below.
Execute the script. In View Results Tree or Debug Sampler you can view the value of myVar which is constant across the threads.

Jmeter: Is it possible to increment the value of variable for every thread in Jmeter?

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}

Using JMeter PreProcessor and User Variables logic

I am new to JMeter and it maybe a stupid question but I still find it hard to understand the concept here.
I have a simple test.
Thread Group with a Single thread with loop count of 2
PreProcessor that place two
variables on the vars map
A loop that execute a request twice based
on the PreProcessor parameters
I expected that the preprocessor will initialize the parameter and it will use the same values twice in the request.
It looks like it’s executing the PreProcessor once pair call.
When I switch the PreProcessor with similar User Defined Variables it reuses the same value on every call.
Can anyone explain the logic here?
I am using JMeter 2.11
A PreProcessor is executed each time the HTTP Request is executed so if you have a total of 2 iterations, you should see log twice, you have it 4 times so maybe number of iteration is different than what your write or you have 2 threads.
When you use User Defined Variables, the value is computed once and then reused. Value will be different per thread.
After reading the documentations and with #UBIK LOAD PACK help I used User Variables and it worked
User Variables - are specific to individual threads.
Pre-Processor is attached to a Sampler element (e.g. http request in our case), then it will execute just prior to that sampler element running
So 4 request for different parameters because it runs before every request
User Defined Variables - It is processed at the start of a test, no matter where it is placed. For simplicity, it is suggested that the element is placed only at the start of a Thread Group. This is why I get the same value all the time

load test with varying number of threads in JMeter

I am have been exploring JMeter for the last couple of days. And I am try to achieve the following:
I am trying to create a load test for a service such that, in the first loop 'n' threads are created and in the second loop 'n+m' threads are created and in the third loop 'n+2m' threads, in the fourth 'n+3m' threads and so on. I did find many solutions here and I tried replicating them, but somehow it is not working for me. The test plan I created looks something like this:
Step 1: Add a user defined variable called USERCOUNT = 0
Step 2: Create a thread group. I have used __intSum to increment USERCOUNT by one and storing the result back in USERCOUNT for future reference.
Ideally what I am expecting here is, in the first loop one thread is created, in second loop 2 thread are created and in the third loop 3 threads are created. So in total there should be 6 thread created. However the results show up something like this:
Not sure if I am missing something silly or my approach itself is completely wrong. Any help from the community would be appreciated. :)
I believe what you are trying to do is impossible. When JMeter starts a thread group for the first time it initializes the number of threads.
What you are essentially trying to do is re-run the same test three times with different numbers of users each time. JMeter cannot re-run a thread group once started, it can only re-run ("loop") a thread in a thread group. It is not possible to add threads to a running thread group once the ramp up and threads are initialized. (Let me know if I should try to explain that further).
If you want one thread group to populate the run-time settings of another thread group, you must have two thread groups in the test plan. At the test plan level, check off the option "Run Thread Groups Sequentially."
With that option, JMeter will not initialize the number of threads on the second thread group until the first one finishes. The first thread group can set a global property, and the second thread group can reference it in the number of threads.
How to set a property in beanshell: (this would be in Thread Group 1)
props.put("threadgroup_2_num_users","15");
How to reference that value in Thread Group 2:
${__P(threadgroup_2_num_users)}
If this does not help, maybe try to describe your end goal. What are you trying to learn about the thing you are testing?
Edit: Perhaps using the plugin package "Stepping Thread Group" will allow you to achieve the scenario you are trying in a single thread group. Check this out:
http://jmeter-plugins.org/wiki/SteppingThreadGroup/
JMeter currently doesn't provide possibility to change number of threads on-the-fly during test execution so I would suggest to go with the following alternatives:
Use i.e. Ultimate Thread Group available via JMeter Plugins which adds some extra features to JMeter's Thread Group so you will be able to implement your scenario
Consider so called "goal oriented scenario" when load is based on requests per second rather than on number of virtual users. You can precisely set desired throughput rate and even change it during test run using Constant Throughput Timer

How to run all loops for the first sample and then switch to the following samples in Jmeter

I have a Jmeter project that contains 3 samples and one counter that is used by all three samples.
The test structure is next:
-Test Plan
--Thread Group
----Counter
----Listener
----Enrollment HTTP sample (SOAP request)
----Configuration HTTP sample (SOAP request)
----Start Cycle HTTP sample (SOAP request)
The test has a value when I run all threads and loops for the first sample, then for the second and then for the third sample.
Other words, I have to Enroll an Individual, Configure cycle and Start cycle. The counter value should be the same for all three samples.
The question is how can I configure the test so Jmeter will execute all threads and loops for the first sample, then for the second and for the third sample separately?
I need it into the one Jmeter project because I plan to include this test into CI process.
You can break down your samples to different thread groups as follows:
Thread Group 1
Counter
Enrollment
Thread Group 2
Counter
Configuration
Thread Group 3
Counter
Start cycle
And check Run Thread Groups Consecutively box on Test Plan level. In this case thread groups will be executed one by one.
I would also recommend to take a look into __threadNum function which returns the number of current thread, i.e. 1 for the first thread, 2 for the second, and so on. Perhaps you could switch from counter to __threadNum function. Also there is a __counter function which is being incremented by 1 each time it's called. You may wish to check out How to Use JMeter Functions post series to see how you can achieve additional flexibility.

Resources