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:
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:"Request Id in Thread 1 = " + "${Request_Id}");"Session Id in Thread 1 = " + "${Session_Id}");

Now if we run the Script we get the below output:
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(Session_Id,"${Session_Id}")};"Request Id in Thread 2 = " + ${__P(Request_Id)});"Session Id in Thread 2 = " + ${__P(Session_Id)});

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:


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:



Popular posts from this blog

Steps to Analyze AWR Report in Oracle

Steps to Analyze AWR Report in Oracle
AWR -Automaticworkload repository is a collection of persistentsystem performancestatisticsowned by SYS. It resides in SYSAUXtablespace. Bydefault 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 help to troubleshoot issues in easy and …

Using SQL Developer to create and view Tablespaces

Below are the steps Create and View Table Spaces settings using SQL Developer.
Required SQL developer version is version 3.0
To Create TableSpace :
Click on Menu View/DBA - DBA navigator window will appear.
In the DBA window add a new connection to the DB, and click connect. Then under storage option right click on Tablespaces and choose New Tablespace to create new one. Fill the Details as shown below:

To View the created table spaces: Under Storage, Select Data Files:
It will display the below:

Recording Jmeter Scripts behind a proxy server

Recording Jmeter Scripts behind a proxy server
In one of the blog we saw the steps of recording Jmeter scripts using a proxy server.
JMeter has its own in-built Proxy Server, theHTTP(S) Test Script Recorder. This is only used for recording HTTP or HTTPS browser sessions as explained in below link.
The above steps will work properly if the internet connection is not behind a proxy and can be accessed directly.
If we are testing from behind a firewall/proxy server or if we the internet access is provided using proxy server then the above steps will fail and will not record any of the steps.
Steps to record in Jmeter if the internet is accessed via proxy:
1.Start Jmeter with the firewall/proxy server hostname and port number. To do so, Open a command prompt in windows and run the jmeter.bat file from a command line with the following parameters: -H [proxy server hostname or ip address]
-P [proxy s…