Performance Testing of Websites Using JMeter


In this tutorial, we will be studying the creation of a Performance Test Plan for Web Applications in JMeter. We will see the different test plan elements required for creating the test script along with their usage and configurations. Before going further, you are requested to go through our very important tutorial on planning a load test - Planning a Load Test, to get hold of the whole planning process.

Pre-requisites for a Performance Tests

The following things should be known beforehand while creating performance test plan for web applications-

  1. Knowledge of application's business scenarios.
  2. An application instance dedicated for performance testing with configurations and state similar to production.
  3. List of scenarios selected for performance testing (as not all scenarios are required to be load tested).
  4. The peak load in production or the anticipated peak load value.
  5. The user distribution across different scenarios as some scenarios are more frequently used than others. Hence, different number of user count is assigned to different scenarios.
  6. The value of think time or wait time to be included in between some operations for simulating real users - thinking time, typing time, reading and information processing time etc.
  7. The performance test metric to be derived from test results like response time, Hits per Second etc.

Steps involved in creating a Performance Tests Scripts

The following steps need to taken in order to create a performance test plan for web applications-

  1. Creation of a Test Script Skeleton having Test Plan, Thread Groups and Logic Controllers Configured.
  2. Creation or recording of HTTP Requests using HTTP Proxy Server.
  3. Adding Timers for introducing wait time or think time between requests.
  4. Adding listeners for storing and analyzing test results
  5. Dry run of test with 1 or 2 users.
  6. Configuration of the load test with required number of users and run it.
  7. Running and analyzing the test results.

Now, let's see how we can perform each step mentioned above in detail.

Creation of a Test Script Skeleton

Based on the number of user group required for performing different operations, we will add Thread Groups and Logic Controllers to our Test Plan. For example - if we have two set of users performing searching and login operations on a website. Then we will create two Thread Groups and add different Logic Controllers to simulate the different operations performed by the users. Steps to perform-

  • Add a Thread Group to the test plan and name it UsersSearchingKeywords.
  • Add multiple transaction controllers as child of this Thread Group and name them as per the operations they perform like - "Launch application", "Search a Keyword and hit enter", "Close the Application".
  • Add another Thread Group and name it UsersLogin.
  • Add transaction controllers to this thread Group like - "Launch application", "Click on Login Link", "Enter credentails and click Submit".

Add the of configuration our test plan will look like this-

Web Application Performance testing in JMeter

Please note that we have used transaction controller here, as within this controller we can have multiple HTTP requests and after the atest execution, we will get the overall response time of the whole transaction which is desirable. Depending on the scenarios, we can also add different Logic Controllers like Loop Controllers, Random Controller etc.

Creation or recording of HTTP Requests

When we perform an operation like cliking a button, several HTTP requests are sent to the server. While scripting we need to create all these requests, in order to determine the time taken for processing the requests. One way of doing this is to add different HTTP request and configure them with values like - URL, Port, request type(Get, Put, Post, Delete etc), request body, request Header etc. But this can get very cumbersome unless we are required to test very limited requests or need to test a particular HTTP request.
To perform this efficiently JMeter provides us an HTTP(s) Test Script Recorder, using which we can record scripts in JMeter directly by performing operations on a browser. Check our tutorial on recording scripts Record and Playback in JMeter.
Once we get hold of recording scripts, we can select a transaction controller like "Launch application" from the Target Controller of the HTTP(s) Test Script Recorder and perfom the operations like launching the web application on the configured browser, the different HTTP requests will get added to the selected Controller.

Recording in JMeter

Adding Timers

We can add Timers between two transaction controllers to introduce think time like a timer with of 3 seconds timeout value can be introduced between "Launch application" and "Search a Keyword" controllers to simulate the time a user takes to process the response and type a keyword to search.


Adding Listners

In order to store and analyze the test results, we can different types of listners studied in our tutorial - Listners in JMeter.


Dry run the test

Before performing the test with actual number of users we need to dry run the test with very small number of users in order to validate the correctness of the script.


Configure and schedule the load test

Once the scripts is verified, we will configure the load test with desired number of users and schedule the load test.


Run and analyze the test

Once the whole test script creation and configuration is done, we will run the test by clicking the play icon or pressing Ctrl+r on keyboard. During the test execution, we will monitor the server in parallel. Once the test gets over, we can store and analyze the test results.


Still got some problem

Now we have seen a basic test plan for a web application, still there are couple of things which needs to be taken care of-

  1. During testing we should not hard code the values like - search terms and user credentials etc. For this, we need to parameterize the test scripts. To get of hold of the parameterizing concept, check our tutorial - Parameterization in JMeter
  2. Creating dynamic scripts and handling session variable is another thing that needs to be considered while scripting. For handling these issues we have a concept of correlation, check our tutorial - Correlation in JMeter for getting insight of this concept.

Reference

Apache JMeter User Manual