Getting started with Apache Jmeter
Increasing usage of web based application has raised a need to test the performance of web-based applications for speed i.e. responsiveness of the application, scalability i.e. sustainabilty of an your web application at peak load or maximum users load and stability i.e stable state of the system under peak load. In order to conduct these performance tests against web applications we need to bombard the system with humongous amount of load in terms of requests and monitor system differently depending on the goal of the test. One of the most widely used open source tool for performance testing is JMeter. I will be covering JMeter in detail right from recording to most of commonly used JMeter components like Transaction Controller, Authorization manager and also issues with recording https requests and so on.
What is JMeter?
Apache JMeter is an Open Source tool mainly used to test performance both on static and dynamic resources (files, Servlets, Perl scripts, Java Objects, Data Bases and Queries, FTP Servers and more). It can simulate a heavy load on a server, network or object to test its strength or to analyze overall performance under different load types. It can also be used for graphical analysis of performance or to test your server/script/object behavior under heavy concurrent load.
You need jdk 1.6 in order to use JMeter 2.8 and above. Make sure that you have made appropriate entry in PATH variable.
You can get latest JMeter build from: http://jmeter.apache.org/download_jmeter.cgi
JMeter UI can be launched in two ways:
- Open JMeter folder -> Bin -> Double Click on JMeter.bat file
- Open command prompt and go to Apache JMeter directory using cd command.
And type JMeter.bat
If you are working behind proxy, you are bound to get “socket connection” exception if you launch JMeter as mentioned above. You need to launch JMeter from command prompt as below if you are working behind proxy.
JMeter.bat –H “proxyname” –P “PortNumber” –u “username” –a “Password”
This will resolve initial “socket connection” exception caused due to proxy.
You will see JMeter UI as below once you launch JMeter using any of the above mentioned ways.
When you launch JMeter it has TestPlan and WorkBench by default. We will look into these components one by one.
What is a TestPlan
Test Plan usually contains overall the setting for your JMeter script. You can add user defined variable which can be referred across all the threads coming under the test plan.
You can see three check-boxes when you click on TestPlan.
- Run Thread Consecutively: By default all the threads coming under test plan run concurrently. If you check this option threads will run one after other.
- Run tearDown Thread Groups after shutdown of main threads: if selected, the tearDown groups (if any) will be run after graceful shutdown of the main threads. The tearDown threads won’t be run if the test is forcibly stopped
- Functional Test Mode: If you check this option JMeter will save additional sample information – Response Data and Sampler Data to all result files affecting the performance of system.
What is a WorkBench?
The WorkBench simply provides a place to temporarily store test elements while not in use, for copy/paste purposes, or any other purpose you desire. When you save your test plan, WorkBench items are not saved with it
Certain test elements are only available on the WorkBench:
Now let’s begin with recording in JMeter:
You need to add a ThreadGroup to TestPlan and add HTTP Proxy Server to WorkBench as first step to begin with recording.
We will talk in detail about ThreadGroup and HTTP Proxy Server later. For now make the settings as shown below to begin with recording.
Configuring your web browser to record requests using JMeter
You need to modify your connection settings so that JMeter will capture all the requests which are being sent from your browser to target application. Modify your browser settings as shown below.
Make sure that the port number mentioned in JMeter HTTP Proxy Server and Port number mentioned in connection settings should be same.
Now go to JMeter UI, select HTTP Proxy Server and click on start button as shown below.
Now go to your already configured web browser and type url of the target application. All the requests will be captured in TestPlan->ThreadGroup as you record your workflow as shown below:
Follow above mentioned steps and am sure you shall be able to record HTTP requests using JMeter.