Tuesday 22 January 2013

Database performance testing using JMeter

In this post we will see how we can build a test plan and run load test on databases using JMeter. We will consider MySQL database for our discussion. In order to test the SQL Query performance using JMeter, first you should be aware of the below concepts and terminologies.

A . JDBC Driver :

JDBC driver is a software component enabling a Java application to interact with a database. JDBC drivers are analogous to ODBC drivers, ADO.NET data providers, and OLE DB providers. It provides methods for querying and updating data in a database. JDBC is oriented towards relational databases. 


 

B. JDBC Request Sampler in JMeter : 

This sampler lets you send an SQL query to the database using JDBC server . 

C . JDBC Connection Configuration ( Config Element ) :

This helps us to create a database connection from the supplied JDBC Connection settings .

Scenario : Load Testing an SQL query on MySQL Database


In order to establish a connection from JMeter to MySQL database , you should download the proper JDBC Driver that connects to your database .You can download the JDBC Driver for MySQL from the below link

http://dev.mysql.com/downloads/connector/j/

Note : The downloaded "jar" file should be placed under the JMeter/lib directory .
The classes from jars are automatically found by the Jmeter in the following directories:

JMETER_HOME/lib - used for utility jars

Note: Only .jar files are found by JMeter not the .zip files.

Now you can start the JMeter and you are ready to build the DB test plan.

Step 1 :

Add the thread group and provide the appropriate name to it . In this case we have given it as DB Test plan .



Step 2 : 

Add the JDBC Connection configuration element and provide the appropriate JDBC connection settings relevant to your database.






You have to carefully fill the fields listed below and for the remaining you can use the default values.( In this case we have used the MySQL database installed in the local machine and the database name is given as “Test”).
Variable name bound to pool. This needs to uniquely identify the configuration. It is used by the JDBC Sampler to identify the configuration to be used.
  • Database URL: jdbc:mysql://localhost:3306/Test 
  • JDBC Driver class: com.mysql.jdbc.Driver 
  • Username: Suman 
  • Password: **** 

Step 3 :

Add the JDBC Sampler which lets you send the SQL request to the server.







We have given an ‘insert’ statement and the query type as ‘Update statement’.

Note : The same variable name which we have used ( in the Variable name field ) in the JDBC Config elment should be used in the sampler as well.


Step 4 :

Add the listeners required as per your requirement.




Now the test plan is ready for you to perform SQL query performance testing on MySQL.


Frequent error you may get while execution and their resolution:


1. Response code: 080010

Response message: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/sakila

This error may occur if there is any mistake in the Database URL field. This may occur even if there is a “leading space” in the Database URL Field. Another reason would be, the database driver is not present in the JMeter Lib directory .


2. Response code: 42000 1049

Response message: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'sakil'

This message is self-exploratory; if the database name is incorrect or the database is not created you may encounter the above error.

3. Response code: 28000 1045

Response message: java.sql.SQLException: Access denied for user 'sumana'@'localhost' (using password: YES)

Even the above error message is self-exploratory; If the database access credentials are not correct then you may receive this error.


Hope this post is useful .



16 comments:

  1. Excellent article - very helpful unlike general JMeter documentation :)

    ReplyDelete
  2. @Anonymous : Thank you very much .

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  3. It is Quite Useful. But i feel post some advance examples.

    ReplyDelete
  4. Thank You for sharing this information!

    ReplyDelete
  5. Thanks for fabulous article, bookmarking. Just in case here are few more posts on database testing with JMeter:

    Using JDBC Sampler in JMeter 2.6 - which highlights advanced JDBC Sampler's options

    The Real Secret to Building a Database Test Plan With JMeter - which provides extra information on configuration and meaning of standard controls.

    ReplyDelete
  6. Is there a way to send multiple records using a csv file.
    Csv file has multiple rows and i wanted to insert into that database,those many multiple records

    ReplyDelete
  7. The response time calculated in summary report is also included the time taken to establish JDBC connection to the server and executing the query?

    ReplyDelete
  8. I don't know actual what is database URL?

    and actual Class path?
    Can you help me?

    ReplyDelete
  9. Hi Suman, First of all nice article, It helped. But Im getting following error -
    Response code: null 17003
    Response message: java.sql.SQLException: Invalid column index

    I tried and checked multiple times, same insert statement works when run via SQL devloper. but not working though JMETER.
    Please note i tried Select statement it works fine

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. how can i configure OLEDB in Jmeter??

    ReplyDelete
  12. Hi! Thanks for sharing your thoughts. Well, the automated testing tools actually save your time and energy. The testing tools will do the work for them when it comes to the testing process so that they can do other work as well.Performance testing services is a highly specialized field of testing.

    ReplyDelete