How to Start Load Testing — Part 1

Dipak Singh
walkin
Published in
9 min readOct 1, 2019

Well Hello Guys…

In my first blog, we have seen how we can write API automation tests using Jest. As a QA Engineer, we have to perform many types of testing like Integration testing, Functional Testing, UI Testing etc… These tests only covers functional aspects and may not be sufficient. Our users might lose interest, if our application is performing poorly with crashes or delayed load time, even if we have excellent features. An ideal application should be able to withstand peak load, perform under lower network bandwidth and should not affect battery performance.

By reading this blog, you will learn how to to create API requests, perform load testing on those APIs and view the results.

What is Load Testing?

Load testing is a kind of performance testing which determines a system’s performance under real life load conditions. This testing helps us to determine how the application behaves when multiple users access it simultaneously.

Load testing is used to identify whether the infrastructure used for hosting the application is sufficient or not.

But the question is Why we want load testing and when should we use Load Testing?

Well the answer is…when we want to determine how many users our system can handle. We can also determine different user scenarios that let us focus on different parts of our system, like the checkout webpage on our website or app or APIs.

What are the goals for doing load testing?

Our Goals for load testing are:

  • Verify Response time for each and every transaction.
  • Verify Performance of the system components under different loads.
  • Verify Software application design issues affecting the performance.
  • Verify response time of the application under low, normal, moderate and heavy load conditions.
  • Check the maximum number of users that the application can handle before it crashes.
  • Verify response time of the Application Under Load is within an acceptable range when the network connectivity is slow
  • Check CPU and memory usage of the application and the database server under peak load conditions

Based on our success criteria, we can confidently say whether our system will perform well under load or not.

Success criteria:

Below are some of the success criteria which will consider while load testing:

Response time → should not take more than 3 seconds (Total time to send a request and get a response).

User load → it should be able to handle 1000 concurrent users (how many active users at any point).

Transaction Rate → it should be able to handle 100 transaction/second (total numbers of successful or unsuccessful requests).

CPU Utilization → CPU utilization on application server should not exceed 70% (How much time the CPU needs to process requests).

Average Load Time → Should not be more than 2 seconds (The average amount of time it takes to deliver every request is a major indicator of quality from a user’s perspective).

Error Rate → Should not be more than 5% (percentage of requests resulting in errors compared to all requests).

Memory Utilization → (How much memory is needed to process the request).

Wait Time (Average Latency)→ (long it takes to receive the first byte after a request is sent).

Throughput → Its depend on no. of request sending, high throughput shows good performance of system(throughput shows the amount of bandwidth used during the test).

There are many tools available in market for load testing, but when evaluating a load testing tool, be sure to keep the following factors in mind:

  1. Ease of Use — is it easy to create complex, realistic load tests?
  2. Accuracy — does it run in real browsers?
  3. Scalability — can you increase or decrease usage/use cases, users, instances?
  4. Integrations — can you integrate with the tools you use everyday?

Based on the above factors, I found that Apache J-meter is best tool for load testing. The main advantage of this tool is that it is free and open-sourced.

J-meter has a comprehensive GUI, which helps us to create test plan and configure the elements.

J-meter is pure java application, so its requires a fully compliant JVM 6 or higher. We can verify java version using command in terminal

java -version, it will show version of java and if java is not installed in system then above command will throw error, so first install java then install j-meter.

How does J-Meter perform Testing?

Let’s have a look at the different steps performed by J-Meter during testing:

  1. It creates a request and sends to the server.
  2. It receives the response from server, collects them and visualises those details in a chart or graph.
  3. It processes the response from the server.
  4. It generates the test result in several formats such as text, XML, JSON so that the tester can analyse data.

J-meter installation is very easy, Download and extract the latest JMeter binaries.

Note: Please ensure that all the downloads and extracted files should be kept in a single folder.

To Start J-meter click on Link and follow the instructions or

open terminal and type below commands

> cd/path of downloaded jmeter/apache-jmeter-5.x/bin

> ./jmeter(linux users) or ./jmeter.bat(window users)

J-meter will open in GUI mode like below:

Jmeter Test Plan:

A test plan describes a series of steps J-Meter will execute when clicked on “run”

  • A complete test plan will consist of one or more thread groups, samplers, logic controllers, listeners, timers, assertions and configuration elements
  • Test Plan node is where the real node is kept
  • Test plan is saved and we can run the test

Elements of Jmeter:

The different components of J-Meter are called Elements. Each Element is designed for a specific purpose. Some of the main elements are :

  • Thread Group
  • Sampler
  • Listener
  • Configuration

In below example we will see that what are the elements must need to add when performing load testing:

Thread Group:

  • Thread group elements are beginning of any test plan.
  • Thread groups is a collection of Threads.
  • Each thread represents one user using the application under test.
  • Thread group element controls the number of threads J-Meter will use during the test run.

To add the Thread Group: Right click on Test Plan > Add > Thread(Users) > click on Thread Group, like below screenshot

We can also control the following via thread group:

  1. Number of threads — Simulates the number of users to the server application.
  2. Ramp up period — Defines the time taken by J-Meter to get all the threads running.
  3. Loop count — Defines the number of times to execute the test.

For example, First of all we will create a Thread Group where we will set Number of Threads, Ramp-Up Period and Loop Count. As you can see in below screenshot

We can change Thread Group name by clicking on Name field, enter new name and saved.

Sampler:

  • Samplers allow J-Meter to send specific type of requests to a server
  • J-Meter supports testing HTTP, FTP, JDBC and many more protocols
  • Thread Groups simulate user request to the server
  • Samplers help the Thread Group to know which type of requests (HTTP, FTP etc.) it needs to make.

To add HTTP Request: Right click on Thread Group > Add > Sampler > click on HTTP Request, like below screenshot

For example, I have to perform load testing on create order API, so i will add one HTTP Request for create order and i will pass query request of create order in body data as you can see in below screenshot

HTTP Request:

In the same way we will add HTTP Request for our all APIs or web pages on which we have to perform load testing.

My APIs are graphql APIs so my url and headers are same for every APIs. In this case instead of adding header and url for all APIs i will add Config Element and will pass headers and url from one place.

See the next step for adding config elements.

Configuration:

  • Configuration elements are used to set up defaults and variables for later use by samplers.
  • Below are some important config elements
  1. CSV Data Set Config : The csv Data Set Config allows you to read different parameters from text file. It is used to read lines from a file, and split them into variables.
  2. HTTP Cookie Manager : HTTP Cookie Manager has the same feature as a web browser. If you have an HTTP Request and the response contains a cookie, the Cookie Manager automatically stores that cookie to use it for all future requests.
  3. HTTP request default : This element lets you set default values that your HTTP Request controllers use.
  4. Login Config Element : The Login Config Element lets you add or override username and password settings in samplers.

To add HTTP Request Defaults : Right click on Thread Group > Add > Config Element > click on HTTP Request Defaults, like below screenshot

For example, In my APIs i need to add HTTP Header Manager and HTTP Request Defaults so that i will pass header and url from one place and there is no need to enter for each HTTP Request separately. As you can see in below screenshot.

HTTP Header Manager:

In this have added all headers which required in my APIs.

HTTP Request Defaults:

In this only we add url on which we have to hit the request.

Now let’s think if we have a request where we have to test for multiple user data then how we can do.

For example, In my API it need to pass different headers for different user, in this case i have created a csv file on local folder and created columns for From,Authentication,UserDevice, deviceId etc…and enter multiple data in those columns and saved that file. Now in j-meter create csv Data Set Config from Config Elements and click on Browse button and import that csv file from saved location. As you can see in below screenshot

And in variable names field we enter columns name with comma separated in the same order how we have saved in csv file.

Now add the listener and run the test and you can see the results.

Listener:

  • Listeners show the results of the test execution.
  • They can show results in a different format such as a tree, table, graph or log files.
  • Graph result listeners display the server response times on a Graph
  • View Result Tree show results of the user request in basic HTML format
  • Table Result show summary of a test result in table format
  • Log shows summary of a test results in the text file

Running Test Plan:

After adding all elements Run the Test Plan by hitting on Start button or (Control + r) from the Run menu item. When J-Meter starts running and we will get the results based on listener added in our test. We can add as many listeners as we want from listeners list. But this is not a good idea to add many listeners because it will slow As you can see in below screenshots.

Summary Result:

Graph Result:

View Result Tree:

J-Meter has many listeners which provide useful information like

  • Number of requests processed
  • Average response time
  • Throughput
  • Deviation
  • Error % etc

Note: All Listeners save the same data, the only difference is in the way the data is presented on the screen.

That’s it for this blog. In the next part, we will see how we can add plugins in JMeter and how we can use it.

--

--