📜 ⬆️ ⬇️

How to create a load test using Apache Jmeter

In this post I will describe how to create a load test of a web application with the help of a load testing tool developed within the Apache Jakarta Project - JMeter .

JMeter is a very powerful load testing tool with the ability to create a large number of requests at the same time thanks to parallel work on multiple computers. Supports plugins, with which you can extend the functionality. The tool I used earlier when testing large Internet banking. You can download JMeter via the link http://jmeter.apache.org/download_jmeter.cgi , to start you need to go to \ bin \ jmeter.bat.

Having started the program, on the left we see 2 points - Test Plan and WorkBench . Add Thread group in Test plan, for this you need to right-click on Test plan - Add - Threads (Users) - Thread group.
')
image

Next, inside the Thread group, create the test settings elements, right-click on the Thread group - Add - Config Element and select 4 items in turn:

The next thing to be done is to add an HTTP Proxy Server . Right-click on WorkBench - Add - Non-Test Elements - HTTP Proxy Server. In the HTTP Proxy Server settings, we specify any unique port address (I always use 8089) and uncheck the Capture HTTP Headers.



Now we go to any browser to configure the proxy server on it. I prefer Firefox for such purposes. In the network settings, we specify the use of a proxy and enter the HTTP Proxy - localhost, the port - 8089 used by us. Do not forget to remove the exception for localhost.

We return to the Jmeter in the HTTP Proxy Server and click the Start button at the very bottom. Now back to the browser, and load all the interfaces that need to conduct load testing.

Go back to Jmeter and click Stop in HTTP Proxy Server.

In a situation in which you need to edit the host settings for those packages in which they are different from HTTP Request Defaults, it is more convenient to do this as follows. Save the project (File - Save), and close it. Open the saved * .jmx file with Notepad ++ (or Notepad) and delete the values ​​of all the lines:
domain
port
protocol
and all other parameters that need to be changed. Save the file and open it in Jmeter. Return values ​​in HTTP Request Defaults. Now they apply to those requests that have their own settings.

Next, clear the project, he unnecessary information. Some packages refer to third-party services that we don’t need to load. They need to be removed. To do this, go through them all and see what is the value of Server Name or IP. If the server name is not related to the resource being tested, we will not create an additional load on it. We delete such url (by pressing del):



And such leave:



If in url we need to register a link with a parameter or change the current one, click on the url in which to insert (edit) the parameter. In the column Parameters make the necessary changes.

If necessary, specify the parameters via variables, add to Thread Group User Defined Variables by clicking on it with the right key - Add - Config Element - User Defined Vaiables. Add variables by specifying their Name and Value. Now we specify the parameters as variables in the format in the format $ {VariableName}.

Add to the Thread Group in turn the elements of the view. Right click on Thread Group - Add - Listener - Graph Results , Aggregate Report , View Result in Table and View Result Tree .

The last setting before launching is to specify the number of users (Number of Threads) and the number of iterations (Loop Count) by clicking on the Thread Group and setting the corresponding parameters.


You can distribute testing by running multiple copies of the test on different hosts, but managed from one central location. This increases the load and is done as follows:
  • On the server computer, run the file / bin / rmiregistry.exe. If this file is missing from the build, download it through a search engine. If at startup the file swears at the absence of the jli.dll library, download it also (for example, here www.search-dll.com/dll-files/download/jli.dll.html ) and drop it in windows / system32 (system64).
  • We open /bin/jmeter.properties via Notepad ++, here it is necessary to remove the comment from the line server.rmi.create = false, deleting the “#” character at the beginning of the line.
  • Run /bin/jmeter-server.bat.
  • On the client, in the /bin/jmeter.properties file, you need to specify the hosts in the remote_hosts line, for example remote_hosts = 10.1.100.101, 10.1.100.102, 10.1.100.103, and then restart Jmeter.
  • We start the test by selecting the menu item Run - Remote Start (to start one host) or Run - Remote Start All (to start all hosts).

All is ready. We start the test by pressing the green triangle on the top panel and open any of the viewing elements - we have the statistics online. Since we installed Loop Count - Forever, click Stop after testing. Now, in order for each item viewed.

Graph Results will display the result as a graph:



Values ​​are provided in milliseconds.
Data - the response time of each individual data unit i.e. every checked url.
Average - the average response time, an objective graph of load changes.
Median - median value (used in statistics, I do not use these data).
Deviation - error, standard deviation.
Throughput - the bandwidth of the queries performed.

For the work, the Average and Throughput values ​​are sufficient, which show the load on the web server and the bandwidth of the requests. From the graph above it can be seen that the response time is about 200 ms and does not grow, that is, the server normally maintains a load of 3 virtual users. But what happens if there are 30 of them:



The response time is significantly increased, the higher the throughput of requests (less milliseconds), the more time is required for the server to process.

By the way, at the time when the test is launched, the site really falls, so you should not check for load third-party Internet resources, because we can be taken for ddoserov.

Aggregate Report displays statistics for each individual url separately.



In the Average column we see the average response time, it is logical to assume that the larger it is - the greater the load on this url.

View Result in Table will display the result as a table, the time is shown here, as well as the status (successful / not successful).



The bottom line is an error. Why it arose, you can check in the View Result Tree . We go there and find this line. Now we see the cause of the error.



This testing is completed. During it, we checked one of the web applications for workload, and got very visual results.

Source: https://habr.com/ru/post/165159/


All Articles