Skip to main content

How to use a value between two different threads in Jmeter

How to use a value between two different threads:
Let us see how we can use the extracted value in one thread can be used in a different thread:
Threads
As shown below we have Two threads (Thread Group – 1 and Thread Group -2). Under Thread Group -1 we have a HTTP Request where we extracted Request_Id and Session_Id. In our example we will use the same Ids in Thread Group -2
We have BeanShell PostProcessor to log the output of the variables in the output log.
The Lines in the both BeanShell is as below:
log.info("Request Id in Thread 1 = " + "${Request_Id}");
log.info("Session Id in Thread 1 = " + "${Session_Id}");

Now if we run the Script we get the below output:
Id_Output1
As we see the values of both the IDs are not passed to Thread Group-2.
Now we will add few lines in the BeanShell PostProcessor as below and run again:
${__setProperty(Request_Id,"${Request_Id}")};
${__setProperty(Session_Id,"${Session_Id}")};
log.info("Request Id in Thread 2 = " + ${__P(Request_Id)});
log.info("Session Id in Thread 2 = " + ${__P(Session_Id)});
Id_Output2

As we see the values are passed to Thread Group -2.
Few lines on : ${__setProperty(Request_Id,"${Request_Id}")};
__setProperty() – The setProperty function sets the value of a JMeter property and is a Jmeter built-in function. Detail here
Request_Id – name of the property that will be set.
${ Request _ Id} – Value of the property and is the variable that was referred to as in Regular Expression Extractor.
This is the line that is responsible for transferring the value between threads. Now we can access  the value of ${ Request _ Id} from any other thread group.
Note: Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.
Point to note:
Sometimes it may happen that Thread Group-2 will run before Thread Group -1. Then we will not get the required result. Example is as shown in below screenshot:

Not_expected

Here Thread Group-2 ran before Thread Group-1, so the variables for ThreadGroup-2 are not set.
To avoid such situation we need to check the option “Run Thread Groups consecutively” option under Test Plan as shown below:

TestPlan

Comments

Popular posts from this blog

Steps to Analyze AWR Report in Oracle

Steps to Analyze AWR Report in Oracle AWR -   Automatic   workload repository is a collection of persistent   system performance   statistics   owned by SYS. It resides in SYSAUX   tablespace . By default snapshot are generated once every 60 min and maintained for 7 days . Each snapshot has a unique ID know as "snap_id". Snapshot detail can be found in " dba_hist_snapshot " view.   If we have Database performance issue and not the Database machine, then AWR Report is the place to look at. AWR is not used for real-time performance monitoring like the v$ tables. It is used for historical analysis of performance. AWR complements, but doesnot replace real-time monitoring. Once AWR Report is generated in Oracle, the next task is to analyze it. By going through the AWR Report we can easily solve issues like slow database, high wait events, slow query and many more issues. Even though the report is lengthy, Analyzing or Reading relevant part of AWR Report can

Verifications and Error Handling in LoadRunner *Web_reg_find and Web_reg_save_param*

Verification's and Error Handling Verification points must be inserted into the scripts to verify the application being tested with the load. Verification function that are used in our application are:  Web_reg_find, web_reg_save_param These verification should be outside towards the end of the transaction. Mandatory verification points: ■          Login – whenever there is a login, verification points must be added to verify that the user logged in correctly. ■          Update Transactions – transactions that update the database must be verified that they are successful. ■          Each page should be verified using Web_reg_find function Using Web _ reg_find for verifications. Example: web_reg_find("Text= Main Package","SaveCount=Verify_Count1",LAST); Verification: if (strcmp(lr_eval_string("{Verify_Count1}"),"0")==0) { lr_end_transaction("AddMainPackage", LR_FAIL);  lr_error_message(&q

Vmstat Output explained

vmstat : vmstat is a tool in Unix/Linux which is used to Report virtual memory statistics. It shows how much virtual memory there is, how much is free and paging activity. Most important, you can observe page-ins and page-outs as they happen.   vmstat   reports   information about processes, memory, paging, block IO, traps, and cpu activity.   > vmstat procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----   r   b    swpd    free    buff   cache         si    so     bi     bo    in    cs us sy id wa st   0   0   21688 12797396 850716 15372668     0     0      3     35     0     0   1   0 99   0   0   0   0   21688 12789292 850716 15372668     0     0      0   1355   883   744   1   0 99   0   0   1   0   21688 12784648 850716 15372676     0     0      0     15 1934 1292   6   0 93   0   0   2   0   21688 12781356 850716 15372736     0     0      0     16 2222 2094   8   1 92   0   0   0   0   21688 12809992 850716 15376880     0