Load testing with J meter

24
Load Testing With JMeter By Manoj.Shankaramanchi [email protected] 1

Transcript of Load testing with J meter

Page 1: Load testing with J meter

Load Testing With JMeter

By Manoj.Shankaramanchi [email protected]

1

Page 2: Load testing with J meter

What is Performance Testing?Performance testing, a non-functional testing technique performed to determine the system parameters in terms of responsiveness and stability under various workload. Performance testing measures the quality attributes of the system, such as scalability, reliability and resource usage.

Performance Testing Techniques:

Load testing - It is the simplest form of testing conducted to understand the behaviour of the system under a specific load. Load testing will result in measuring important business critical transactions and load on the database, application server, etc., are also monitored.

Stress testing - It is performed to find the upper limit capacity of the system and also to determine how the system performs if the current load goes well above the expected maximum.

2

Page 3: Load testing with J meter

What is Jmeter?Apache JMeter is a 100% 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.

Additionally, JMeter can help you regression test your application by letting you create test scripts with assertions to validate that your application is returning the results you expect. For maximum flexibility, JMeter lets you create these assertions using regular expressions.

Can run on just about any workstation or environment that can run java.

JMeter is not a browser, it works at protocol level.

3

Page 4: Load testing with J meter

Running JmeterAfter downloading the Jmeter, go to the bin directory. In this case, it is C:\Jmeter\apache-jmeter-2.13\bin. Now click on the following based on the operating system.

4

OS Output

Windows jmeter.bat

Linux jmeter.sh

Mac jmeter.sh

Page 5: Load testing with J meter

How Jmeter Works?JMeter simulates a group of users sending requests to a target server, and returns statistics that show the performance/functionality of the target server/application via tables, graphs, etc.

Start Create requests to target servers and simulates a number of users End

Jmeter gathers data to calculate statistical info Server Responds Reports

Jmeter Saves all responses 5

Page 6: Load testing with J meter

Jmeter ElementsTest Plan Elements:

1. Threads(Users)2. Test Fragment3. Config Element4. Timer5. Pre Processors6. Post Processors7. Assertions8. Listeners

WorkBench Elements:

1. Non-Test Elements2. Logic Controllers3. Config Elements4. Timer5. Pre Processors6. Sampler7. Post Processors8. Assertions9. Listeners

6

Page 7: Load testing with J meter

What is a Test Plan?Test Plan is where you add elements required for your JMeter Test. A test plan describes a series of steps JMeter will execute when run. A complete test plan will consist of one or more Thread Groups, logic controllers, sample generating controllers, listeners, timers, assertions, and configuration elements.

7

Page 8: Load testing with J meter

Building a Test PlanAdding and Removing Elements

Adding elements to a test plan can be done by right-clicking on an element in the tree, and choosing a new element from the "add" list. Alternatively, elements can be loaded from file and added by choosing the "merge" or "open" option.

To remove an element, make sure the element is selected, right-click on the element, and choose the "remove" option.

Loading and Saving Elements

To load an element from file, right click on the existing tree elements to which you want to add the loaded element, and select the "merge" option. Choose the file where your elements are saved. JMeter will merge the elements into the tree. 8

Page 9: Load testing with J meter

Building a Test Plan Continued...Saving the Test Plan

Test Plan consists of one or many elements. To save the Test Plan, select "Save" or "Save Test Plan As ..." from the File menu or right click on an element and choose the "Save Selection As ..." option. JMeter will save the element selected, plus all child elements beneath it. In this way, you can save test tree fragments and individual elements for later use.

● When you save your Test Plan, all those elements in the plan are saved.

Saving an Element

Element is a basic component of JMeter.

When you save your elements, only one element is saved.

Running a Test Plan

To run your test plan, choose "Start" (Control + r) from the "Run" menu item. When JMeter is running, it shows a small green box at the right hand end of the section just under the menu bar. You can also check the "Run" menu. If "Start" is disabled, and "Stop" is enabled, then JMeter is running your test plan (or, at least, it thinks it is).

The numbers to the left of the green box are the number of active threads / total number of threads. These only apply to a locally run test; they do not include any threads started on remote systems when using client-server mode.

9

Page 10: Load testing with J meter

Building a Test Plan Continued...Stopping a Test

There are two types of stop command available from the menu:

Stop (Control + '.')/Shutdown (Control + ',')

Shutdown - stops the threads immediately if possible.StopTestNow - requests the threads to stop at the end of any current work.

10

Page 11: Load testing with J meter

Building a Test Plan Continued...Error Reporting

JMeter reports warnings and errors to the jmeter.log file, as well as some information on the test run itself.

JMeter shows at the right hand end of its window, the number of warnings/errors found in jmeter.log file next to the warning icon. Click on the warning icon to show the jmeter.log file at the bottom of JMeter's window.

Just occasionally there may be some errors that JMeter is unable to trap and log; these will appear on the command console. If a test is not behaving as you expect, please check the log file in case any errors have been reported.

11

Page 12: Load testing with J meter

Thread GroupThread 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 threadsSet the ramp-up periodSet the number of times to execute the test(Loop Count)

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 number of threads tells Jmeter how many users need to be connected to the server at a certain time.

The ramp-up period tells JMeter how long to take to "ramp-up" to the full number of threads chosen.

Loop count tells Jmeter how many number of times to perform the test case for each thread.

Action to be taken after a Sampler error contains following options

ContinueStart Next Thread LoopStop ThreadStop Test Stop Test Now

Delay Thread creation until needed

Scheduler: If we check the option it asks us to enter the particular time to start a test.

12

Page 13: Load testing with J meter

Config ElementsA configuration element works closely with a Sampler. Although it does not send requests (except for HTTP(S) Test Script Recorder ), it can add to or modify requests.

A configuration element is accessible from only inside the tree branch where you place the element. For example, if you place An HTTP Cookie Manager inside a Simple Logic Controller, the Cookie Manager will only be accessible to HTTP Request Controllers you place inside the Simple Logic Controller . The Cookie Manager is accessible to the HTTP requests "Web Page 1" and "Web Page 2", but not "Web Page 3".

Config Elements:

1. Counter2. CSV Data Set Config3. DNS Cache Manager4. FTP Request Defaults5. HTTP Authorization Manager6. HTTP Cache Manager7. HTTP Cookie Manager8. HTTP Header Manager9. HTTP Request Defaults10. Java Request Defaults11. JDBC Connection Configuration12. Keystore Configuration13. LDAP Extended Request Defaults14. LDAP Request Defaults15. Login Config Element16. MongoDB Source Config17. Random Variable18. Simple Config Element19. TCP Sampler Config20. User Defined Variables

13

Page 14: Load testing with J meter

ControllersJmeter has two types of controllers: Sampler and Logical Controllers.

Sampler: 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.

Logic Controllers: Logic Controllers let you customize the logic that JMeter uses to decide when to send requests. Logic Controllers can change the order of requests coming from their child elements. They can modify the requests themselves, cause JMeter to repeat requests, etc.

Logic Controller Elements:

1. Critical Section Controller

2. ForEach Controller3. If Controller4. Include Controller5. Interleave Controller6. Loop Controller7. Module Controller8. Once Only Controller9. Random Controller10. Random Order

Controller11. Recording Controller12. Runtime Controller13. Simple Controller14. Switch Controller15. Throughput Controller16. Transaction Controller17. While Controller

14

Sampler Elements:

1. Access Log Sampler2. AJP/1.3 Sampler3. BeanShell Sampler4. BSF Sampler5. Debug Sampler6. FTP Request7. HTTP Request8. Java Request9. JDBC Request10. JMS Point-to-Point11. JMS Publisher12. JMS Subscriber13. JSR223 Sampler14. JUnit Request15. LDAP Extended

Request16. LDAP Request17. Mail Reader Sampler18. MongoDB Script19. OS Process Sampler20. SMTP Sampler21. SOAP/XML-RPC Request22. TCP Sampler23. Test Action

Page 15: Load testing with J meter

TimerBy 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.

Timer Elements:

1. BeanShell Timer2. BSF Timer3. Constant Throughput

Timer4. Constant Timer5. Gaussian Random Timer6. JSR223 Timer7. Poisson Random Timer8. Synchronizing Timer9. Uniform Random Timer

15

Page 16: Load testing with J meter

Pre ProcessorsA Pre-Processor executes some action prior to a Sampler Request being made. If a Pre-Processor is attached to a Sampler element, then it will execute just prior to that sampler element running. A Pre-Processor is most often used to modify the settings of a Sample Request just before it runs, or to update variables that aren't extracted from response text.

Pre Processors Elements:

1. BeanShell PreProcessor2. BSF PreProcessor3. HTML Link Parser4. HTTP URL Re-writing Modifier5. JDBC PreProcessor6. JSR223 PreProcessor7. RegEx User Parameters8. User Parameters

16

Page 17: Load testing with J meter

Post ProcessorsA Post-Processor executes some action after a Sampler Request has been made. If a Post-Processor is attached to a Sampler element, then it will execute just after that sampler element runs. A Post-Processor is most often used to process the response data, often to extract values from it.

Post Processor Elements:

1. BeanShell PostProcessor2. BSF PostProcessor3. CSS/JQuery Extractor4. Debug PostProcessor5. JDBC PostProcessor6. JSR223 PostProcessor7. Regular Expression Extractor8. Result Status Action Handler9. XPath Extractor

17

Page 18: Load testing with J meter

AssertionsAssertions 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.

Note that assertions apply to all samplers which are in its scope . To restrict the assertion to a single sampler, add the assertion as a child of the sampler.

To view the assertion results, add an Assertion Listener to the Thread Group. Failed Assertions will also show up in the Tree View and Table Listeners, and will count towards the error %age for example in the Aggregate and Summary reports.

18

Assertion Elements:

1. BeanShell Assertion2. BSF Assertion3. Compare Assertion4. Duration Assertion5. HTML Assertion6. JSR223 Assertion7. MD5Hex Assertion8. Response Assertion9. Size Assertion10. SMIME Assertion11. XML Assertion12. XML Schema

Assertion13. XPath Assertion

Page 19: Load testing with J meter

ListenersListeners 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.

Additionally, listeners can direct the data to a file for later use. Every listener in JMeter provides a field to indicate the file to store data to. There is also a Configuration button which can be used to choose which fields to save, and whether to use CSV or XML format. Note that all Listeners save the same data; the only difference is in the way the data is presented on the screen.

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.

There are several listeners that come with JMeter.

Listener Elements:

1. Aggregate Graph2. Aggregate Report3. Assertion Results4. Backend Listener5. BeanShell Listener6. BSF Listener7. Comparison Assertion Visualizer8. Distribution Graph (alpha)9. Generate Summary Results10. Graph Results11. JSR223 Listener12. Mailer Visualizer13. Monitor Results14. Response Time Graph15. Save Responses to a file16. Simple Data Writer17. Spline Visualizer18. Summary Report19. View Results in Table20. View Results Tree

19

Page 20: Load testing with J meter

What is Workbench?The WorkBench simply provides a place to store test elements temporarily. WorkBench has no relation with Test Plan. JMeter will not save the contents of the WorkBench. It only saves the contents of the Test Plan branch.

That’s why, if the designed test in the WorkBench is ready to proceed, copy that and move it into Test Plan. Jmeter only save the contents of Test Plan not WorkBench.

WorkBench keeps non-test Elements too: Http Mirror Server and Http Mirror Server, these elements are not available in the Thread Group and Test Plan.

20

Page 21: Load testing with J meter

Errors and Response Code1xx: Information:

100 Continue The server has received the request headers, and the client should proceed to send the request body101 Switching Protocols The requester has asked the server to switch protocols103 Checkpoint Used in the resumable requests proposal to resume aborted PUT or POST requests

2xx: Successful:

200 OK The request is OK (this is the standard response for successful HTTP requests)201 Created The request has been fulfilled, and a new resource is created202 Accepted The request has been accepted for processing, but the processing has not been completed203 Non-Authoritative Information The request has been successfully processed, but is returning information that may be from another source204 No Content The request has been successfully processed, but is not returning any content205 Reset Content The request has been successfully processed, but is not returning any content, and requires that the requester reset the document view206 Partial Content The server is delivering only part of the resource due to a range header sent by the client

21

Page 22: Load testing with J meter

Errors and Response Code Continued...3xx: Redirection:

300 Multiple Choices A link list. The user can select a link and go to that location. Maximum five addresses301 Moved Permanently The requested page has moved to a new URL302 Found The requested page has moved temporarily to a new URL303 See Other The requested page can be found under a different URL304 Not Modified Indicates the requested page has not been modified since last requested306 Switch Proxy No longer used307 Temporary Redirect The requested page has moved temporarily to a new URL308 Resume Incomplete Used in the resumable requests proposal to resume aborted PUT or POST requests

4xx: Client Error:

400 Bad Request The request cannot be fulfilled due to bad syntax401 Unauthorized The request was a legal request, but the server is refusing to respond to it. For use when authentication is possible but has failed or not yet been provided402 Payment Required Reserved for future use403 Forbidden The request was a legal request, but the server is refusing to respond to it404 Not Found The requested page could not be found but may be available again in the future405 Method Not Allowed A request was made of a page using a request method not supported by that page406 Not Acceptable The server can only generate a response that is not accepted by the client407 Proxy Authentication Required The client must first authenticate itself with the proxy

22

Page 23: Load testing with J meter

Errors and Response Code Continued...408 Request Timeout The server timed out waiting for the request409 Conflict The request could not be completed because of a conflict in the request410 Gone The requested page is no longer available411 Length Required The “Content-Length” is not defined. The server will not accept the request without it412 Precondition Failed The precondition given in the request evaluated to false by the server413 Request Entity Too Large The server will not accept the request, because the request entity is too large414 Request-URI Too Long The server will not accept the request, because the URL is too long. Occurs when you convert a POST request to a GET request with a long query information415 Unsupported Media Type The server will not accept the request, because the media type is not supported416 Requested Range Not Satisfiable The client has asked for a portion of the file, but the server cannot supply that portion417 Expectation Failed The server cannot meet the requirements of the Expect request-header field

5xx: Server Error:

500 Internal Server Error A generic error message, given when no more specific message is suitable501 Not Implemented The server either does not recognize the request method, or it lacks the ability to fulfill the request502 Bad Gateway The server was acting as a gateway or proxy and received an invalid response from the upstream server503 Service Unavailable The server is currently unavailable (overloaded or down)504 Gateway Timeout The server was acting as a gateway or proxy and did not receive a timely response from the upstream server505 HTTP Version Not Supported The server does not support the HTTP protocol version used in the request511 Network Authentication Required The client needs to authenticate to gain network access

23

Page 24: Load testing with J meter

Thank You

24