1. Performance testing

1.1. What are performance tests

1.1.1 Broad Definitions

Based on protocol simulation, users send requests to form a certain load on the server to test whether the server performance indicators meet the requirements. Performance indicators focus: time performance, space performance performance test has nothing to do with the page

1.1.1 Narrow Definition

It refers to the testing of system performance indicators through automated test tools that simulate various normal, peak, and abnormal load conditions.

1.2. Performance testing tools

Introduction to Jmeter

2.1. Why do we use Jmeter

Open source, free, based on Java code, can be integrated into other systems can expand the function plug-ins Support interface testing, pressure (load) and pressure testing of a variety of functions, support the recording playback, introduction to simple compared to writing your own framework to live other open source tools, have relatively perfect UI interface, easy to interface debugging Platform support, available in Linux, Windows, Mac run, support multiple protocols

2.2. Role of Jmeter

  1. Interface test interview said Postman, because convenient to use.
  2. Performance test JMeter, can also use Postman (runner), but there is no performance indicator
  3. Database testing

2.3. How to use Jmeter

Under Windows Jmeter download and install, login jmeter.apache.org/download_jm… , according to their own platform, download the corresponding file

2.4. Install the JAVA environment

Install the JDK and configure the environment variables.

Decompress the downloaded Jmeter file and open /bin/jmeter.bat

2.5. Directory structure of Jmeter

Common files in the /bin directory:

Examples: The directory contains Jmeter examples. Apachejmeter. jar: Jmeter source package Jmeter. Jmeter run log file Jmeter. Properties: Jmeter configuration file Jmeter -server.bat: Load generator service file in Windows Jmeter -server: The Linux startup load Generator files /docs directory -- The Jmeter Help documentation/Extras directory -- provides Ant support files, but can also be used in the continuous integration /lib directory -- stores Jmeter dependent JAR packages. Install plug-ins in the/Licenses directory -- software license file, never mind /printable_docs -- Jmeter User manualCopy the code

Use Jmeter to test quick start

3.1. What is a thread group

六四事件

A process has multiple threads of execution. Thread group: Grouping of threads by their nature. View the relationship between task manager (iQiyi has multiple) : a process has multiple thread groups, a thread group has multiple threadsCopy the code

Test Plan – Thread Group – Number of threads in the thread group property Concurrent execution: Multiple threads are executed at the same time. By default, threads in a thread group execute concurrently. Each thread executes HTTP requests within the group. Set thread group order: Select the thread group in the test plan (each thread group runs independently) to simulate concurrent access by users

3.1.1. Creating thread Groups

3.1.2. Thread groups consist of three main parameters:

Number of threads, ramp-up Period(in seconds), and number of loops.

3.1.3. Thread count:

Virtual number of users. A virtual user occupies a thread. Set the number of virtual users and in this case, set the number of threads.

3.1.4. Preparation Duration (seconds) :

How long does it take for the set number of virtual users to start up? If the number of threads is 20 and the preparation time is 10, then it takes 10 seconds to start 20 threads. That’s two threads per second.

3.1.5. Cycles:

Number of requests sent per thread. If the number of threads is 20 and the number of loops is 100, then each thread sends 100 requests. The total number of requests is 20*100=2000. If “forever” is checked, all threads will continue to send requests until they choose to stop running the script.

3.1.6. Scheduler

Set the start time and end time for the thread group to start. (When configuring the scheduler, check the number of cycles to forever.)

3.1.7. Duration (s)

The duration of the test, which overrides the end time

3.1.8. Startup Delay (s)

The test delays the startup time, overwriting the startup time

3.1.9. Startup time

Test startup time, which is overridden by startup delay. When the startup time has passed, the current time will override it when you manually test only.

3.1.10. End Time

Test end time, duration will override it.

3.2. Create an HTTP request

I’ve seen the most, so we’ll focus on:

3.3. Specify the request domain name and request path

Explanation of interface documents

An HTTP request has a number of configuration parameters, which are described below:
Name: This property is used to identify a sampler and a meaningful name is recommended.
Comments: Has no effect on the test, only the user records user-readable comments.
Server name or IP address: The name or IP address of the server to which the HTTP request is sent.
Port: port number of the target server.
Method: Methods of sending HTTP requests. Available methods include GET, POST, HEAD, PUT, OPTIONS, TRACE, and DELETE.
Content encoding: Content encoding. The default value is ISO8859
Path: Destination URL path (not including server address and port)

I’m going to click on the Run test, which is a lot of trouble, but I’m going to use the Postman test, which is much easier, and I’m going to use the Postman operation. You can demonstrate one using the aggregate interface in the interface document.

3.4. Set the content to be viewed

Note: If the listener starts with jp@gc, it is a third-party plug-in

Sample: indicates the sequence number of each request. Start Time: indicates the Start Time of each request. Thread Name: indicates the Name of each Thread. Request status. A check mark indicates success, and a cross mark indicates failure. Bytes: the number of Bytes requested. Sample number: the number of successful requests, which is equal to the number of concurrent requests you set times the number of loops. Average: Average time per thread requested. Changes in server response time, the size of the dispersion measure, or, in other words, the distribution of the data.

3.6. Viewing the Result Tree

  • Request data display (request header, request parameters,,)

  • Data display of the response (response code, response header,,)

By looking at the result tree, we can see the result of each request, where red is the request that failed and green is the request that passed.

Thread Name: Thread group Name Sample Start: Load Time: Load time Latency: wait time Size in bytes: total Size of data to be sent Headers Size in bytes: Size of the rest of the data to be sent Sample Count: Error Count: statistics on interaction errors Response Code: return code Response Message: Response message Response headers: returned header informationCopy the code

3.7. Aggregation report Parameters

Lable: for each HTTP request, the Name of the HTTP request is displayed. For example, the Name of a Baidu HTTP request is Baidu
#Samples: indicates how many requests were made during this test, as shown above, the Sougou and Baidu HTTP requests each made 30 requests
Business: the Average response time, refers to all the requests of the Average response time, above 30 requests of the total response time is divided by 30 to come up with the Average response time, the default is a single request under the Average response time, but when using the controller “affairs”, shows that the Average response time for the unit with the things
Median: Median response time of 50% of users
90%Line: 90% user response time
Min: indicates the minimum response time
Max: indicates the maximum response time
Error% : The number of incorrect requests/the total number of requests in this test. As shown in the figure above, in this test, 66.6% of Sougou’s HTTP requests were incorrect, while none of Baidu’s requests were incorrect
Throughput: Indicates the number of requests completed per second by default. As shown in the preceding figure, the number of requests completed per second is 6.6 and 6.2 respectively
Received KB/Sec: Indicates the amount of data received from the server per second. The unit is KB

Master: average time, error rate, throughput.

3.8. Graphical Results

Function: Display the distribution of the performance test data through graphs. The graphical results are generally used as an analytical aid for aggregated reports \

Sample number: Total number of requests sent to the server. Latest sample: a number representing the time when the server responded to the last request. Throughput: The number of requests processed per minute by the server. Average: Total run time divided by the number of requests sent to the server. Median: Half the server response times were below this value and half were above this value. Deviation: Indicates the size of the measured value of the server response time change and the degree of dispersion.Copy the code

Introduction to main components of Jmeter

  1. Test Plan: The starting point for testing using JMeter, which is a container for other JMeter test components.
  2. Thread group: represents a number of concurrent users that can be used to simulate concurrent users sending requests. The actual request content is defined in Sampler, which is contained by the thread group. This can be created by going to Test Plan -> Add -> Thread Group, and then in the thread Group panel there are several input fields: number of threads, ramp-up Period(in seconds), and number of cycles, where ramp-up Period(in seconds) indicates that all threads will be created within that time. If you have eight threads with ramp-up = 200 seconds, then the thread start time interval is 200/8=25 seconds, which has the benefit of not putting too much load on the server at first. Thread groups are designed to simulate concurrent load.
  3. Sampler: Simulate various requests. All the actual testing is done by the sampler, and there are many requests. Such as: HTTP, FTP requests, and so on.
  4. Listener: Is responsible for collecting test results and is also told how the results will be displayed. The function is to display the result of the request to the sampler, statistics some data (throughput, KB/S…) And so on.
  5. Assertion: Used to determine whether the result of a request response is correct or not as expected by the user. It can be used to isolate the problem domain, that is, to perform stress tests while ensuring proper functionality. This limitation is very useful for effective testing.
  6. Logic Controller: Allows you to customize the behavior logic of JMeter sending requests, which in combination with Sampler can simulate complex sequences of requests.
  7. Timer: Responsible for defining the delay interval between requests (threads) to simulate continuous requests to the server.
  8. The configuration component maintains the configuration information required by Sampler and changes the contents of the request as needed.
  9. The front processor and the post processor are responsible for completing the work before and after the request is generated. The pre-processor is often used to modify the Settings of the request, and the post-processor is often used to process the data in response.

4.1. Test Plan

1. The test plan is a complete scenario 2. "Run each thread group independently" : after this check, all thread groups are executed sequentially. This option is generally deselected to allow all thread groups to start concurrently. 3. Function Test mode: After this parameter is selected, detailed request records are generated, which consumes resources and affects client performance. Generally, it is not selected. 4. User-defined variables: Global variables can be added to the test plan. Generally, you can add some common system configurations. If you want to switch the environment and configuration during the test, it is generally not recommended to add variables to the test planCopy the code

4.2. The thread group

(1) Thread group

This is the thread we normally add to run. Colloquially speaking, a thread group can be seen as a virtual user group, each thread in the thread group can be understood as a virtual user.

(2) Setup thread group

A special type of ThreadGroup that can be used to perform a pretest operation. These threads behave exactly like a normal thread group component. The difference is that these types of threads perform periodic thread group execution before performing tests; Similar to LoadRunner’s init, initialization is performed at the beginning of the test.

(3) TearDown thread group

A special type of ThreadGroup that can be used to perform post-test actions. These threads behave exactly like a normal thread group component. The difference is that these types of threads execute periodic thread groups after the end of the test; End, similar to LoadRunnner, is reclaimed at the end of the test.

4.3. Sampler (Http request)

The HTTP request attributes are described as follows:

六四事件

1) Name: Used to identify a sample. You are advised to use a meaningful name. 2) Comment: has no effect on the test and is only used to record user-readable comment information. 3) Server name or IP: The name or IP address of the server to which the HTTP request is sent, such as http://www.baidu.com. Port number of the target server. The default value is 80. Do not enter 5) Protocol: the protocol for sending HTTP requests to the target server. http://www.cnblogs.com/imyalost/p/5630940.html) 7) Content encoding: Content encoding (the content-type = application/json; Charset = UTF-8) 8) Path: The destination URL path (not including the server address and port) 9) Automatic redirection: If this item is selected, the response to the HTTP request is 301/302, and the Jmeter will redirect to the new interface 10) Use keep Alive: Use multipart/from-data for HTTP POST: Use keep-alive to communicate with the target server. When sending an HTTP POST request, use 12) Parameters, Body Data, and Files Upload: parameter refers to the Parameters in the function definition, while argument refers to the actual Parameters in the function call. Parameter = formal parameter, argument= actual parameter 3. In the less rigorous case, now you can use argument and argument, While parameter uses less While defining method, variables passed in the method are called parameters. When defining a method, the variables passed into the method are called parameters. While using those methods, values passed to those variables are called arguments. When a method is called, the value passed to the variable is called an argument. (Sometimes the argument is translated as "argument") When selected, make an HTTP request and retrieve the contents of the HTML file in response. Parse the HTML and retrieve all the resources (images, flash, etc.) contained in the HTML file: (Not selected by default) If the user only wants to obtain a specific resource, you can fill in the Embedded URLs Must Match text box below with the specific resource expression to download. Only URLs that match the specified regular expression will be downloadedCopy the code

4.4. The listener

The Listener is responsible for collecting test results and is also told how the results will be displayed. Common examples include aggregating reports, viewing result trees, and viewing results in tables, all of which support writing result data to a file. Just add the rest and see. Aggregation reports were covered earlier, followed by screenshots of viewing the result tree and viewing the results in a table.

4.5. Loop controller

4.6. Transaction controller

What it does: The transaction controller produces an additional sampler that counts all The Times of the controller’s children. · Generate parent Sample: · Include duration of timer and pre-post processors in generated samples: If this item is selected, the time of the timer is counted; otherwise, only the time of the sample is counted

Create the sample to access the home page and the registration page

Generate aggregation reports

Check the

There is only one transaction report in the aggregate report

4.7. Assertions — Checkpoints

Assertions can be used to determine whether the result of a request response is what the user expects. It can be used to isolate the problem domain, that is, to perform stress tests while ensuring proper functionality. This limitation is very useful for effective testing. Two important assertions: response assertion and JSONAssertion response assertion:

JSON assertion:

4.8. Front and rear processors

Pre Processors and Post Processors are responsible for doing the work before and after the request is generated. The pre-processor is often used to modify the Settings of the request, and the post-processor is often used to process the data in response. We mainly use the postprocessor’s regular expression extractor for dynamic correlation. www.cnblogs.com/fengpingfan…

4.9. The timer

The Timer defines the delay interval between requests

5. Parameterization of Jmeter components

5.1. What is parameterization

Get and set data dynamically

5.2. Why use parameterization

六四事件

Batch operation, batch add batch delete, low manual efficiency using procedures to replace manual access and set data, safe and efficient such as: the user name and password of the system under test for parameterization, to simulate multiple users at the same time login systemCopy the code

5.3. User-defined variables for parametric implementation

Through this function, multiple interfaces can be realized to share data, modify one can modify all

Filename: indicates the path of the required data file. If the path is the same as that of the script, enter the File name. File Encoding: The encoding is the same as that of the File. The default encoding is ANSI. If the name is in Chinese, utF-8 Variable Names: specifies the Variable Names to be referenced. Each column in the data file is separated by commas (,). Delimiter: In.txt and.dat files, use commas (,) or Tab (\t) to distinguish columns from columns. Allow quote data: When this option is set to True, garbled characters occur during the processing of full-angle characters. Recycle on EOF: Indicates whether to read the data file in a loop at the end of the data file. Set to True if there are too many threads, the data file will read from the first line again when it reaches the last line. If the value is set to False, the value will default to if reading continues at the end of the file, which can be changed by setting the JMeter property cSvDataset. Eofstring. Stop Thread on EOF: Recycle on EOF is set to False and Stop Thread on EOF is set to True. The test is stopped after the last line of the data file is read, regardless of how many thread groups remain unexecuted. Sharing Mode: Sharing mode. By default, it is used in all thread groups. You can choose to open the same part of each thread group separately. Using user-defined variables, you only need to modify the interface effect once

5.4. Parameterized implementation of CSV Data Set Config

Add CSV Data Set Config:

Add interface:

Through this component, data can be dynamically obtained and set to achieve batch add operation.

六四事件

Filename: indicates the path of the required data file. If the path is the same as that of the script, enter the File name. File Encoding: The encoding is the same as that of the File. The default encoding is ANSI. If the name is in Chinese, utF-8 Variable Names: specifies the Variable Names to be referenced. Each column in the data file is separated by commas (,). Delimiter: Use commas (,) or Tab keys (\t) to distinguish columns from columns in. TXT or. Dat files. Whether to loop read at the end of the data file. Set to True if there are too many threads, the data file will read from the first line again when it reaches the last line. If the value is set to False, the value will default to <EOF> if reading continues at the end of the file, which can be changed by setting the JMeter property cSvDataset. Eofstring. Stop Thread on EOF: Recycle on EOF is set to False and Stop Thread on EOF is set to True. The test is stopped after the last line of the data file is read, regardless of how many thread groups remain unexecuted. Sharing Mode: Sharing mode. It is used by default in all thread groups, optionally open separately for each thread groupCopy the code

Reference: Added in JMeter

Change the thread number to a value to view the result tree:

Other:

  1. The number of threads in the thread group is changed to greater than the data in the file: the terminator is encountered in the loop to stop the thread
  2. If the data is from the database, the database exports the TXT file

5.5. Using Jmeter function helper (do not appear Chinese in the file) :

六四事件

Select the _CSVRead function (the first box in the figure below). 3. Function parameters: 1) The first parameter: fill in the file path. 2) The second parameter: the column number of the file starts from 0, the first column is 0, the second column is 1, the third column is 2, and so on. Then click the "Generate" button, and the parameterized function we need will be generated automatically. 3) Copy the generated parameterized function, where the copy process needs to use. 4) _Random function reads data randomly from a data segment to replace parameters. It is used when multiple data records need to be added and some fields need to be unique.Copy the code

Jmeter regular expression extraction

6.1. Use regular extract

Using the Jmeter regular extractor, you can get the required content from the response result of the request, thus achieving correlation. Association refers to the data that needs to be obtained from the previous request and sent back to the next request because there is a data dependency relationship between requests. Regular expression describes a pattern of string matching. It can be used to check whether a string contains a substring, replace a matching substring, or take a substring from a string that meets a condition, etc.

character describe
* Matches the previous subexpression zero or more times. For example, zo* matches both “z” and “zoo”. * is equivalent to {0,}.
+ Matches the previous subexpression one or more times. For example, ‘zo+’ matches “zo” and “zoo”, but not “z”. + is equivalent to {1,}.
? Matches the previous subexpression zero or one times. For example, “do (es)?” Matches “does” in “do”, “does” in “does”, and “do” in “doxy”. ? This is equivalent to {0,1}.
( ) Marks the start and end positions of a subexpression. Subexpressions can be retrieved for later use.
. Matches any single character other than the newline \n character. To match a., use a.

You construct regular expressions the same way you create mathematical expressions. That is, multiple metacharacters and operators can be used to combine smaller expressions to create larger ones. The components of a regular expression can be a single character, a set of characters, a range of characters, a choice between characters, or any combination of all of these components. Settings related to regular expression extraction \

Description:

六四事件

(1) Reference name: the name of the parameter to be referenced in the next request. For example, if title is entered, ${title} can be used to reference it. (2) Regular expression: () : The part in brackets is what to extract. . : Matches any string. + : one or more times. ? : Don't get greedy and stop after the first match. (3) Template: use $$reference, if there are more than one regular expression in the regular expression, then can be $2$$3$, etc., indicating the parse to the value of the title. For example: $1$indicates the first value (4) to be parsed. 0 indicates the random value, 1 indicates all values, usually 0 (5) default value: If the parameter does not get a value, it is given a value by default.Copy the code

Case: API interface \


1. What is script recording

When testing, there may be many scripts or interfaces that need to be operated to test, and some test links need to be tested with repeated multi-threaded high concurrency. We usually record a script for these operations, and then test can be conducted on this basis.

2. Jemeter Script recording mode

Web :BadBoy script recording App: Use the proxy server provided by Jmeter to record scriptsCopy the code

3. Script recording on Android

Premise: The computer and the phone are on the same network segment

1: adds an HTTP proxy server

2: Adds a recording controller to the thread

3: Specifies the path for recording scripts on the HTTP proxy server. The default port is 8888

4: View the local IP address (wifi hotspot)

5: Set the mobile agent, IP address, and port number

6: start

Click “ok”

7: Open the mobile app and grab the interface

8: Click “Stop” button to end recording

4. Record the script on the Web

4.1.  Install the Badboy script software

Fool type installation can be

4.2. Open the Badboy software

4.3. Badboy script recording

Click the record button to record the script, complete the operation of opening sogou search and searching the salary of the test position, then stop and play back (when playing back, there will be garbled characters due to coding reasons, so it needs to manually adjust the garbled characters)

4.4. Add verification points

The purpose of the verification point is to verify that the script is executed as we tested it, and to determine whether problems exist during the execution of the script

4.5. Badboy parameterization

Parameterization means that multiple values are set in advance for a parameter in a request. When a specific request is made, the preset values are obtained. The parameters set in different business scenarios are inconsistent.

4.6. Export the Jmeter Script

4.7. Import the script generated by Badboy into Jmeter to verify the test

4.8. Badboy concurrent test

Select Tools Run Background

4.9. Badboy Test report

You can see the test report under Badboy –> View –> Report


I. Database pressure measurement

1. Why do you need to test the database

Constantly put pressure on the database to verify the performance of the database processing

2. How to perform a database pressure test

In the process of testing, we often need to query, modify, add and other operations to the database table data. When using JMeter for performance or interface testing, you can also connect JMeter to a database and perform related operations on the database data. Let’s learn how to connect to a MySql database using JMeter.

2.1 the JDBC configuration
  • Start by creating a test plan and thread group, and then add the Configuration component JDBC Connection Configuration under the thread group.

  • Next, set the configuration items for the database connection.

Variable Name for created Pool: Specifies the Variable Name for creating the pool. This variable is used in the JDBC Request Request described later. Max Number of Connections: indicates the maximum Number of Connections allowed in the pool. In most cases, this is set to zero (0), which means that each thread will have its own pool with only one connection, which is not shared between threads. If you really want to use a shared pool, set Max count to the same as the number of threads to ensure that threads don't wait for each other. Max Wait (MS) : The pool throws an error if the timeout period is exceeded while attempting to retrieve the connection. Time Between Eviction Runs (ms) : The Time interval Between Eviction Runs (ms). The number of milliseconds elapsed between idle object ejection threads. When non-positive, no useless object ejection thread is run (default: "60000", 1 minute). Auto Commit: Automatically Commit or close the connection to the connection. Transaction Isolation: Indicates transaction isolation. This default can be, the specific usage has not been studied, will be able to share. Test While Idle: The Idle connection of the Test pool, which will be tested by subsequent validation queries. Soft Min Evictable Idle Time(MS) : Indicates the Soft Min Evictable Idle Time(MS). A connection may be idle in the pool and have at least an additional condition of an idle connection in the pool before it is eligible to be forcibly evicted by an idle object drive, which defaults to 5000 (5 seconds). Validation Query: Validation Query. A simple query to determine if the database is still responding. This validation query is used during pool creation, even if the "idle test" recommends that the query be used only on idle connections. The Database URL: data link URL, format: JDBC: mysql: / / localhost: 3306 / host annotation: Database of IP address + port/database name (query database port number show global variables like 'port') JDBC: mysql: / / 127.0.0.1:3306 / mydb2? ServerTimezone =UTC& allowMultiQueries=true JDBC Driver class: JDBC Driver class. MySql select com.mysql.jdbc.Driver Username: Username used to connect to the database. Password: Password for connecting to the database.Copy the code
2.2 After the setup is complete, create a JDBC Request Request under the thread group.

Next, add a view result tree listener in JMeter and run the script once.

2.3 the select statement
  1. Only the first data can be queried

六四事件

AllowMultiQueries =true allowMultiQueries=true allowMultiQueries=true allowMultiQueries=trueCopy the code
2.4 updata the statement
  • Modify the data

六四事件

Updata S, tatement Updata stu set name=" dafei "where id=1;Copy the code
  • The new data

六四事件

// First change the query type. Updata Statement INSERT intoCopy the code
  • Also added support and modification statements
  • Multiple statements are supported, but select can only place the last row
2.5 a Callable Statement
  • Supports query and modification
  • Support for multiple queries
2.6 Prepared the Select Statement

Note: The type must be Varchar

  • Combined with CSV to process multiple queries to create file data:

Add CSV data file Settings and write corresponding variables:

${id}

  • Add function assistant to the options, select csvread, fill in the path index, get the corresponding string, and pass the string as the value

Ii. Jmeter Server Pressure test (Windows)

When Jmeter tool is used for performance test or stress test, server resources need to be monitored, such as THE usage of CUP, memory resources of the server, etc. At this time, we need to configure relevant plug-ins for monitoring.

1. Resource preparation

Plug-in: JMeterPlugins – Extras. Jar, JMeterPlugins – Standard. The jar Insert jmeterplugins-extras. jar and jmeterplugins-standard. jar into apache-jmeter-3.0\lib\ext server: serveragent-2.2.1

2. Enable the server listening function on the server

3. Add a listener -jp@gc -perfmon Metrics Collector to the server (impersonating the server with the local database)

4. Add performance counters and set the number and time of threads

Ii. Jmeter Server Stress Test (Linux)

Many services are deployed on Linux, so we do server stress testing on Linux.

1. Resource preparation

Insert jmeterplugins-extras. jar and jmeterplugins-standard. jar into apache-jmeter-3.0\lib\ext directory and place serveragent-2.2.1 in opt directory of the Linux server. And extract the unzip

2. Environment preparation

ServerAgent The default port number is 4444. You need to configure the firewall not to block this port: Open Port 4444 for Linux external access

六四事件

/ sbin/iptables -i INPUT -p TCP -- dport 4444 - j ACCEPT/etc/rc d/init. D/iptables save - will change forever in the firewallCopy the code

3. Start the monitoring service on the server

./startagent.sh

4. Modify the JDBC Connection Configuration

Change the local address to the remote address