Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jmeter random variable in several threads

Tags:

random

jmeter

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.

like image 418
Jon Carlstedt Avatar asked May 22 '13 14:05

Jon Carlstedt


People also ask

How do you pass variables between thread groups in JMeter?

Step to implement the logic for passing the variable value to another Thread Group: Add a 'Regular Expression Extractor' post-processor as a child element of 1.1 HTTP Request (Fetcher) and fetch the value in a variable (say employeeID) Add a 'BeanShell Assertion' and write ${__setProperty(valueToPass,${employeeID})}

How do you select a random value from an array in JMeter?

The __Random function will give you an index for your interval. To obtain values from 1 to 5, you have to call __Random(1,6,) , as it will never reach the MAX value. The __V function, will obtain the value of the variable with the given name.


2 Answers

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.

like image 154
Aliaksandr Belik Avatar answered Sep 21 '22 17:09

Aliaksandr Belik


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.

like image 43
skellapa Avatar answered Sep 21 '22 17:09

skellapa