How to use Jmeter for performance testing

chiragppatel0111 43 views 71 slides Jul 24, 2024
Slide 1
Slide 1 of 71
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71

About This Presentation

Jmeter for performance testing


Slide Content

What is Performance Testing To Check the Application behaviour to various load condition is called Performance testing . Why do Performance Testing ? Nobody likes using a slow application. Performance testing is necessary to make sure your application runs quickly, is stable, and can scale.

Attributes of Performance Testing 1.Speed - Determines whether the application responds quickly 2.Scalability - Determines maximum user load the software application can handle. 3.Stability - Determines if the application is stable under varying loads

Performance Testing Process

Types of Testing People will be able to make search on travel website portals with Origin , Destination , Departure , Arrival date and N o.of passengers So we are giving the request to the website, Travel API providers are integrated on website then fetching data from travel API Providers data base and display it to the website. And the portal will be integrated with the payment gateway for the customers to pay through Credit cards, D ebit cards and Net banking. Finally through travel portal development the customers wiil be able to make search on website , book a hotel or flight and pay online which reduce the extra work of travel agents.

Advantages of JMeter Booking.com API Booking.com is leading travel agency with more than 200 thousands of hotels in different categories in different countries . Expedia API Expedia is a large database of Hotels say 4,35,000 in 1500 destinations. It is one of the most used API for hotel reservation system. Amadeus API Amadeus API is the best Global distribution system for flight booking site . It has 75,000 travel agencies and 11,000 airlines to run their services.

JMeter Workflow API stands for Application Programming Interface. API is a software to software interface, not a user interface. With APIs, applications talk to each other without any user knowledge or intervention. Implemented by writing function calls in the program.

1. JMeter Introduction Definition of JMeter History of JMeter JMeter Features 2. Steps to Install JMeter Installation of Java Download JMeter Installation of JMeter

3.Building a Test Plan Adding and Removing Elements Loading and Saving Elements Run the Test Plan Stop the Test Plan Clear Results in Test Plan Building a Workbench

4. Elements of a Test Plan Thread Group Configuration Elements Timers Pre-Processor Post-Processer Assertions Listeners Controllers Samplers

5. Application under Test Generate script using Test Script Reorder Settings to be done for Test Script Recorder View the Test Results and Analyze the Test Report

1. JMETER Introduction Apache JMeter is a pure Java application designed to load test client/server software (such as a web application). It may be used to test performance both on static and dynamic resources such as static files, Java Servlets, ASP.NET, PHP, CGI scripts, Java objects, databases, FTP servers, and more . JMeter can be used to simulate a heavy load on a server, network or object to test its strength or to analyze overall performance under different load types.

1.2 History of JMeter Stefano Mazzocchi of the Apache Software Foundation was the original developer of JMeter. He wrote it primarily to test the performance of Apache JServ (now called as Apache Tomcat project). Apache later redesigned JMeter to enhance the GUI and to add functional testing capabilities.

JMeter Features Being an open source software, it is freely available. It has a simple and intuitive GUI. JMeter can conduct load and performance test for many different server types − Web - HTTP, HTTPS, SOAP, Database via JDBC, LDAP, JMS, Mail - POP3, etc. It is a platform-independent tool. On Linux/Unix, JMeter can be invoked by clicking on JMeter shell script. On Windows, it can be invoked by starting the JMeter.bat file. JMeter store its test plans in XML format. This means you can generate a test plan using a text editor. Its full multi-threading framework allows concurrent sampling by many threads and simultaneous sampling of different functions by separate thread groups. It is highly extensible. It can also be used to perform automated and functional testing of the applications.

2. Steps to Install JMeter JMeter is pure Java desktop application, it requires a fully compliant JVM 6 or higher. You can download and install the latest version of Java SE Development Kit. The following procedure to check whether Java JDK is installed successfully in your system Navigation : Go to Start-->Enter cmd in search --->Double click on cmd icon--->Enter command java -version in cmd.

Basic Inputs

If Java runtime environment is installed successfully, you will see the output as figure below If nothing displays, please re-install Java SE runtime environment by below process

2.1 Installation of Java Check out Windows Versions: The JDK software has two different versions: a 32-bit version and a 64-bit Window Version On Windows 7 you can open the Start menu and choose “Computer” from the list. On the “Computer” screen, click on the button that says “System Properties”, as seen below:

Downloading the JDK To download Downloading the JDK To download the Java Development Kit (JDK), launch your web browser (e.g. Internet Explorer) and go to this address: http://www.oracle.com/technetwork/java/javase/downloads/index.html

Downloading the JDK To download

Downloading the JDK To download

Downloading the JDK To download Once you have accepted the license agreement, you will need to choose a file to download. The Windows files are at the bottom of the screen. If you have a 32-bit Windows system, you will choose the “Windows x86” file. If you have a 64-bit Windows system, you will need to choose the “Windows x64” file . 2.2 Download JMeter Open the URL: http://JMeter.apache.org/download_JMeter.cgi Choose the Binaries file (either zip or tgz ) to download as shown in figure below

I nvoking Jmeter

2.3 Installation of JMeter Installation of JMeter is extremely easy and simple. You simply unzip the zip/tar file into the directory where you want JMeter to be installed. There is no tedious installation screen to deal with! Simple unzip and you are done! Once the unzipping is done installation directory structure should look like as figure below

Batch File

JMeter Test Plan

JMeter Test Plan

1.Test Plan 2.Work Bench

Elements of a Test Plan The elements of the test plan will be added under this item in the left portion of the window Threads - Each thread simulates a single user hitting the web server. Note that the actual plan is built under a Thread Group Thread Groups are under the Threads menu item Test Fragment - A special type of controller. You can build a test fragment from other elements under this element It can be included in the test plan in multiple places An Include Controller is used to include it

Elements of a Test Plan Config Element - Various configuration elements are here For example the HTTP Request Default element which defines the default host and port etc. when placed at the same level as the Thread Group they become global configurations. Timer - various types of timers that can be used to time the test plan Generally JMeter send requests with no pauses between requests This does not correspond to the way systems are used by users

Elements of a Test Plan Pre Processors - Executes an action prior to a request (Samplers are discussed below) For example setting parameters for a request There are scoping rules that apply to Pre Processors Post-Processors - Executes an action after a request usually it processes the response data There are scoping rules that apply to Post-Processors Assertions - Used to test the responses Was the response correct If not fail the response Generally added as the child of a Sampler (Discussed below) Listeners - provide access to the information JMeter gathers during the test

Thread Group Thread Groups is a collection of Threads. Each thread represents one user using the application under test. Basically each Thread simulates one real user request to the server. The controls for a thread group allow you to Set the number of threads for each group. Navigation Open JMeter---->Right click on Test Plan----> click on Add--> click on Threads---> click on Thread Group

Thread Group

Thread Group

Thread Group Thread group elements are the beginning points of any test plan. All controllers and samplers must be under a thread group. Other elements, e.g. Listeners, may be placed directly under the test plan, in which case they will apply to all the thread groups. As the name implies, the thread group element controls the number of threads JMeter will use to execute your test. The controls for a thread group allow you to: Set the number of threads Set the ramp-up period Set the number of times to execute the test Each thread will execute the test plan in its entirety and completely independently of other test threads. Multiple threads are used to simulate concurrent connections to your server application. The ramp-up period tells JMeter how long to take to "ramp-up" to the full number of threads chosen. If 10 threads are used, and the ramp-up period is 100 seconds, then JMeter will take 100 seconds to get all 10 threads up and running. Each thread will start 10 (100/10) seconds after the previous thread was begun. If there are 30 threads and a ramp-up period of 120 seconds, then each successive thread will be delayed by 4 seconds.

Thread Group Ramp-up needs to be long enough to avoid too large a work-load at the start of a test, and short enough that the last threads start running before the first ones finish (unless one wants that to happen). Start with Ramp-up = number of threads and adjust up or down as needed. By default, the thread group is configured to loop once through its elements. Version 1.9 introduces a test run scheduler. Click the checkbox at the bottom of the Thread Group panel to reveal extra fields in which you can enter the start and end times of the run. When the test is started, JMeter will wait if necessary until the start-time has been reached. At the end of each cycle, JMeter checks if the end-time has been reached, and if so, the run is stopped, otherwise the test is allowed to continue until the iteration limit is reached. Alternatively, one can use the relative delay and duration fields. Note that delay overrides start-time, and duration over-rides end-time.

4.2 Configuration Elements Configuration Elements allow you to create defaults and variables to be used by Samplers. They are used to add or modify requests made by Samplers. They are executed at the start of the scope of which they are part, before any Samplers that are located in the same scope. Therefore, a Configuration Element is accessed only from inside the branch where it is placed. Navigation Right click on Test Plan----> click on Add--->Click on HTTP Cache Manager

Configuration Elements

4.3 Timers By default, a JMeter thread sends requests without pausing between each request. We recommend that you specify a delay by adding one of the available timers to your Thread Group. If you do not add a delay, JMeter could overwhelm your server by making too many requests in a very short amount of time. The timer will cause JMeter to delay a certain amount of time before each sampler which is in its Scope If you choose to add more than one timer to a Thread Group, JMeter takes the sum of the timers and pauses for that amount of time before executing the samplers to which the timers apply. Timers can be added as children of samplers or controllers in order to restrict the samplers to which they are applied. Navigation Right click on Test Plan----> click on Add-->click on Timer-->click on constant Timer.

Timers

Pre-processor A pre-processor element is something that runs just before a sampler executes. They are often used to modify the settings of a Sample Request just before it runs, or to update variables that are not extracted from response text. Navigation Right Click on Test Plan  click on Add  Preprocessors

Pre-processor

Post-processor A post-processor executes after a sampler finishes its execution. This element is most often used to process the response data, for example, to retrieve a particular value for later use. Navigation Right Click on Test Plan  click on Add  Post processors

Post-processor

Assertions Assertions allow you to assert facts about responses received from the server being tested. Using an assertion, you can essentially "test" that your application is returning the results you expect it to. For instance, you can assert that the response to a query will contain some particular text. The text you specify can be a Perl-style regular expression, and you can indicate that the response is to contain the text, or that it should match the whole response. You can add an assertion to any Sampler. For example, you can add an assertion to a HTTP Request that checks for the text, "</HTML>". JMeter will then check that the text is present in the HTTP response. If JMeter cannot find the text, then it will mark this as a failed request. Navigation Right Click on Test Plan  click on Add  Assertions-->click on Response Assertion

Response Assertions

Listeners Listeners provide access to the information JMeter gathers about the test cases while JMeter runs. The Graph Results listener plots the response times on a graph. The "View Results Tree" Listener shows details of sampler requests and responses, and can display basic HTML and XML representations of the response. Other listeners provide summary or aggregation information. Listeners can be added anywhere in the test, including directly under the test plan. They will collect data only from elements at or below their level.

Listeners

Controllers JMeter has two types of Controllers: Samplers and Logical Controllers. These drive the processing of a test. Samplers tell JMeter to send requests to a server. For example, add an HTTP Request Sampler if you want JMeter to send an HTTP request. You can also customize a request by adding one or more Configuration Elements to a Sampler.

Controllers

Samplers Samplers tell JMeter to send requests to a server and wait for a response. They are processed in the order they appear in the tree. Controllers can be used to modify the number of repetitions of a sampler. JMeter samplers include: Ftp Request Http Request Jdbc Request Java Object Request Ldap Request Soap/Xml- Rpc Request Webservice (Soap) Request

Samplers

Application under Test

Generate script using Test Script Reorder

Settings to be done for Test Script Recorder

Settings to be done for Test Script Recorder

Settings to be done for Test Script Recorder

Follow these steps to change your proxy setting (for Windows) Click the Chrome menu on the browser toolbar. Select Settings. Click Show advanced settings. In the "Network" section, click Change proxy settings. ... Click LAN settings. Deselect the "Automatically detect settings" checkbox. Click on customize and control Google chrome button--- >click on Setting--- > Enter Proxy in Search Text box--->click on change Proxy button---> Click on LAN setting Button --- > Deselect the "Automatically detect settings" checkbox ---->Enable Use Proxy server check box(Proxy server)---- >Enter Address as local host ---- >Enter port as 1234 --- > click on ok button

Script Generated After Recording

Script Generated After Recording

View Results Tree

How to Test Mobile App Performance using Apache JMeter? JMeter records mobile application requests on HTTP(S) Script Recorder and it has features to prepare and run our mobile application performance test scripts. All we have to do is to configure JMeter and Mobile device. In JMeter, we can test both iOS and Android native applications . Steps to install the certificate: Go to  jmeter /bin directory and find the ApacheJmeterTemporaryRootCA.crt file. (If you cannot find the certificate from bin directory, just go to your HTTP(S) script recorder screen in Jmeter and click ‘Start’ button. It will generate new certificate on your bin directory automatically). 2. Attach that file and send an email to yourself. 3.Download from your mail and then install on your device.

How to Test Mobile App Performance using Apache JMeter ? Go to Settings > Wi-Fi option. ( Note:  Network should be same for both Mobile and Laptop/Desktop). Click on the Connected network. Select “Manual” option from HTTP Proxy. Set ‘Server value as system IP address and Port value to 8080 as per JMeter setup. Now start the application on the device and its each request will be recorded in JMeter.

How to Test Mobile App Performance using Apache JMeter ?

How to Test Mobile App Performance using Apache JMeter ?

How to Test Mobile App Performance using Apache JMeter ? 6 .  Click on ‘Save’. 7 .  Now start the application on the device and its each request will be recorded in JMeter. 8 .  Before running the application, make sure that HTTP(S) script recorder was started in JMeter. 9 .  Once the application is started, the actions of the script will be recorded under “Recording Controller.” 10 .  Once actions are done in the application, stop the script recording by clicking ‘Stop’ button in HTTP(S) script recorder screen. 11 .  Now, expand the “Recording Controller” in JMeter. You can view all the Recorded scripts of whatever actions are done in the applications. 12 .  Finally, click the ‘Play’ button. It will run recorded scripts as per your Threads setup. 13 .  Click on “View Results in Tree”. Here you will see the result of your script.

Apache JMeter Distributed Testing Step-by-step On the slave systems, go to  jmeter /bin  directory and execute  jmeter-server.bat  ( jmeter-server on unix ). On master system acting as the console, open windows explorer and go to  jmeter /bin  directory Open  jmeter.properties  in a text editor Edit the line  remote_hosts =127.0.0.1 Add the IP address. For example, if I have JMeter server running on  192.168.0.10 , …,  192.168.0.15 , the entry would like like this: remote_hosts =192.168.0.10,192.168.0.11,192.168.0.12,192.168.0.13,192.168.0.14

Distributed Testing Step-by-step

Distributed Testing

How Do I Run JMeter in Non-GUI Mode? Step 1. Prepare the JMeter test Open your *. jmx file Remove all graphic data writers They will not work in the non- gui mode and there no need to keep them in testing scenario Step jmeter -n -t C:\Users\katamaiahj\Desktop\apache-jmeter-2.13\bin\examples\demoflipkart29_03_2018.jmx -l C:\Users\katamaiahj\Desktop\apache-jmeter-2.13\bin\examples\CSVSample_user.csv

Step 2. Run the JMeter test Go to bin folder of your JMeter installation from command prompt Type the following command : JMeter -n -t D:\TestScripts\script.jmx -l D:\ TestScripts\scriptresults.jtl   -n [This specifies JMeter is to run in non- gui mode ] -t  [name of JMX file that contains the Test Plan ] -l  [name of JTL file to log sample results to ] -j  [name of JMeter run log file].

References http://jmeter.apache.org/ http://www.oracle.com/technetwork/java/javase/downloads/index.html http://JMeter.apache.org/download_JMeter.cgi http://www.tutorialspoint.com/jmeter/jmeter_tutorial.pdf http://www.johnandcailin.com/files/ApacheJMeterChapter6.pdf
Tags