Developers learn Linux (4): Stress testing websites and databases using JMeter

Source: Internet
Author: User
Tags mysql version prepare tomcat server

Preface
On the face of it, JMeter seems to have little to do with this series of courses, but it actually plays an important role in many of the later scenarios: how do you know if you've modified some code or settings to improve or decrease the performance of your system? The Commercial Stress test tool LoadRunner is really big, but it is said that the cost is not cheap and the volume is not small, The current maximum version of the open source free stress test Tool JMeter3.2 compressed package volume is less than 53M, and for developers rather than professional testers, JMeter provides the testing capabilities are strong enough. To fully introduce the jmeter, even if the jmeter comes with a document translated into Chinese is a thick book. But in this article just how to use JMeter to stress test Web sites and databases because of the complexity of the test scenario, this example describes a parameterized test based on a CSV file.
JMeter provides test support for different protocols, servers, and applications, as follows:
Web – A variety of development language developed sites, such as Asp/asp.net/jsp/php/python/perl, etc.
Soap/rest webservices
Ftp
Database via JDBC (JDBC-based stress testing of databases)
Ldap
message-oriented Middleware (MOM) via JMS
MAIL-SMTP (s), POP3 (s) and IMAP (s)
Native commands or shell scripts
Tcp
Java Objects
Still the same sentence: This article only describes the Web site and JDBC-based database stress testing.

Software Preparation
JMeter3.2: To maintain a better comparison with this article, we recommend to download version 3.2 from the official website: http://jmeter.apache.org/[preferred]/jmeter/binaries/ Apache-jmeter-3.2.zip
This software can be used after decompression.
Tomcat8.5: The stress tests for Web sites in this example are based on Tomcat8.5: http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.15/bin/ Apache-tomcat-8.5.15.tar.gz
If you have trouble, you can do it directly in the context of the previous "developer Linux (3): Installing JDK8 and Tomcat8 in CentOS7."
MySQL Community Server5.7: This article will take MySQL as an example of how to stress test the database, in fact, this article is not required for the MySQL version, but later, it is recommended to download version 5.7,: https://dev.mysql.com/ downloads/mysql/, please download the JDBC driver for MySQL as well.
Note: In this article JMeter runs under Windows, and the MySQL database and Tomcat server are running under CentOS7.
Use JMeter to stress test a general website
To facilitate the demonstration, here is a "developer Linux (3): CentOS7 in the installation of JDK8 and TOMCAT8" in the environment for stress testing, my virtual machine support bridge mode, The IP address is: 192.168.60.198, there is a simple submission form in Tomcat, the URL is: http://192.168.60.198:8080/examples/servlets/servlet/ Requestparamexample, the page looks like this:
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M00/97/B8/wKiom1kxiAiwLvKbAABT6Z6HfD0847.png-wh_500x0-wm_ 3-wmp_4-s_703271064.png "title=" Jmeter_use01.png "alt=" Wkiom1kxiaiwlvkbaabt6z6hfd0847.png-wh_50 "/>
There is a form on the page that looks at the source code of the page to see that the form is submitted to the current servlet, and there are two fields, namely: FirstName and LastName, as shown in:
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/97/B9/wKioL1kxiBrTPu8fAAC3ElPt2K4231.png-wh_500x0-wm_ 3-wmp_4-s_3579188273.png "title=" Jmeter_use02.png "alt=" Wkiol1kxibrtpu8faac3elpt2k4231.png-wh_50 "/>
The following describes the creation of related jmeter elements.
1. Running JMeter
First run the bin directory in the extracted JMeter directory to find Jmeter.bat to run the JMeter (important thing to say again: This article jmeter run under Windows, MySQL database and Tomcat server are running under CENTOS7), JMeter support multiple languages , including Chinese (in fact, the support of Chinese is not exhaustive), and in the Chinese environment jmeter the default language is Chinese, because it is necessary to look at the JMeter directory under the Printable_docs directory of documents, and here the document is all in English, so I set it to English, As shown in the following:
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/97/B9/wKioL1kxiC7w62nBAACs3wzzi6o859.png-wh_500x0-wm_ 3-wmp_4-s_1172699735.png "title=" Jmeter_use03.png "alt=" Wkiol1kxic7w62nbaacs3wzzi6o859.png-wh_50 "/>
This is the interface after it is set to English:
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/97/B8/wKiom1kxiD6BblfRAAC2qA4Yzog047.png-wh_500x0-wm_ 3-wmp_4-s_3445419325.png "title=" Jmeter_use04.png "alt=" Wkiom1kxid6bblfraac2qa4yzog047.png-wh_50 "/>
2. Add the necessary elements to the test plan.
The order of the necessary elements for adding a test plan is: Threadgroup->httprequest->listener. You should actually include the Testplan (test plan), which creates a testplan by default, so the steps to add Testplan are omitted.
2.1 Adding Threadgroup
As shown in the following:

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/97/B8/wKiom1kxiFzhkQqZAACsGAabW84733.png-wh_500x0-wm_ 3-wmp_4-s_2172390779.png "style=" Float:none; "title=" Jmeter_use05_threadgroup.png "alt=" Wkiom1kxifzhkqqzaacsgaabw84733.png-wh_50 "/>


2.2 Add HTTP Request Defaults
right mouse button on the Threadgroup element, "Add"-"Config Element"-"HTTP request Defaults", HTTP request Defaults suitable for a large number of HTTP in a Threadgroup Request situation, in many cases the HTTP request configuration is the same, then only need to be set in the HTTP request defaults, do not need to be set in each HTTP request, add HTTP request The interface of the defaults is as follows:

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/97/B9/wKioL1kxiFzwRH4jAAE01ZDsN1g528.png-wh_500x0-wm_ 3-wmp_4-s_1154804489.png "style=" Float:none; "title=" Jmeter_use06_httprequestdeaults.png "alt=" Wkiol1kxifzwrh4jaae01zdsn1g528.png-wh_50 "/>

2.3 Adding an HTTP Request
With the right mouse button on the Threadgroup element, add the HTTP request via "Add"-"Sampler"-"HTTP request".

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/97/B9/wKioL1kxiF3yMpqFAAE1pmZr O_o 234.png-wh_500x0-wm_ 3-wmp_4-s_806233884.png "style=" Float:none; "title=" Jmeter_use07_httprequest.png "alt=" wKioL1kxiF3yMpqFAAE1pmZrO_ O234.png-wh_50 "/>

2.4 Adding listener
The Threadgroup element on the right mouse button, through the "add"-"Listener" to add Listener, where necessary to add Listener, I will generally add the following Listener:
Summary report: You can have a summary of the results of the test, the results include the number of tests, average/maximum/minimum response time, concurrent throughput, the number of bytes received/sent, and other information;
View result Tree: Because by default the success of a test is judged by whether it received content, such as requesting a page that needs authorization, if not authorized will be directed to the login page, in JMeter it does not appear to occur 40X, 50X such http Code errors will still be treated as a test result, and the data sent and responded to by the client and server can be seen after adding view result tree.
View Results in Table: Similar to summary report, but with a different focus.

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/97/B8/wKiom1kxiKqguQdVAAFOWJbcmUQ361.png-wh_500x0-wm_ 3-wmp_4-s_3671572135.png "style=" Float:none; "title=" Jmeter_use08_listener.png "alt=" Wkiom1kxikqguqdvaafowjbcmuq361.png-wh_50 "/>





2.5 adding CSV Data Set Config
As you can see in the previous form form, you need to FirstName and LastName two values, we can specify a fixed value directly, or you can set a series of matching values from the data in the CSV file.
With the right mouse button on the Threadgroup element, add the CSV Data set config via "add"-"Config element"-"CSV Data set config".

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/97/B9/wKioL1kxiKui2bh5AAFg-fjQqqE838.png-wh_500x0-wm_ 3-wmp_4-s_2139707089.png "style=" Float:none; "title=" Jmeter_use09_csv_data_set_config.png "alt=" Wkiol1kxikui2bh5aafg-fjqqqe838.png-wh_50 "/>

2.6 Parameter Configuration
The final effect of the Testplan created as described in the previous steps is as follows:

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/97/B8/wKiom1kxiKvRekSTAACOBV2p2kw883.png-wh_500x0-wm_ 3-wmp_4-s_690287931.png "style=" Float:none; "title=" Jmeter_use10_testplan_summary.png "alt=" Wkiom1kxikvrekstaacobv2p2kw883.png-wh_50 "/>

Here again, we are testing the CentOS7 installed in the Tomcat8 of the instance program, CentOS7 virtual machine with bridge mode, IP address is 192.168.60.198, the requested URL address is:/http 192.168.60.198:8080/examples/servlets/servlet/requestparamexample

Configuration information for HTTP Request defaults such as:

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/97/B9/wKioL1kxiKyjR6VJAACI6iWaxwM645.png-wh_500x0-wm_ 3-wmp_4-s_3280509525.png "style=" Float:none; "title=" Jmeter_use11_http_request_defaults.png "alt=" Wkiol1kxikyjr6vjaaci6iwaxwm645.png-wh_50 "/>

The configuration information for the CSV Data Set config is as follows:

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/97/B9/wKioL1kxiQexREU7AAB-uS5YhOw357.png-wh_500x0-wm_ 3-wmp_4-s_848900358.png "style=" Float:none; "title=" Jmeter_use12_csv_data_set_config.png "alt=" Wkiol1kxiqexreu7aab-us5yhow357.png-wh_50 "/>



Note: A file named Tomcat_performance_test_parameter.csv is mentioned here, this file and the current JMeter project file tomcat-based-test-plan-jmeter3.2_ The DEMO.JMX is placed in the same directory. You can use text editing software such as notepad++ to create this file and set the file encoding to utf-8 with the following file contents:

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/97/B9/wKioL1kxiQfi-Ed_AAA7LqE0X8U735.png-wh_500x0-wm_ 3-wmp_4-s_1683298002.png "style=" Float:none; "title=" Jmeter_use13_csv_data_set_config_data.png "alt=" Wkiol1kxiqfi-ed_aaa7lqe0x8u735.png-wh_50 "/>

Configuration information for HTTP request such as:

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/97/B8/wKiom1kxiSihtVZpAACP2fsi6bY112.png-wh_500x0-wm_ 3-wmp_4-s_882045296.png "style=" Float:none; "title=" Jmeter_use14_http_request.png "alt=" Wkiom1kxisihtvzpaacp2fsi6by112.png-wh_50 "/>
Configuration information for Thread Group

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/97/B9/wKioL1kxiSmwFNpTAABv8FDfTDE521.png-wh_500x0-wm_ 3-wmp_4-s_3362083758.png "style=" Float:none; "title=" Jmeter_use15_threadgroup.png "alt=" Wkiol1kxismwfnptaabv8fdftde521.png-wh_50 "/>

Note: This changes the number of tests to 100 for easy display.
2.7 Test Results
After you finish the test, you can view the results in listener.
Summary Report Interface

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/97/B8/wKiom1kxiSmCDhn6AABLHkNgRT0413.png-wh_500x0-wm_ 3-wmp_4-s_3963051937.png "style=" Float:none; "title=" Jmeter_use16_summary_report.png "alt=" Wkiom1kxismcdhn6aablhkngrt0413.png-wh_50 "/>

View Results in Table interface

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/97/B9/wKioL1kxiWCBTTWXAAHxzVw-lBE136.png-wh_500x0-wm_ 3-wmp_4-s_1678191763.png "style=" Float:none; "title=" Jmeter_use17_view_results_in_table.png "alt=" Wkiol1kxiwcbttwxaahxzvw-lbe136.png-wh_50 "/>
View Results Tree Default interface:

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/97/B8/wKiom1kxiWGA6Rf6AAE2QVjVTD0583.png-wh_500x0-wm_ 3-wmp_4-s_3078020004.png "style=" Float:none; "title=" Jmeter_use18_view_results_tree_text.png "alt=" Wkiom1kxiwga6rf6aae2qvjvtd0583.png-wh_50 "/>

The default is to display the response data in text format, and if the response data is xml/json/html, it can be changed to the corresponding display mode, which is more intuitive. In this case, the interface for displaying the response data in the browser is as follows:

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/97/B8/wKiom1kxiWHhMG8PAAE6qtbzBf4458.png-wh_500x0-wm_ 3-wmp_4-s_3217844808.png "style=" Float:none; "title=" Jmeter_use19_view_results_tree_browser.png "alt=" Wkiom1kxiwhhmg8paae6qtbzbf4458.png-wh_50 "/>


Create a stress test plan based on a template
The first example of a simple but complete HTTP web stress test is that most of the same type of stress test always has some common elements, so you can use a template to create a stress test plan.
1. Select Create a stress test plan from the template, such as:

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/97/B8/wKiom1kxiZXy8vghAACh693KpWE111.png-wh_500x0-wm_ 3-wmp_4-s_3350576750.png "style=" Float:none; "title=" Jmeter_use20_templates.png "alt=" Wkiom1kxizxy8vghaach693kpwe111.png-wh_50 "/>


2. Select "Building a Web Test Plan" In the popup dialog box, as shown in:

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/97/B9/wKioL1kxiZWTpd7kAACifcsyN9w300.png-wh_500x0-wm_ 3-wmp_4-s_1005635235.png "style=" Float:none; "title=" Jmeter_use21_template_select.png "alt=" Wkiol1kxizwtpd7kaacifcsyn9w300.png-wh_50 "/>

3. Click "Create" to build a stress test project based on the template, as shown in:

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M01/97/B8/wKiom1kxiZbimXXNAAEovVnb5i4790.png-wh_500x0-wm_ 3-wmp_4-s_1575513876.png "style=" Float:none; "title=" Jmeter_use22_template_finished.png "alt=" Wkiom1kxizbimxxnaaeovvnb5i4790.png-wh_50 "/>

Then add or remove some elements according to our own needs and then set them up for stress testing.
Stress test a database using JMeter
As mentioned above, JMeter supports a variety of stress tests, so let's talk about JMeter stress testing the database.
1. Database Preparation
First prepare the need to carry out the stress test database, this time I used to learn the crawler using a data, the basic information is as follows:
Database version: mysql-5.1.58
Database name: NETSKYCN
Query table name: Ty_content (with 748,007 data, 2.2GB).
The creation script for Ty_content is as follows:

CREATE TABLE ' ty_content ' (' Id ' int (one) not null auto_increment, ' ArticleID ' int (one) not null, ' content ' mediumt EXT not NULL, ' Contenthash ' VARCHAR (+) NOT null, ' createat ' DATETIME not null, ' IsVisible ' TINYINT (1) NULL Defau LT ' 1 ', PRIMARY KEY (' Id '), UNIQUE index ' Idx_contenthash ' (' Contenthash '), index ' Idx_articleid ' (' ArticleID ')) C Ollate= ' Utf8_general_ci ' Engine=myisam;

2.JDBC Drive Preparation
The JDBC driver can be downloaded from each database vendor's website, where I have downloaded the MySQL JDBC driver Mysql-connector-java-5.1.36.jar and copied it to the Lib directory in the JMeter directory.
3. Create Testplan
You can create a JDBC Test Plan based on a template, as shown in:

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/97/B8/wKiom1kxieHQNLb9AAGuNPsWIik615.png-wh_500x0-wm_ 3-wmp_4-s_3768990052.png "style=" Float:none; "title=" Jmeter_use23_template_jdbc.png "alt=" Wkiom1kxiehqnlb9aagunpswiik615.png-wh_50 "/>


4. Modify configuration information
1. First add the CSV Data Set Config, and prepare the Mysql_jdbc_articleid.csv file, mysql_jdbc_articleid.csv content as follows:

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/97/B9/wKioL1kxieGisbqWAAAkxX6Uj-g583.png-wh_500x0-wm_ 3-wmp_4-s_4258657510.png "style=" Float:none; "title=" Jmeter_use24_jdbc_csv_data.png "alt=" Wkiol1kxiegisbqwaaakxx6uj-g583.png-wh_50 "/>

There are 6,964 data in this file, which comes from the statistics of ArticleID in the Ty_content table (no duplicate data).
The configuration information for the CSV Data Set config is as follows:

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/97/B8/wKiom1kxieLz5bKIAABbGo8WYxs424.png-wh_500x0-wm_ 3-wmp_4-s_4270173237.png "style=" Float:none; "title=" Jmeter_use25_jdbc_csv_config.png "alt=" Wkiom1kxielz5bkiaabbgo8wyxs424.png-wh_50 "/>

The JDBC Connection configuration information is as follows:

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/97/B9/wKioL1kxieKgqMDBAACRjV-XfL4764.png-wh_500x0-wm_ 3-wmp_4-s_493397261.png "style=" Float:none; "title=" Jmeter_use26_jdbc_connection_config.png "alt=" Wkiol1kxiekgqmdbaacrjv-xfl4764.png-wh_50 "/>


The Thread group configuration information is as follows:

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/97/B8/wKiom1kxih2B8uAjAABErpm7flI964.png-wh_500x0-wm_ 3-wmp_4-s_416680448.png "style=" Float:none; "title=" Jmeter_use27_jdbc_thread_group.png "alt=" Wkiom1kxih2b8uajaaberpm7fli964.png-wh_50 "/>


The JDBC request configuration information is as follows:

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/97/B8/wKiom1kxih2jXTKlAABsSsnbHHk083.png-wh_500x0-wm_ 3-wmp_4-s_2257073006.png "style=" Float:none; "title=" Jmeter_use28_jdbc_request.png "alt=" Wkiom1kxih2jxtklaabsssnbhhk083.png-wh_50 "/>

Final Test results:

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/97/B9/wKioL1kxih7w2fDaAABFuAMgWtA444.png-wh_500x0-wm_ 3-wmp_4-s_3310692339.png "style=" Float:none; "title=" Jmeter_use29_jdbc_summary_report.png "alt=" Wkiol1kxih7w2fdaaabfuamgwta444.png-wh_50 "/>


Summarize:
This article describes how to use JMeter for Web and database stress testing, to create a stress test plan quickly, and to create a template. It can be seen that a jmeter stress test plan must contain the following elements: Threadgroup, request corresponding to the stress test plan (such as HTTP request or JDBC request), Listener (You can add as many Listener as you want), and to reduce the impact of caching, we show you how to use a CSV file to save parameter information from a test.
The best part of this article is how to stress test a Web site that requires authentication, and temporarily disable the CAPTCHA feature during a stress test for the needs of a verification code. In addition, for a variety of authentication methods, the method used also has a difference, during which I tried to target some of the sites need to establish a stress test plan, but did not find too much commonality of things, so in this article does not tell the content of this aspect, and so later there is time to summarize this aspect of the content.

This article is from the "Zhou Gong (Zhou Jinchao) column" blog, please be sure to keep this source http://zhoufoxcn.blog.51cto.com/792419/1931864

Developers learn Linux (4): Stress testing websites and databases using JMeter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.