JMeter

I, Arslan Mirbzergi,in this article, I would like to meet you with another software called JMeter, which is one of the products of Apache. In previous articles, you were familiar with various open source software and programs. The software was created to apply load testing on a server or group of servers or networks. Below we will review more details about JMeter together. Be with us.

Various components of JMeter

Each component of JMeter is called an element or element that is built for a specific purpose.

In this article, we will talk to you about other required elements such as Thread Group, Samplers, Configuration and Help.

Thread Groups

Thread Groups actually includes a set of threads. Each Thread represents a user who is using the software under testing. In other words, each Thread is a simulated user instance that sends a request to the server.

A thread group allows you to control a number of threads. For example, if the number of Threads is assumed to be equal to 100, JMeter will redirect 100 users simulated to the server that is being tested.

Sampling or Samplers

JMeter supports HTTP, FTP and JDBC and other protocols for the testing process. In this case, the user’s request can be http request, JDBC Request or FTP Request.

FTP Request

This controller in JMeter allows you to send a request (download or upload) to the FTP request server.

For example, if you want to send a “Test.txt” file from an FTP server tested by JMeter, you need to change some of the parameters in JMeter as shown below.

JMeter sends the FTP command to the ftp.example.com server and then downloads a Test.txt file from that server.

HTTP Request

This controller in JMeter allows you to send an HTTP/HTTPS request to a web server that is undergoing testing. In the example below, JMeter sends an HTTP request to Google’s site, then recovers HTML files or images from this website.

JDBC Request

This controller in JMeter relates to database performance testing. In the example below, a JDBC request (an SQL query) is sent to the database.

Suppose we have a database server with a test_result value in a table called test_tbl. If you want to test a search to retrieve this data from the database, you can configure the corresponding JMeter software to send a SQL search to this server.

BSF Sampler

This example allows you to create a sample using a programming language. Below you will see an example of BSF Sampler running on JMeter.

Access Log Sampler

By insampler, you will be able to read the log files as well as access these logs. In addition to that with this sampler, you will also have the ability to generate HTTP requests.

SMTP Sampler

SMTP Sampler is used to test the server of an e-mail. This sampler uses the SMTP protocol to send texts of each email to the server you specify.

Listeners

Once you have done the load test, you can view the results by The Hears in the form of trees, graphs, tables, charts, along with the log file.

In The Informeds, which are displayed in the form of a chart, the server response time is shown as a chart.

In View Result Audios, the user’s request result is displayed as a public HTML file.

In Table Result’s Syndes, the test results are summarized and displayed as tables.

In Log Result-type Synods, such as Table Result type Syndes, the test results are summarized and displayed in table format.

Configuration Elements

Configuration Elements means configuring elements or setting a default value for variables, in order to use them, next time. In the figure below, you can see some of the routine configuration components in JMeter.

Configured Dataset or CSV Data Set Config

If we have a site with about 100 users, and each of these 100 users has a different level of credibility and want to test them, we need to run JavaScript 100 times. It is also necessary to enter different credentials in the script parameter for each login. This information, which can include a username or password, can be stored in a text file. JMeter also has an element by which different parameters of the text file are read. This feature is known as CSV Data Set Config in JMeter.


In the photo below, you’ll see an example of CSV. In this text file, the username and password needed to login are stored.

HTTP Cookie Management (HTTP Cookie Manager)

Managing cookies is one of the most important and key issues in the IT world. When you use a browser to open a site like Google and enter your username and password, this username and password will be stored as cookies in your system. If you want to log in again, you won’t need to re-login your username and password. This is controlled by HTTP Cookie Manager when it comes to different passwords and usernames. When you have an HTTP request, along with a response that contains a cookie, HTTP Cookie Manager or Cookies Management automatically stores that cookie for future use.

HTTP request default

With this element, you can set the default values used to control Http Request. For example, suppose you’re sending 100 HTTP-type requests to google’s site server. In this case, you must manually enter the name of the server you want, which is google site, for every 100 requests. Of course, you can add only one HTTP request by default with the name or IP of its server instead. No need to type the server name 100 times.

Login Config Element Configuration:

By this element, you will be given the ability to add or ignore usernames and passwords in samplers. For example, if you want to simulate a user’s login to a specific site with a user and password, you can use Login Config Element.

CSV Data Config

CSV Data Config is used to simulate user logins, simulate the number of user logins, simulate the login parameter only (user and password) and also to use in large numbers of parameters. After installing JMeter, you have two elements. One element, Test Plan and another element is Workbench, which in the new JMeter, workbench examples does not exist separately and has been added to TestPlane.

Test Plan

In the Test Plan, you can add the elements you need for the JMeter test. In this section, all elements including Thread Group, Timers, etc. As well as the settings that are needed to run the test you are considering.

In the figure below, an example of the test plan is displayed.

Add Elements

Adding elements is essential for building a test program, because without adding elements, JMeter is unable to perform the test. Test Plan includes many elements such as The Controller, Controller and Timer. You can add new elements from the selection list by right-clicking on test plan. To better understand this issue, suppose you want to add 2 elements of BeanShell Assertion and Java Request Default to test plan. For this purpose, you must proceed according to the following steps:

1- Right-click on Test Plan

2- Add Bean Shell Assertion from Assertion option

3- Right-click on Test Plan

4- Add Java Request Default from Config Element option

Save Elements

Supposing you have added the BeanShell Assertion element and now you want to save it. To do this, right-click on the BeanShell Assertion and select Save Selection As.

After displaying the dialog box, select the default name and click the Save button to save this element. The name of this element can also be changed later.

JMeter tests elements as well as Test Plan (test program) in * format. JMX saves.

Loading elements

By loading elements, you can save the time you need to create and configure new elements. For example, if we want to load an element in Java Request Default and in the Test Plan section, you must first right-click on Java Request Default and then select Merge.

Then, among the available elements, select the BeanShell assertion.jmx element and add it.

Configure elements

To configure each element, you need to select the element from the left window and enter the settings you want in the Settings section.

Run and Stop Test Plan

Before running a test, you need to save the Test Plan (test schedule) related to your test, for the first time. Saving to the test program helps prevent unexpected errors while the test program is running.

Steps to Save Test Plan

First, from the File menu, click save as to open the dialog box. Then, in the section specified for the name, enter the test plan and click save. Note that saving a test plan is different from saving an element. Test Plan contains one or more elements where the element is a basic component of JMeter. When you save a Test Plan, all elements that are available in that program will also be saved.

 Performance Testing

Performance testing to determine whether a request sent to the web or application under the test has the ability to load or load heavy or not?  Very important. By the result of this test you can analyze how a server works versus heavy load.

Advantages of JMeter test tool in performance testing:

To test performance, JMeter can use static resources such as JavaScript and HTML, as well as dynamic sources such as JSP, Servlets and AJAX. JMeter can specify the maximum number of users your website can handle at the same time. JMeter is also able to display a variety of graphical analysis from its performance report and results.

JMeter performance testing generally includes the following.

Load Testing

A method for modeling multi-user simultaneous use is by simulating how many users have access to web-related services.

Stress Testing

Each web server has a maximum load capacity. When the load on this web server exceeds the limit, the response speed drops and error generation increases. By stress testing, the ultimate tolerable load of the web server is determined.

The following figure shows how JMeter simulates heavy load.

Create Test Plan to Test Performance in Jmeter

In this article, we conduct a performance test for Google’s website and with 1,000 users. Before starting the performance test, we need to specify the normal load, i.e. the average number of users visiting your site and the heavy load, i.e. the maximum number of users visiting your website. You should also know what your goal is in this test?

The following image shows the roadmap for this test.

The steps of this test are as follows:

Step 1:

Add thread group. This is by running the JMeter program and selecting Test Plan and right-clicking on Test Plan, followed by adding the Thread Group.

In the Thread Group control panel, you need to fill in the Properties section as follows.

Number of Threads relates to the number of users who connect to the target website.

Count also shows the amount of time it takes to run the test. Ramp-Up Period also indicates the latency period before the start of the process related to the next user.For example, if we have 100 users and a time period equal to 100 seconds, the time lag between users to start will be 1 second. (100 users / 100 seconds) = 100

In the figure below, you can see the difference between Counts Thread and Loop Counts.

Step 2:

Add JMeter elements. At this point, we specify the elements needed for testing in JMeter.

HTTP request Default

To add this element, you must right-click on Thread Group and then select Config Element and HTTP Request Defaults, respectively.

In the HTTP Request Defaults control panel, you must enter the name of the website to be tested. For example (http://www.google.com)

HTTP Request

To add this element, you must right-click on Thread Group and then select Sampler and HTTP Request respectively.

In the HTTP Request control panel, the Path section indicates which URL or which google server path is sent through the request you want.

For example, if you enter a value equal to “calendar” in the Path section, JMeter will redirect the URL request you want to http://www.google.com/calendar to google server.

In contrast, if the inside of this field is empty, JMeter will redirect the requested path to google server as http://www.google.com URL request. In this hypothetical test, leave the field blank so that JMeter redirects the URL request to the Google server http://www.google.com.

Step 3:

It is related to the addition of the resulting graph (Graph results). JMeter has the ability to show the test result in the form of a graph. This is by selecting Test Plan and right-clicking on The Helper, followed by adding the Graph Results.

Step 4:

It relates to test execution and viewing results. To start the software testing process, press the Run button from the toolbar or its shortcut equivalent (Ctrl+R) and see the test results on the chart at runtime. In the image below, you will see the diagram of a pilot scheme in which we have simulated 100 users who have been present at the moment on www.google.com website.

The color codes at the bottom of the image also have a special meaning. The black code means the total number of current samples sent, the blue code means the current average of the samples sent, the red code means the current standard deviation, and finally the green code also means the amount of production that indicates the number of requests per minute towards the server. In the following, we want to analyze the performance of Google’s server.

To analyze the performance of the web server under the test, you need to focus on 2 parameters. These 2 parameters are throughput and deviation.

Throughput performance is a very important parameter. This indicates the server’s ability to load heavy loads. The higher the density, the better the server performance. In this hypothetical test, the performance of google’s site server is 1491163 per minute. This number means that Google’s server can make 1491163 requests per minute. This is a very reasonable amount. Given this result, we can assume that Google’s server has a good performance in this case.

In this form, the deviation rate is shown in red. This deviation actually indicates a deviation from the average, and the smaller it is, the better.

Step 5:

At this point, we want to compare google server performance with another server. This time performance test will be about http://www.yahoo.com/ website, which of course you can test other sites as well.

Website performance under http://www.yahoo.com testing is 867.326 rpm. This means that this server can respond to 867,326 requests per minute, which is lower than Google. Its deviation rate is also 2689 and is much higher than Google’s deviation rate (577). According to the result of this test, we can withdraw that the performance of Yahoo’s website is lower than google’s server.

Notice that reaching high values is due to several factors such as the current server load on Google, your Internet speed, the CPU power of your system, etc. Depends. So, it’s far from expected that you’ll get the same results above.

Troubleshooting

If you encounter any problems while performing the above steps, you should do the following:

First, check if you are connected to the Internet through a proxy. If the answer is yes, you need to remove the proxy. Then open a new JMeter sample and open Performance Test Plan .jmx in JMeter. Then run the test by clicking on Thread Group and then clicking on Graph Result.

Supposing you have a Test Plan called Test_Fragment.jmx on your system. You have the possibility to integrate this test program with the test program that is running on your JMeter and build a new test program.

As you can see in the figure below, all elements that are available in the current testing program will be added in the Test_Fragment.jmx file to the test program that is running.

Run Test Plan

To run one or more test programs, click start or press the keys (Ctrl+R).

When JMeter is running, a small green box is specified at the right end of the program menu bar.

The number on the left side of the green box indicates the number of threads (threads) active and the number on the right side also indicates the total number of threads. To stop the test program as well, you can press the stop button or use the shortcuts Ctrl +’.’   Use.

Test Report

When the test program is finished, you will be able to receive a test report or test schedule. This report contains log file errors and a summary of the test result that is stored in the jmeter.log file.

And in the end,

If we want to use either post or get method in JMeter, we can do so using Json extractor or stackoverflow. To better understand the process, you can view https://www.youtube.com/watch?v=KufhkXgwKFQ videos as well as https://stackoverflow.com/questions/42151962/jmeter-how-to-use-extracted-value-from-response-in-body-data-of-another-reques. 

For this purpose, we must first create the thread group, in the photo above, we have a loop and a yuzer that can be changed.

Then we create http request. In the path section, the same api is available in the controller section, and in the body section, the same json is placed in the postman section.

In this section, right-click on http req and add http header manager for the json/app we are using.

We then click on any request we want to take id or anything that is generated and used immediately. Then right-click on the corresponding http req and add json extractor. If we need two values, we put two values in the json path ex section, and at the top we put two new names for it. About this section, you can see a sample in the link from youtube.

Then we put another http req that wants to use the built-in value, and it’s as high as above, in the path variable debug to see if that new value is created.

The Pot model should be like the case above.

For this pot, we also need a header that we create according to the figure above.

From Lissner, we also create a tree to display the result.

http test script recorder

In the following, we want to check a site, but we don’t know its api, and we also want to do 100 logins and log-outs or anything else. For this purpose, we take action through the commands https://www.youtube.com/watch?v=KufhkXgwKFQ in the video. In this case, http test script recorder or recording controller is used. At the end of the article, we also include the JMeter download link. We hope you have made sufficient use of this article.

JMeter download link:

https://jmeter.apache.org/download_jmeter.cgi