Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jmeter unique id per thread for http request

Tags:

jmeter

My jmeter tests make a http request which contains a unique id.

http://myserver.com/{uniqueId}/

I want to set the base number (say 35000) and increment for each thread, for example my ids would be 35001, 35002, 35003 ...

http://myserver.com/{base + count}

I see functions for __threadnum and __counter but how would I:

  1. set it in a variable so that I can substitute it in my url
  2. add this count to my base value
like image 562
Barry Avatar asked Jul 24 '15 15:07

Barry


People also ask

How to get thread number in JMeter?

To get the number of the current thread (out of 5 in your case) use ctx. getThreadNum() which will get the number of the thread. To get the total number of threads being used by jMeter you can use ctx. getThreadGroup().

How to use functions in JMeter?

Functions can be used for many different operations, including: inputting information from a file, performing math calculations and value generation, processing strings, evaluating JMeter variables, working with JMeter properties and executing scripts like Javascript or BeanShell script.

What does the function javascript do in JMeter?

It is used to decode a string.


2 Answers

I would simply go with Beanshell pre processor.

int threadNo = ctx.getThreadNum()+1; //to get the thread number in beanshell
int base = 35000;
int uniqueId = threadNo + base;
vars.put("uniqueId", Integer.toString(uniqueId));

Now your HTTP requests as given below should have the value substituted.

http://myserver.com/${uniqueId}/

like image 65
vins Avatar answered Nov 03 '22 01:11

vins


To set a variable per thread you can use User Defined Variables.

To sum, you can use functions:

  • __intSum
  • __longSum

Or use a JSR223 PRE Processor or JSR223 POST Processor + Groovy and do it in Groovy.

like image 41
UBIK LOAD PACK Avatar answered Nov 03 '22 00:11

UBIK LOAD PACK