Guel135
Guel135

Reputation: 788

Jmeter threadgroup sharing counter between threads

I want to create a Thread Group in jmeter to create users and their devices with many (for example 5000) devices.

I have no problem to create this test and I want to have the name of the users and device in a correlative order.

1. user1--device1 
2. user2--device2
3. user3--device3

I already created the test but to create 5000 users and devices in the same Thread Group I need to run 5000 iterations with 3 requests each, using 1 thread, because otherwise I have the same user name repeated by multiple threads (for example with 3 threads)

1. user1--device1 
2. user2--device2 
3. user3--device3 
4. user1--device1
5. user2--device2
6. user3--device3
7. user1--device1
8. user2--device2    
9. user3--device3

My question is: is there any way to share the loop counter between threads in order to create 5000 users/devices with more than one thread (for example 20 threads). This will help me a lot because instead of waiting for 20 minutes, it will be a minute to create the users.

Many thanks!

http://pastebin.com/S1izFC9r

Added explanation I want for example maximun 9 devices (counter_max) but I want to run it with 3 threads. I want the result be like that

  1. thread1--user1-device1
  2. thread2--user2--device2
  3. thread3--user3--device3
  4. thread1--user4--device4
  5. thread2--user5--device5
  6. thread3--user6--device6
  7. thread1--user7--device7
  8. thread2--user8--device8
  9. thread3--user9--device9

Upvotes: 6

Views: 5051

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

I think you can implement it using __counter() function in "global" mode, like: ${__counter(FALSE,)}

  • __counter() function returns incremented value each time it's being called
  • in the "global" mode counter value is shared across threads

Counter Global Demo

So you should be able to use as many threads as required and each thread will use the next counter value to create your users and devices with multiple threads.

See How to Use a Counter in a JMeter Test article for comprehensive information on using "counter" config element and function.

Upvotes: 4

Related Questions