Performance and Load Testing with JMeter
ABOUT JMeter
The Apache JMeter™ application is open-source software, a 100% pure Java application designed to load test functional behavior and measure performance. It was originally designed for testing web applications but has since expanded to other test functions. You can use JMeter to analyze and measure the performance of web applications or a variety of services.
Features
· Open source license: JMeter is free, and allows developers to use the source code for their own applications.
· Platform independent: JMeter is a 100% pure Java desktop application. So it can run on multiple platforms
· Full multithreading framework: JMeter allows concurrent and simultaneous sampling of different functions by a separate thread group
· Visualize Test Result: Test results can be displayed in different formats such as a chart, table, tree, or log file
· Easy installation: You just copy and run the *.bat file to run JMeter. No installation is needed.
· Multiple testing strategies: JMeter supports many testing strategies such as Load, Performance, Stress, and Functional Testing. (I usually use it too often for the Load and Stress test. :) )
· Support multi-protocol: All basic protocols such as HTTP, JDBC, LDAP, SOAP, JMS, and FTP are supported by JMeter. ( I’ve been working on HTTP protocol in my experience.)
Requirements
JMeter has minimum system requirements;
Java Version: JMeter is compatible with Java 8 or higher.
Operating Systems: JMeter is a 100% Java application and should run correctly without operating system dependency.
Why Is Jmeter Needed?
When we need Load, Stress, or Performance testing, we can use Jmeter. In this way, we can handle more than one need with a single tool. Knowing the Performance, Load, Stress or Functional Testing will help us understand our needs.
a) Performance Testing: Performance Testing allows us to test whether the applications work within the planned performance criteria. Each application should have some performance criteria. They reflect our approach to the quality of the product.
b) Load Testing: It is the type of test that gives information about how much load the system can carry, while still working with maximum performance. It is done to understand how much load the system can tolerate. it is easier to determine the load-balancing servers or the necessary hardware required by a system whose performance test has been completed.
c) Stress Testing: Stress Testing is a type of test, performed to observe how the system behaves under a load above the planned maximum capacity, and most importantly, at what point it breaks. The expected behavior is that the application remains stable in producing accurate results after the test is over.
d) Functional Testing: It is the technique used to test the features and functionality of the system or software. Functional Testing looks for answers to questions such as “can the user do this” or “does this feature work”.
How Does JMeter Work?
JMeter simulates a group of users sending requests to a target server, and return statistics information of the target server through graphical diagrams.
JMeter Components : In order to use the Jmeter with all its functions, we must first understand all its components.
a) Thread Groups:
Thread Groups is a collection of Threads. Each thread represents one user using the applications under test. Basically, each Thread simulates one real user request to the server.
- Set up a number of threads
- Set up a ramp-up period
- Number of times test execute
Elements of Thread Groups:
Ramp-up Time
Assume that the applications we offer in our test are wanted is to be tested for 1000 users. It is not very realistic to let all 1000 users in the system at the same time. Ramp-up Time determines how many seconds 1000 users will be included in the system by the test tool. When the Ramp-up Time is given as 20 seconds for 1000 users, 50 users will have entered the system at the end of the first second.
Loop Count: Loop Count is the total number of entries of each test user into the system. For example; if we get 10K users into the system in 1 minute and let the finished user enter the system over and over again (10 times in total), we have provided 100k users.
You can access: Right-click on the “Thread Group” > Add > Threads > Thread Group
Think Time: It takes some time for real users to use it with a mouse or keyboard between two test steps. This time can be simulated with Think Time, which is determined between steps for virtual users in load and performance tests.
You can access: Right-click on the “Thread Group” > Add Think Times to children
Sampler: JMeter components are needed to interact with the system to be tested.
Below you can see the most used sampler types.
HTTP Request: This sampler lets you send an HTTP/HTTPS request to a web server. Consider the example below. JMeter sends an HTTP request to the Google website and retrieves HTML files or images from this website.
Access Log Sampler: This sampler allows you to read access logs and generate HTTP requests. The log could be image, Html, CSS…
FTP Request: Let’s imagine you want to performance test an FTP server. You can use an FTP request sampler in JMeter to do this task. This controller lets you send an FTP “download file” or “upload file” request to an FTP server.
JDBC Request: This sampler lets you execute Database Performance Testing. It sends a JDBC Request (an SQL query) to a database.
Mail Reader Sampler: The Mail Reader Sampler can read (and optionally delete) mail messages using POP3(S) or IMAP(S) protocols.
SMTP Sampler: If you want to test a mail server, you can use the SMTP sampler. This sampler is used to send email messages using the SMTP protocol.
Listeners: As a tester, I would say the element I love the most:)
Shows the results of the test execution. They can show results in different formats, such as a tree, table, graph, or log file.
You can see the most used Listener types below. The type of Listener you will use depends on what you are testing and the purpose of the test.
View Result Tree
View Results in Table
Summary Report
Backend Listener
Aggregate Report
Thanks to the Listeners, we can see the connection time to the server “Connect Time”, the loading time of the page “Load Time”, the size of the HTTP response “Size in bytes”.
Configuration Elements: Configuration elements can be used to set up defaults and variables for later use by samplers.
CSV Data Set Config:
Suppose you want to test a website for 100 users signing-in with different credentials. You do not need to record the script 100 times! You can parameterize the script to enter different login credentials. This login information (e.g. username, password) could be stored in a text file. JMeter has an element that allows you to read different parameters from that text file. It is “CSV Data Set Config”, which is used to read lines from a file, and split them into variables.
Jmeter_example.csv file content:
Username1;password1
Username2;password2
The appearance of the CSV Data Set Config component is shown below.
1. Name of the CSV file (actually relative path relative to the location of the JMX file)
2. Variable names are given to be assigned to the columns in the input file.
3. Which character is the separator between the columns in the CSV file.
The most important point to be aware of is that the JMX file where the JMeter Test Plan is saved and the CSV file must be in the same folder, or the relative path must be given according to the JMX file when configuring the CSV file.
HTTP Cookie Manager
Let’s understand this with an example. You used your browser (Firefox, IE…Etc) to browse www.google.com. You log in with your user and password. Your username and password will be stored on your computer as cookies. Next time, when you visit www.google.com, you don’t need to do log in again because your browser will use your cookies as user data to log in.
HTTP Cookie Manager also has the same feature as a web browser. If you have an HTTP Request and the response contains a cookie, the Cookie Manager automatically stores that cookie and will use it for all future requests to that particular website.
HTTP Request Default
This element lets you set default values that your HTTP Request controllers use.
For example,
You are sending 100 HTTP requests to the server google.com
You would have to manually enter server name = google.com for all these 100 requests
Instead, you could add a single HTTP request defaults with the “Server Name or IP” field = google.com
No need to type 100 times!
Assertions: Assertion helps verify that your server under test returns the expected results. We will see this subject in practice in sample test writing. You can see the assertion types below.
Jmeter Functions: JMeter functions can be referred as special values that can populate fields of any Sampler or other element in a test tree.
Syntax of a function in JMeter:
${__functionName(var1,var2,var3)} ,
Here “__functionName” matches the name of a function and Parentheses surround the parameters sent to the function. If a function parameter contains a comma then be sure to escape this with “\”, otherwise JMeter will treat it as a parameter delimiter.
For Example: ${_time(EEE\,d MMM yyyy)}
List of Functions:
I’ve started functions, but it’s a better choice to talk about them on another blog that’s longer and more detailed.
Note: JMeter Functions and Variables are always case-sensitive.
Let us consider an example of a Log Function to understand the use of functions in JMeter.
Syntax of JMeter Log Function: ${__log(“message”)}
Simply, the sequence can be started to Jmeter configuration:
First, we will create a simple test plan with an HTTP request sampler.
Create JMeter Test Plan
Add Sampler
Add Listener
Save and Execute Test Plan
Verify the Output
…
I will continue with another article on functions. :) Have a nice day…
Source: https://www.tutorialspoint.com/jmeter/jmeter_test_plan_elements.htm
https://www.javatpoint.com/jmeter-tutorial