0

Am currently running load test with jmeter triggering 300 request per second concurrently. My application need to generate non duplicate random number, but with these many requests it failing. I cant store it in an set ot Map to prevent duplication, as it take some more time for computation.

So far i have tried

  1. System.currentTimeMillis();

  2. System.nanoTime()

  3. ThreadLocalRandom

All these implementation provide duplicate at some point.

Abra
  • 19,142
  • 7
  • 29
  • 41
Venkatesh
  • 577
  • 1
  • 7
  • 16
  • The only way you can generate non duplicates using nanoTime without map is when you synchronize the source. – Aniket Sahrawat May 07 '20 at 04:10
  • There are already several questions (with answers) on SO about non-repeating, random numbers, for example [Java generating non-repeating random numbers](https://stackoverflow.com/questions/16000196/java-generating-non-repeating-random-numbers/16000210) Have you read them? If you have, then I assume they don't help you. Can you explain why? – Abra May 07 '20 at 04:10
  • @Abra I have tried some. With concurrent request its failing. If i run 1000 request for first time its working. On second batch i tried to run again a 1000 request its failing. – Venkatesh May 07 '20 at 04:16

2 Answers2

0

You can use JMeter's __Random function.

Go to your Function Helper from the Menu and then select your Random function from the dropdown. You can generate and copy your random function very easily.

Here is an example: ${__Random(000000100,999999999,)}

For more references you can check: Functions and Variables

enter image description here

Masud Jahan
  • 3,418
  • 2
  • 22
  • 35
0
  1. Each JMeter thread (virtual user) has its number accessible by __threadNum() function. The iteration of the Thread Group can be obtained using __V() and __threadGroupName() functions combination like:

    ${__V(__jm__${__threadGroupName}__idx,)}
    

    so the construction like:

    ${__threadNum}${__V(__jm__${__threadGroupName}__idx,)} 
    

    should provide you unique numbers which will not repeat during single test execution.

    enter image description here

  2. If you need to repeat the test more than once and the approach from point 1 will be "known" to the system - you can pre-generate the unique list of truly random numbers somewhere in setUp Thread Group and store it into a CSV file and in the main Thread Group you will be able to refer the generated data using normal CSV Data Set Config
Dmitri T
  • 159,985
  • 5
  • 83
  • 133