# Performance testing using Apache JMeter ###### tags: `testing, performance, load` ## What is Performance Testing? - It is a type of non-functional testing that is perfomed: - To know the how fast some aspect of a system perfoms under particular workload. - To determine that the system under test will satisfy high load requirements. - To demonstrate that system meets performance criteria. ## :memo: Why is it important? The performance testing is useful to: - Improve user experience on system. - Gather metrics useful for tuning the system. - Identify bottlenecks such as database configuration. - Determine if a new release is ready for production. - Provide reporting to business stakeholders regarding performance against expectations. ## What kinds of Performance Testing are there? Performance Testing includes: 1. Load testing It's a testing that consists in simulating multiple user access concurrently to the system for modeling the expect usage. 2. Stress testing. It's a test that determines the maximum load that the web server can handle. Given that each server has a maximum load capacity and when the load goes beyond the limit, the web server starts responding slowly and produce errors. ## How do we start? We are going to use JMeter to do the performance testing. Firstly, we are going to work with load testing. #### Why JMeter? - **Cross-platform:** JMeter can run on any operating system with Java - **Scalable:** When you need a higher load than a single machine can create, JMeter can execute in a distributed mode, meaning one master JMeter machine controls a number of remote hosts. - **Multi-protocol support:** The following protocols are all supported out-of-the-box: HTTP, SMTP, POP3, LDAP, JDBC, FTP, JMS, SOAP, TCP - Various assertions to define criteria - Full featured Test IDE that allows fast Test Plan recording - Comprehensive informative load reports. - Integration with major build and continuous integration systems. :::info :pushpin: Want to see other open source tools? ➜ [Performance Testing Tools](https://www.blazemeter.com/blog/open-source-load-testing-tools-which-one-should-you-use) ::: ### Load Testing :bulb: The main idea is that JMeter make copy of samplers and running them in separated thread. :star: Before testing the system, it's important determinate: * **Normal load:** The average number of users that visit the system. * **Heavy load:** The maximum number of user that visit the system. * **Target:** The IP address of the server. ### **Step 1:** Add Thred Group - [x] Start JMeter > For run GUI, open the jmeter folder, open bin and run the bin file jmeter. - [x] Right click Test Plan > Add -> Thread (Users) -> Thread Group - [x] Enter following properties in the Thread Group panel: - [x] **Number of Threads:** 100 Number of users connects to the application. - [x] **Loop Count:** 10 Number of times ONE user connects to the application - [x] **Ramp-Up Period:** 100 Acceleration time that determines how long the user test delay before starting the next user. - [ ] ==Delay between the initial users== Ram-Up Period / Number of Threads ### **Step 2:** Add JMeter elements. - [x] Add an **HTTP request defaults** - [x] Right click Test Plan > Add -> Config Element -> HTTP Request Defaults. - [x] Enter the server name or IP - [x] Add **HTTP Request** - [x] Right click Thread Group > Add -> Sampler -> HTTP Request. - [x] Edit request name. - [x] Edit the path field It indicates which **URL request** you want to send to application. - [x] Add body data To create an HTTP request with a dynamic email parameter which is generated by pre-processor. - [x] Add a **JSON extractor post-processor** To get authentication token from the response of login user request. - [x] Right click HTTP Request > Add -> Post Processors -> JSON Extractor. - [x] Edit **Name of created variables** with ==authToken==. - [x] Edit JSON Path Expressions with value returned. For example, ==$.token== - [x] Add an **HTTP header manager** To add authentication token as the header to all subsequent requests. - [x] Right click Thread Group > Add -> Config Element -> HTTP Head Manager. - [x] Add authentication header - [x] Edit **name** with Authentication. - [x] Edit **value** with variable stored in JSON Extractor, ==${authToken}== ### **Step 3:** Add Graph result. - [x] Right click Thread Group > Add -> Listener -> Graph Results - [x] Right click Thread Group > Add -> Listener -> Summary Report. ### **Step 4:** Run Test and get the test result. - [x] Press the Run button (Ctrl + R) > The Run button is on the Toolbar to start the software testing process. - [x] See the test result display on Graph in the real time. --- ## References | Topic | Tutorials | | ----------------- |:----------------------- | | Load Testing Using Apache JMeter | [:link:][Load-Testing-JMeter-0] | | Rest API Load testing with Apache JMeter | [:link:][Load-Testing-JMeter-1] | | What is Performance testing in software? | [:link:][Definition-0] | | How to Use JMeter for Performance & Load Testing | [:link:][Load-Testing-JMeter-2] | [Load-Testing-JMeter-0]: https://itnext.io/load-testing-using-apache-jmeter-af189dd6f805 [Load-Testing-JMeter-1]: https://medium.com/@chamikakasun/rest-api-load-testing-with-apache-jmeter-a4d25ea2b7b6 [Definition-0]: http://tryqa.com/what-is-performance-testing-in-software/ [Load-Testing-JMeter-2]: https://www.guru99.com/jmeter-performance-testing.html