Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMeter - calculate variable using another variable

Tags:

jmeter

I have 5 thread groups and I want the number of threads in each group to be derived from a total users number.

So I wouldn't need to change the numbers in each thread group every time I change the number of users.

So I defined 6 variables on my test plan:

 1. TOTAL_NUMBER_OF_USERS = ${__P(num_of_users,100)}
 2. WEIGHT_OF_GROUP_1 = ${__P(weight1,0.2)}
 3. ...
 4. ...
 5. ... 
 6. WEIGHT_OF_GROUP_6 = ${__P(weight6,0.2)}

and than in the thread group Number of threads(users) field I put - ${WEIGHT_OF_GROUP_1}*${TOTAL_NUMBER_OF_USERS}.

When I start the test plan I can see in the log that the number of threads was interpreted as 0.

I tried using evalVar or doing the calculation at the place where I define the variables, but it didn't work.

Any idea how to do this?

like image 604
Noa Drach Avatar asked Jun 13 '13 14:06

Noa Drach


People also ask

Can JMeter variables be nested?

Note that variables cannot currently be nested; i.e. ${Var${N}} does not work. The __V (variable) function can be used to do this: ${__V(Var${N})}.

How do I pass a variable from one thread to another 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})}


1 Answers

Use __BeanShell function if you need computations:

like image 84
girlytech59 Avatar answered Sep 28 '22 12:09

girlytech59