There are many load testing tools out there but ApacheJMeter is one the most reliable tools, you are ever going to use for load testing as it provides a variety of services and mainly focus on web applications.
It is projected by Apache Software Foundation and supports a variety of reports, configuration variables, response validation, per-thread cookies and variable parameterization.
It is an open source desktop Java application and is used to give load to various scenarios and performances related to the output data in different ways such as XML files, CSV files and graphs.
In order to use Apache JMeter to carry out load testing on web server you need to follow these steps:
You will need:
- A computer which is able to run JMeter
- Web server to load test
In order to run the load make sure your production servers are able to survive the load, otherwise the performance of your server will be badly impacted.
You will also need to take into account that various factors play a role in impacting JMeter test results such as system resources and web servers available to the network and JMeter and being tested respectively.
In order to increase the size of the load the JMeter is able to generate without any errors you can either:
- Increase the load by using non-graphical mode for running the tests
- Distribute the load to multiple JMeter servers.
It’s also important to prepare your server for load testing. For example, if you’re using a shared server or are using some type of web hosting for nonprofits, you should take the time to make sure that your host can actually handle the load testing. Sometimes having a nonprofit website with lower-tier hosting means that you’re put on a smaller server that can’t handle the load test, although this isn’t always the case.
STEP 1: Installation of JMeter:
JMeter is relatively easy to install. You can either install it by downloading and archiving the JMeter binaries from their official site and installing Java or you can use a package manager such as Homebrew or apt-get.
In order for JMeter to locate Java and key tool binaries, you will need to add the Java bin directory to the PATH, but it solely depends on how you install Java.
Once the JMeter is installed and is being run, you need to build a test plan.
STEP 2: Formation of Test Plan:
Once you have opened the JMeter, you are able to see GUI with an empty Test Plan.
A Test Plan is basically used in determining how the website load test is going to stimulate as it comprises of test components sequence.
STEP 3: Addition of the Thread Group:
You need to add the Thread Group to Test Plan.
- Right click on Test Plan
- Move the cursor to Add
- Move the cursor to Threads (Users)
- Click on the Thread Group
You need to know that the thread group has three important properties which generally impact the load test. These are:
- Number of threads (Users):
JMeter will use this respective quantity in order to simulate the number of users that you are going to type.
- Ramp up period (in seconds):
Time required by the JMeter for distributing the start of the threads over.
- Loop count:
How many times do you want to execute the test is determined by the loop count.
STEP 4: Addition of HTTP Requests Defaults:
The default configuration element of HTTP is used to adjust default values for HTTP Requests in the test plan.
This is particularly useful if you want to send a number of HTTP requests to the same server as a part of the test.
For adding HTTP Request Default to Thread group you need to:
- Select Thread Group and then right click it.
- Move the cursor to Add
- Move the cursor to Config Element.
- Click on HTTP Request Defaults.
Under the Web Server section, in HTTP Request Default, type in the server name or IP address of the server you want to test. This will make the server act as a default server for the remaining items in the thread group.
By adding HTTP Cookie Manager to the Thread Group, you are able to support your web server in using the cookies. You can add HTTP cookie manager by:
- Selecting thread group and right clicking it.
- Moving the cursor to Add.
- Moving the cursor to config element.
- Clicking on HTTP cookie manager.
STEP 5: Addition of HTTP Request Sampler:
HTTP Request Sampler is used for representing a page request that will be accessed by each thread or user.
In order to add HTTP request sampler to the thread group:
- Select the Thread Group and right click it.
- Move the cursor to Add.
- Move the cursor to Sampler
- Click on HTTP Request.
Fill in the Path with the item you want each thread to use. The path is located in the HTTP request which is below the HTTP request section.
Set the item to / in order to let the thread access the homepage of the server.
If you want to add more requests, you can repeat this step.
STEP 6: Addition of View Results in Table Listener:
Listeners are basically used to execute the result of the load test in JMeter. A variety of listeners already exists and more can be added by installing plugins.
For using the table because it is the easiest to read you need to:
- Select the Thread Group and right click it.
- Move the cursor to Add
- Move the cursor to Listener
- Click on view results in the table.
STEP 7: Running the Test Plan:
After setting up your test plan it is time to run it and execute the results.
- Save the test plan by clicking on file.
- Click on save and point out the desired file name.
- Select view results in table located in the left pane
- Click run in the main menu and click start.
- You will be able to see the test result in the form of a table.
STEP 8: Interpretation of results:
After performing the test, you will notice in the table that the status of all the requests is success which is shown by green triangles and a checkmark in it.
You need to notice two there things as well:
- Latency time: the time between sending of the request by the JMeter and receiving of the initial response.
- Sample time: the time required by the server to serve the request completely. (In milliseconds).
STEP 9: Increasing the load:
You can increase the load by changing the number of threads in the thread group as described in the third step.
When the number of threads is increased you will notice a change in sample time as well, now it will take seconds to serve the results instead of milliseconds which show that the system has started to become overburdened by the request. In order to meet the needs of more threads you need to:
- Increase the CPU
- Optimize the ever setup to use less CPU.
You can do this by logging in to the VPS and quick checking the resource usage during the test.
- Log in to the web server via SSH.
- Run top. You will see that CPU % user usage % is very low and CPU % idle will be more than 99%.
- Start the test again in JMeter and log back into the SSH session of your web server. You will notice a rise in CPU % user usage and decrease in CPU % idle.
JMeter is an essential tool in setting up your web server and improving it. It also helps in the removal of bottlenecks and makes the web server perform efficiently.