One of the main drawbacks with VuGen is the inability to easily store data for later retrieval, and the lack of interscript communication. I had this exact problem on a recent assignment, the problem was that the business process involved a batch process that needed to run before the rest of the business process could continue. The business scenario looked like this:
- Create new application data. ** PRODUCER **
- Wait for batch or manual process to process the new application.
(this batch process may create a delay of several hours, and is not part of the load testing scope). - Perform transactions on the application (using lookup data from step 1). ** CONSUMER **
To achieve this business scenario, I created two distinct scripts, a producer script to handle step 1 and a consumer script to handle step 3. I now needed the ability to pass data from script 1 to script 2 in a persistent manner so that a buffer existed which allowed sufficient delay for the batch process to execute.
For this to work, I wrote a Loadrunner add-in library in Visual C that exposed a FIFO (First In, First Out) queue to VuGen using a MySql database. I used a queue structure so that the producer can add items to the queue, and the consumer can pick them up off the queue.
Setting Up Your MySql Environment
Download and configure the MySql database, I used MySql Server 5.0 so I recommend that particular version. Here are a couple of tips for configuring the MySql environment:
- I recommend installing the mysql database on the Loadrunner Controller machine. Not a requirement, but it is a nice central place for the database to be installed, certainly MySql doesn't interfere with LoadRunner in any way.
- Make sure that you enable networking in the my.ini file this is done by commenting out the skip-networking line.
- Ensure that the max-connections setting is set to a value a bit higher than the number of VUsers you plan to run.
Next create a new database and table structure for the VuGen data, to make this easy copy and paste the following into a mysql command line: mysql -uroot -p
create database vugen;
use vugen;
create table runtime_data
( name varchar(50) not null,
value varchar(4000) not null,
flag int default 0 not null,
timestamp datetime not null);
alter table runtime_data
add primary key (name, flag, timestamp);
exit
That's it. You can test the everything is set up correctly by running the following windows command:
mysql -uroot -p -Dvugen -e "select name,value,flag,timestamp from runtime_data limit 0"
Setting up VuGen (and the Load Generators).
This part is easy, the only prequiste is that you have installed VuGen and the Load Generators into their default installation location (C:\Program Files\HP\LoadRunner).
Simply download and run the following setup file which contains the JDS MySql Library.
https://www.jds.net.au/files/JDSMySqlLibrary.msi
Using the JDS MySql Library.
Now this where the real magic happens.
Before progressing any further you must set a property in Runtime Settings to run the VUser as a process. Unfortunately, the JDS MySql library is not thread-safe yet (unfortunately, there is a tradeoff between thread-safety and ease of use...the later won).
To expose the new functions into MySql you must add the following function into the vuser_init section of your script.
lr_load_dll("JDSMySqlLibrary.dll");
Now you're ready to use the MySql functionality. As mentioned at the top of this post, this library exposes queue functionality, rather than the ability to run specific SQL commands. So the SQL code itself is hidden away in the MySql library code itself, and doesn't need to be factored into your script. Easy eh!
The JDS MySql Library Function Reference.
Life Cycle Overview.
There are four functions within the JDS MySql Library, these functions form part of a lifecycle. How you integrate this lifecycle into your script requirements.
The life cycle is:
- Connect to the MySql Database
int jds_mysql_connect(char *host_name, char *user_name, char *password, char *db_name, int port_num)
- Insert new data into the queue.
int jds_mysql_insert(char *name, char *value, int status)
- Retrieve the data, and update the status.
char* jds_mysql_retrieve(char *name, int old_status, int new_status)
- Retrieve the data, and update the status.
char* jds_mysql_retrieve(char *name, int old_status, int new_status)
- Disconnect from the Database.
int jds_mysql_disconnect()
You will notice two particular things here, firstly, the data is inserted with a status. And that we retrieve the data twice. This allows a piece of data to transistion from state to state (or status to status), following the business process.
For example, A customer creates a new airline booking (Status 0), the airline confirms the booking (Status 1), the customer checks in at the airport (Status 2), the customer boards the plane (Status 3), the customer arrives at his/her destination (Status 4). Each one of these states can be handled by a different script at different times.
jds_mysql_connect
Connects to the MySql database using the credentials specified.
int jds_mysql_connect(char *host_name, char *user_name, char *password, char *db_name, int port_num)
Returns 0 on success, otherwise error.
host_name - The network host name of the MySql Server. Note that while, localhost, will might work fine for VuGen it won't necessarily work for your load generators.
user_name - The user name of the MySql user. Normally "root".
password - The password you configured for the MySql user.
db_name - If you used the above script to configure your MySql environment, then this should be "vugen".
port_num - The MySql server port number. Normally 3306.
Example:
jds_mysql_connect("nicks_pc", "root", "mypass", "vugen", 3306);
I recommend enclosing the connect and disconnect statements immediately before and after the function statements, rather then adding them to the vuser_init and vuser_end sections.
jds_mysql_disconnect
Disconnects from the MySql database.
int jds_mysql_disconnect()
Returns 0 on success, otherwise error.
I recommend enclosing the connect and disconnect statements immediately before and after the function statements, rather then adding them to the vuser_init and vuser_end sections.
jds_mysql_insert
Inserts a new name/value pair into the queue.
int jds_mysql_insert(char *name, char *value, int status)
Returns 0 on Success, otherwise error.
name - The name from the name/value pair.
value - The value from the name/value pair.
status - The initial status for this name/value pair.
Example:
jds_mysql_insert("bookingId", "3443364", 0)
jds_mysql_retrieve
Retrieve the next name/value pair from the queue, and set the status.
char* jds_mysql_retrieve(char *name, int old_status, int new_status)
Returns a string with the value, or NULL is no value is found.
name - The name from the name/value pair.
old_status - The status to retrieve.
new_status - The new status to set.
Example:
jds_mysql_retrieve("BookingId", 0, 1);
Note, that you must set the status. If you use the same status value from old_status and new_status this has the effect of "peeking" at the queue.
Foot Note
When I get a chance I'll make a full example for this library. But in the meantime enjoy, and feel free to add any comments or ask any questions. I hope to develop this library further over time.
Tech tips from JDS

Browser Console
Read More

Glide Variables
Read More

Understanding Database Indexes in ServiceNow
Read More

Fast-track ServiceNow upgrades with Automated Testing Framework (ATF)
Read More

Read More

Splunk .conf18
Read More

ServiceNow Catalog Client Scripts: G_Form Clear Values
Read More

Is DevPerfOps a thing?
Read More

The benefits of performance testing with LoadRunner
Read More

Monitoring Atlassian Suite with AppDynamics
Read More

5 quick tips for customising your SAP data in Splunk
Read More

How to maintain versatility throughout your SAP lifecycle
Read More

How to revitalise your performance testing in SAP
Read More

Reserve and import data through Micro Focus ALM
Read More

How to effectively manage your CMDB in ServiceNow
Read More

ServiceNow and single sign-on
Read More

How to customise the ServiceNow Service Portal
Read More

Integrating a hand-signed signature to an Incident Form in ServiceNow
Read More

Integrating OMi (Operations Manager i) with ServiceNow
Read More

Implementing an electronic signature in ALM
Read More

Service portal simplicity
Read More

Learning from real-world cloud security crises
Read More

Static Variables and Pointers in ServiceNow
Read More

Citrix and web client engagement on an Enterprise system
Read More

Understanding outbound web services in ServiceNow
Read More

How to solve SSL 3 recording issues in HPE VuGen
Read More

How to record Angular JS Single Page Applications (SPA)
Read More

Calculating Pacing for Performance Tests
Read More

Vugen and GitHub Integration
Read More

What’s new in LoadRunner 12.53
Read More

Filtered Reference Fields in ServiceNow
Read More

ServiceNow performance testing tips
Read More

Monitor Dell Foglight Topology Churn with Splunk
Read More

Straight-Through Processing with ServiceNow
Read More

Splunk: Using Regex to Simplify Your Data
Read More

ServiceNow Choice List Dependencies
Read More

Tips for replaying RDP VuGen scripts in BSM or LoadRunner
Read More

Incorporating iSPI metric reports into MyBSM dashboard pages
Read More

Using SV contexts to simulate stored data
Read More

What’s new in LoadRunner 12.02
Read More

Recycle Bin for Quality Center
Read More

LoadRunner Correlation with web_reg_save_param_regexp
Read More

LoadRunner 11.52
Read More

QC for Testers – Quiz
Read More

Agile Performance Tuning with HP Diagnostics
Read More

What’s new in HP Service Virtualization 2.30
Read More

Understanding LoadRunner Virtual User Days (VUDs)
Read More

Problems recording HTTPS with VuGen
Read More

Improving the management and efficiency of QTP execution
Read More

Performance testing Oracle WebCenter with LoadRunner
Read More

Generating custom reports with Quality Center OTA using Python
Read More

Asynchronous Communication: Scripting For Cognos
Read More

How to fix common VuGen recording problems
Read More

Monitoring Active Directory accounts with HP BAC
Read More

URL Attachments in Quality Center
Read More

What’s new in LoadRunner 11.00?
Read More

Restore old License Usage stats after upgrading Quality Center
Read More

Changing LoadRunner/VuGen log options at runtime
Read More

Restricting large attachments in Quality Center
Read More

Retrieving Quality Center user login statistics
Read More

A comparison of open source load testing tools
...
Read More

Worst practices in performance testing
Read More

LoadRunner Sales Questions
Read More

LoadRunner Analysis: Hints and tips
Read More

LoadRunner in Windows 7
HP Loadrunner 11 is now available. This new version now natively supports Windows 7 and Windows Server 2008. I ...
Read More

Using the QuickTest Professional “commuter” license
Read More

Installing HP Diagnostics
Read More

Understanding LoadRunner licensing
Read More

VuGen scripting for YouTube video
Read More

Creating a Web + MMS vuser
Read More

Why you should use backwards dates
Read More

How to get the host’s IP address from within VuGen
Read More

VuGen scripting for BMC Remedy Action Request System 7.1
Read More

Unique usernames for BPM scripts
Read More

Mapping drives for LoadRunner Windows monitoring
Read More

VuGen feature requests
Read More

LoadRunner script completion checklist
Read More

Querying Quality Center user roles
Read More

Querying the Quality Center Database
Read More

HPSU 2009 Presentation – Performance Testing Web 2.0
Read More

Scaling HP Diagnostics
Read More

Global variables aren’t really global in LoadRunner
Read More

Client-side certificates for VuGen
Read More

Detect malicious HTML/JavaScript payloads with WebInspect (e.g. ASPROX, Gumblar, Income Iframe)
Read More

VuGen code snippets
Read More

Integrating QTP with Terminal Emulators
Read More

Why you must add try/catch blocks to Java-based BPM scripts
Read More

Querying a MySQL database with LoadRunner
Read More

ANZTB 2009 Presentation: Performance Testing Web 2.0
Read More

How to make QTP “analog mode” steps more reliable
Read More

Testing multiple browsers in a Standardized Operating Environment (SOE)
Read More

DNS-based load balancing for virtual users
Read More

What’s new in LoadRunner 9.50?
Read More

Calculating the difference between two dates or timestamps
Read More

The “is it done yet” loop
Read More

Think time that cannot be ignored
Read More

Understanding aggregate variance within LoadRunner analysis
Read More

Load balancing vusers without a load balancer
Read More

Harvesting file names with VuGen
Read More

Parameterising Unix/Posix timestamps in VuGen
Read More

HP Software trial license periods
Read More

How to handle HTTP POSTs with a changing number of name-value pairs
Read More

VuGen string comparison behaviour
Read More

Persistent data in VuGen with MySQL
Read More

How to write a Performance Test Plan
Read More

Unable to add virtual machine
To get ...
Read More

LoadRunner scripting languages
Read More

WDiff replacement for VuGen
Read More

Testing web services with a standard Web Vuser
Read More

Why your BPM scripts should use Download Filters
Read More

Querying your web server logs
Read More

Importing IIS Logs into SQL Server
Read More

QTP “Uninstall was not completed” problem
Read More

VuGen correlation for SAP Web Dynpro
Read More

How to save $500 on your HP software license
Read More

Testing and monitoring acronyms
Read More

Solving VuGen script generation errors
Read More

An introduction to SiteScope EMS Topology
Read More

Using the BAC JMX Console
Read More
Example code to perform arbitary queries against a MySQL database is now available at https://www.jds.net.au/tech-tips/query-mysql-with-loadrunner/
Hope you find it useful.
Hi,
This is excellent, but I was expecting to insert or update in any custom table. do you have a version like this?
Thanks, Joseph
Hi Joseph,
Yes, I agree this is a glaring omission from the JDS MySql library…however it wasn’t a requirement at the time I wrote it. Currently, to run any aribitary SQL statements you would need to use the lr_load_dll function to load the MySql Client DLL file (libmysql.dll). This would expose the MySql C API funtions to VuGen…these are quite tricky to use however there are plenty of examples on the web.
However, I’ll look at updating the JDS MySql library in the next few days to permit arbitary insert/update/select statements to be executed from VuGen without the need to use complicated API function calls. I’ll update this page when this available.
I hope this helps.
-Nick