JMeter — Performance and Load Testing: Beginner’s Guide | Part I
JMeter is an open source Java application designed to load test functional behavior and measure performance. It is platform independent and can conduct load and performance test for many server types.
Performance testing is crucial to determine that the web application under test will satisfy high load requirements. It can be used to analyze overall server performance under heavy load. JMeter can not only discover the maximum number of concurrent users that your website can handle, but also provides a variety of graphical analyses of performance reports.
JMeter is one of the most popular tool in the market used in performance & load test.
Pre-requirement: Make sure Java JDK is already installed. JMeter is compatible with Java 8 or higher.
Download JMeter: https://jmeter.apache.org/download_jmeter.cgi
Launch the following from
/bin folder using terminal.
For Mac: sh jmeter.sh
For Windows: just click on executable jmeter.bat file.
How to record a test
In order to use recorder, we need to either adjust port settings for Firefox browser (Open/Network settings: Choose manual proxy configuration and give the port number whatever you provided in JMeter), or we can directly use Blazemeter Chrome extension, which I find it very useful.
There are also some other third party tools, such as Badboy Software (Windows only), which can be downloaded and used for the recording. I will just demonstrate shortly how it seems on Blazemeter tool.
In order to start executing recording, we just need to log-in first.
Once the recording executed on the website it should be saved as .jmx file, so that we can use it in our JMeter platform.
Then, we just need to open it with JMeter, and all recording items, such as visited web pages, all requests and responses will be shown there. We don’t need to enter something manually, thread group will be created automatically. We just need to set the number of threads and listeners to see and analyze the result.
Basic terminology in JMeter :
Test Plan : A test plan describes a series of steps JMeter will execute when run. A complete test plan will consist of one or more Thread Groups, logic controllers, sample generating controllers, listeners, timers, assertions, and configuration elements.
Thread Group : A thread group is a set of threads executing the same scenario. Set the number of iterations in the configuration.
Number of Thread(Users) : Number of users to be tested with.
Ramp Up Period : Ramp up period defines the amount of time in which all users will be initialised like in 10ms 100 (Number of Users)
Loop Count : It defines the number of times Thread Group will execute.
Samplers : Samplers tell us which type of request is to be sent like HTTP,HTTPS etc.
Ramp-Up Period tells JMeter how long to delay before starting the next user. For example, if we have 50 users and a 5-second Ramp-Up period, then the delay between starting users would be 0,1 second (5 seconds /50 users). In other words, 50 User will be launched in 5 Seconds. If we had defined Ramp-up period as 50 seconds for instance, the interval between users would be then 1 second.
We can either click Loop count option as infinite and specify duration (e.g. 30 sec.), or we can give a number (e.g. 5 sec.)as a loop number, which means the process will be repeated at that given number.
How to use Assertions in JMeter
There are lots of assertion available in JMeter, such as Compare Assertion, Duration Assertion, HTML Assertion, XML Assertion, or Size Assertion. As the name suggests, we can make basic checks on the response.
The most common used ones are Response Assertion. We can assert response header, request header, URL…etc. For instance, we can verify whether Response Code equals to 200.
By adding Assertion Results as a Listener, we can easily monitor the results.
In case there is an assertion failure, we can see it as Test failed with a detailed explanation.
Another common assertion type is Size Assertion. We are checking below example whether the server can handle min 3000 Byte size response.
In the same way, Duration Assertion shows us, whether the response time for each end point equals to, greater than given milliseconds. HTML, or XML Assertions also shows us, whether we have valid HTML or XML response. Based on our needs, we can use those assertions separately or together in the same request.
Listeners in JMeter
The most used one is View Results in Table, so that we can see the whole result, and we can analyze the response.
Latency: It is the time when the first piece of information is received i.e. the first byte of data is received.
Connect Time: It is the time taken to establish connection with the server.
Sample Time: It is the time taken to receive all data.
Sample — Sequence of sample number.
Bytes — Size of data received.
Another most common is View Results Tree. This listener shouldn’t be used if we are planning to set a heavy load of performance test, since it takes up a lot of memory. It is better to use it at the beginning of our load test to see whether everything is working fine. It shows us the whole details, including the request and response data.
We can use an Aggregate Report, if we want to see the tho whole result as a single line for the available samples. We have 3 samples below example, and we can see the total accumulation as well.
Average shows us the average of all our requests (milliseconds), Median: Half of the requests took more than this millisecond (878 ms in above example for the first one). In the same way %90, %95, %99of the requests took than this millisecond. Most of the time, 99 percent will be equal to the max value, as it covers %99 of the request. The number of request per second will be shown as Throughput. In other words, our server is able to handle 2,5 request per second in the second sample.
We could also see above explained details in a graphic by using “Graph Results” listener.
The Throughput as explained above represents the ability of the server to handle heavy load. The higher the Throughput is, the better is the server performance. The deviation is shown in red — it indicates the deviation from the average. The smaller, the better. As we can observe, at the beginning of the test Throughput and average have similar values — as the time progress, the average value is getting lower, since we are hitting the same request repeatedly, and the cache is being developed.
How to create a simple test in JMeter
All in all, the process is very straightforward. Since we know the basics as of now, we can execute our tests, make our assertions, and with the help of Listeners, we can analyze our responses. There are some certain steps that needs to be followed.
- Start JMeter
- Create a Test Plan
- Create a Thread Group
- Add a sampler (Https)
- Add Listeners
- To run the test and analyze the result
After filling all the required fields above, all we need to do is executing tests and see the results.
As it can be seen, this short tutorial aims only those, who have just begun to use JMeter as a performance and/or load testing tool. With above-mentioned basics, we can actually handle most of our job. In the following article, I will try to cover some other details, such as using controllers, cookie manager, timers, regular expressions, how to execute tests from the command line, and receiving awesome HTML report, finally how to execute data-driven testing, which will be the most common real life usage.
Stay tuned :) Happy testing!