conclusion

Today’s content is jMeter installation, JMeter timer and other operations, add, delete, change and check, and extract token.

Day09_JMeter software test

  1. The performance test

1.1. What is the performance test? Based on the protocol, it simulates the user to make a request and imposes a certain load on the server to test whether the performance indicators of the server meet the requirements

Performance test definition: to test various performance indicators of a system by using automated testing tools to simulate various normal, peak and abnormal load conditions. 1.2. Type of performance test

  1. Benchmarking: When low pressure is applied to the system, the health of the system is viewed and the correlation is recorded as a base reference
  2. Load test: continuously increase the pressure on the system or the duration under a certain pressure until one or more performance indicators of the system reach the safety critical value, for example, a resource has reached the saturation state.
  3. Stress testing: Stress testing evaluates the performance of a system at or above the expected load. The focus is on how well the system can handle peak load or beyond the maximum load.
  4. Stability test (reliability test) : When the system is under certain service pressure, the system runs for a period of time to check whether the system is stable. X3 24 hours
  5. Concurrent testing: Tests whether there are deadlocks or other performance problems when multiple users simultaneously access the same application, module or data record.

1.3. Performance testing tools

  1. Introduction of Jmeter

Apache Jmeter is a Java-based stress testing tool developed by the Apache Organization. 2.2. Why do we use Jmeter? It is open source, free, and written in Java, which can be integrated into other systems and can expand various functions. The plug-in supports interface testing, pressure (load and pressure) testing and other functions, and supports recording and playback. Easy interface debugging multi-platform support, can run on Linux, Windows, Mac support multi-protocol 2.3. Jmeter function

  1. The interface test
  2. The performance test
  3. Pressure test
  4. Web Automation Testing
  5. Database testing
  6. JAVA program testing

2.4. How to use Jmeter under Windows Jmeter download and install the login jmeter.apache.org/download_jm… , download corresponding files according to your platform

2.5. Install the JAVA environment. Install the JDK and configure environment variables.

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

2.6. Directory structure of Jmeter

Jar: Jmeter source package jmeter.bat: startup file jmeter.sh for Windows: Jmeter. log: jmeter run log file jmeter.properties: Jmeter configuration file jmeter-server.bat: Load generator service file jmeter-server: Linux load generator file /docs – Jmeter help/Extras – provides support for Ant and can also be used for continuous integration /lib – holds Jmeter dependent JAR packages. Also, install plug-ins in the Jmeter user manual in the /licenses directory, forget the /printable_docs directory

  1. Use Jmeter to test quick start

3.1. What process is a thread group: a running program corresponds to a process thread: a process has multiple execution threads thread group: according to the nature of the threads grouped into three relationships: a process has multiple thread groups, a thread group has multiple threads

Test plan – Thread Group – Number of threads in the thread group property

Concurrent execution: multiple threads to perform at the same time, the characteristic: the implementation of the end of the order is not consistent with the order of start Order: according to the startup sequence of thread execution by default, each thread in the thread group is concurrent execution each thread to perform HTTP requests set inside thread group sequential: check in the test plan (run independently each thread group)

Thread groups are used to simulate concurrent access by users

1.1.1. Creating thread groups

1.1.2. Thread group consists of three parameters: number of threads, ramp-up Period(in seconds), and number of cycles. 1.1.3. Number of threads: number of virtual users. A virtual user occupies a process or thread. Set the number of virtual users and in this case, set the number of threads. 1.1.4. Preparation Duration (s) : Indicates the time required for all the specified virtual users to start. If the number of threads is 20 and the preparation time is 10, it takes 10 seconds to start 20 threads. That’s two threads per second. 1.1.5. Number of loops: the 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. Total number of requests: 20 x 100=2000. If “always” is checked, all threads will continue to send requests and stop running the script as soon as possible. 1.1.6.. Scheduler: Set the start time and end time of the thread group (when configuring the scheduler, you need to check the cycle times to always) 1.1.7. Duration (s) : test duration, overwriting end time 1.1.8. Start Delay (s) : test delay start time, overwriting start time 1.1.9. Startup time: Test startup time, which is overridden by startup delay. When the startup time has passed, the current time will also overwrite it when manually testing only. 1.1.10. End time: the end time of the test, which is overridden by the duration.

3.2. Create an HTTP request

3.3. Specify the request domain name and request path

An HTTP request has a number of configuration parameters, as described below: Name: This attribute identifies a sampler. A meaningful name is recommended. Comment: Has no effect on the test, only user records user readable comment information. Server name or IP address: specifies the name or IP address of the server to which the HTTP request is sent. Port number: port number of the target server. Method: Used to send HTTP requests, including GET, POST, HEAD, PUT, OPTIONS, TRACE, and DELETE. Content encoding: Content encoding. The default value is ISO8859. Path: destination URL path (excluding server address and port)

3.4. Set the corresponding view content

3.5. View table information

Sample: serial number of each request Start Time: Start Time of each request Thread Name: Name of each Thread Label: Name of the Http request Sample Time: duration of each request, in milliseconds Status: Request status. check indicates success, cross indicates failure. Bytes: number of requests Sample number of requests, equal to the number of concurrent requests you set if successful times the number of loops average: Average time per thread request Latest sample: represents the time deviation in which the server responded to the last request: Changes in server response time, measurements of dispersion, or, in other words, distribution of data.

3.6. View the result tree

By looking at the result tree, we can see the result of each request, where red is the error request and green is the pass. Thread Name: Name of the Thread group Sample Start: Load time: Latency: Latency Size in bytes: total Size of the data to be sent Headers Size in bytes: Size of the rest of the data to be sent Sample Count: Error Count: indicates the statistics about interaction errors. Response Code: indicates the returned message. Response Message: indicates the returned message

3.7. Aggregation report parameter description

Lable: for each HTTP request, the Name of the HTTP request is displayed. For example, Baidu HTTP request Name is Baidu #Samples: Represents the total number of requests made in this test, as shown in the figure above, sougou and Baidu HTTP requests each send 30 requests. Average: The average response time, refers to all the requests of the average response time, above 30 request 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”, displayed a Median average response time in things: Line: response time of 90% users Min: minimum response time Max: maximum response time Error% : As shown in the figure above, in this test, 66.6% of sougou HTTP requests are in error, while baidu requests have no Throughput of error requests: Throughput, which by default represents requests completed per second, as shown in the figure above, 6.6 requests completed per second and 6.2 requests completed per second Recived KB/Sec: Amount of data received from the server per second, measured in kilobytes

3.8. Graphic results

Sample size: The 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 handled by the server per minute. Average: Total elapsed time divided by the number of requests sent to the server. Median: Half of the servers have response times below the change value and half have response times above it. Deviation: indicates the size of server response time variation and discrete degree measurement.

  1. The main components of Jmeter are introduced

1. The test plan is the starting point for testing with JMeter and 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 the Sampler, which is contained by the thread group. You can set it Up by going to Test Plan -> Add -> Thread Groups, and in the thread Groups panel there are several input fields: number of threads, ramp-up Period(in seconds), and number of cycles, where the ramp-up Period(in seconds) indicates that all threads have been created within that time. If there are eight threads ramp-up = 200 seconds, then the thread start interval is 200/8=25 seconds, which has the advantage of not putting too much load on the server initially. Thread groups are designed to simulate concurrent loads. 3. Sampler: Simulate various requests. All the actual testing is done by the sampler, and there are multiple requests. For example, HTTP and FTP requests. 4. Monitor: responsible for collecting test results and being informed of the way the results are displayed. The function is to display and count some data (throughput, KB/S…) from the sampler request. And so on. 6. Assertion: Used to judge whether the result of the request response is as expected and correct. It can be used to isolate problem areas, that is, to perform stress tests while ensuring proper functionality. This limitation is very useful for effective testing. 7. Timer: Responsible for defining the delay interval between requests (threads) to simulate continuous requests to the server. Logic Controller: Behavior logic that allows JMeter to send requests to be customized and used in conjunction with Sampler to simulate complex sequences of requests. 8. The configuration component maintains the configuration information required by the Sampler and modifies the requested content according to actual needs. 9. The pre-processor and post-processor are responsible for completing the work before and after the request is generated. The front processor is often used to modify the Settings of the request, and the back processor is often used to process the data of the response.

4.1. Test plan

  1. The test plan is a complete scenario

  2. “Run each thread group independently” : When checked, all thread groups are executed sequentially. Otherwise, all thread groups can be started concurrently.

  3. Function Test mode: If this parameter is selected, detailed request records are generated, consuming resources and affecting client performance. This parameter is not selected.

  4. User-defined variables: Global variables, user-defined variables can be added to the test plan. Generally add some common configurations of the system. You are not advised to add variables to the test plan if you want to change the environment and configuration during the test

4.2. The thread group

(1) Thread group

This is the thread we normally add to run. Generally speaking, a thread group can be regarded as a virtual user group, and 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 pre-test operations. These threads behave exactly like a normal thread group element. The difference is that these types of threads perform periodic thread group execution before executing tests; Similar to LoadRunner init, the test starts with initialization.

(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 element. The difference is that these types of threads execute periodic thread groups after the test ends; Similar to the end of LoadRunnner, the collection is done at the end of the test.

4.3. Sampler (Http Request)

HTTP request attributes parameter description:

1) Name: used to identify a sample. A meaningful name is recommended

2) Comments: it has no impact on the test and is only used to record user readable comments

3) Server name or IP address: the name or IP address of the server to which the HTTP request is sent, such as www.baidu.com

4) Port number: Specifies the port number of the target server. The default value is 80

5) Protocol: the protocol used to send HTTP requests to the target server. HTTP/HTTPS is case insensitive and the default is HTTP

6) methods: send the HTTP request method (link: www.cnblogs.com/imyalost/p/…

7) Content encoding: Encoding (content-type =application/json; Charset = utf-8)

8) Path: destination URL path (excluding server address and port)

9) Automatic redirection: If selected, jMeter will redirect the HTTP request to the new interface in response to 301/302

10) Use keep Alive: HTTP communication between jmeter and target server using keep-alive mode (default)

11) Use multipart/from-data for HTTP POST: used when sending HTTP POST requests

12) Parameters, Body Data and Files Upload

  1. Parameter refers to the argument in the function definition, while argument refers to the actual argument when the function is called

  2. Parameter = formal parameter, argument= actual parameter

3. In a less strict case, the two can now be mixed. Argument is usually used, while parameter is seldom used

While defining method, variables passed in the method are called parameters.

When a method is defined, 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 the argument.

4. Body Data refers to entity Data, namely the content of the main entity in the request message. Generally, when we send a request to the server, the parameters of the main entity carried can be written here

5, Files Upload refers to: get all contained resources from an HTML file: when selected, make an HTTP request and get the content of the HTML file in response to the HTML file

Parse and get all resources contained in HTML (images, Flash, etc.) : (Default is not selected.) If the user only wants to obtain a specific resource, fill in the Embedded URLs must Match text box below to download the specific resource expression. Only URLs pointing to the resource that match the specified regular expression will be downloadedCopy the code

4.4. Listeners collect test results and are told how the results should be displayed. Common examples include: aggregate reports, view result trees, view results in tables, and write result data to files. Just add the rest and see. Aggregated reports are described earlier, followed by screenshots of viewing the result tree and viewing the results in a table.

4.5. Logical Controller

4.6. Loop controller, transaction controller

1.1.11. Loop controller

1.1.12. What the transaction controller does: The transaction controller produces an extra sampler that counts all The Times of the controller’s children. • Generate parent sample: • Include duration of timer and pre-post processors in generated sample: If you select this item, the time of the timer will be counted. Otherwise, only the time of the sample will be counted

Create sample to access the home page and registration page

Generate aggregate reports

Check the

There is only one transaction report in the aggregate report

4.7. Assertions — Checkpoint Assertions are used to determine whether the result of a request response is as expected by the user. It can be used to isolate problem areas, that is, to perform stress tests while ensuring proper functionality. This limitation is very useful for effective testing.

4.8. Pre-processor and post-processor

Pre and Post Processors are responsible for completing the work before and after generating the request. The front processor is often used to modify the Settings of the request, and the back processor is often used to process the data of the response. We mainly use the regular expression extractor of the post-processor for dynamic correlation. www.cnblogs.com/fengpingfan…

4.9. Timers Timers are responsible for defining the delay interval between requests

  1. Parameterize the Jmeter component

5.2. Why do we use parameterization to perform batch operation, batch add and batch delete, and manual efficiency is too low? It is safe and efficient to use programs to replace manual acquisition and setting of data, such as: Parameterize the user name and password of the system under test to simulate the simultaneous login of multiple users 5.3. CSV Data Set Config can be dynamically obtained and Set through this component to achieve batch add operations

Filename: indicates the path of the required data file. If it is in the same path as the script, enter File encoding: The File encoding must be the same as the File. The default value is ANSI. Utf-8 Variable Names: Variable Names used to reference variables. Use commas (,) to separate each column in the data file. Delimiter: In a. TXT or. Dat file, use commas (,) or Tab (\t) to separate columns. Allow Quote data: Garbled characters occur when the “true” option is used to process full-corner characters. Recycle on EOF: Specifies whether to Recycle data at the end of a data file. When set to True, the number of threads is too high, and the data file will be read from the first line again when it reaches the last line. If the jmeter property csvDataset.eofString is set to False, the value defaults to csvDataset.eofString if you continue reading at the end of the file. Stop thread on EOF: If the value of Recycle thread on EOF is set to False and the value of 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. Sharing Mode: Sharing mode. It is used in all thread groups by default. Optionally, each thread group can be opened separately

View the result tree

5.4. Use Jmeter function assistant:

1, click options -> Function Assistant to bring up the function Assistant dialog box

2. Select the _CSVRead function (first box below)

3. Function parameters:

1) The first parameter: enter the file path.

2) The second parameter: the file column number starts from 0, the first column 0, the second column 1, the third column 2, and so on, and then click the “Generate” button, it will automatically generate the parameterized function we need.

  1. Copy the generated parameterized function wherever the copy procedure needs to use it.
  2. The _Random function is used when multiple data records need to be added and some fields need to be unique.
  1. Jmeter script recording

6.1. What is the script recorded At the time of test, there may be a lot of scripts or interface to test operation, and some test links need to be repeated high multi-threaded concurrent test, we usually for the some operations, recorded in a script, recording, after test will test them on this basis. 6.2. Jemeter Script Recording Mode BadBoy Script recording The Jmeter proxy server is used to record scripts

  1. Jmeter uses its own proxy server to record scripts

7.1. Create thread groups on the test plan

7.2. Adding a Recording Controller

7.3. Add an HTTP proxy server on the workbench

7.4. Configure the Http proxy server

7.5. Configure the Browser 1.1.13

1.1.14. Firefox

7.6. Browser request test

7.7. Filter Information Add the following information.. js.|.. css.|.. png.|.. jpg.|.. gif.|.. bmp.

  1. Script recording on an Android mobile phone

8.1. Check the COMPUTER IP address

8.2. Configure the mobile network connection

8.3. Mobile phone access to app

8.4. Simulated login operation

8.5. Stop script recording after the script is executed

8.6. Script test – Thread group set 10 threads to request 10 times each

8.7. View the result tree

  1. BadBoy script recording

9.1. Install badboy script software

Foolproof installation

9.2. Open the Badboy software

9.3. Badboy Script Recording Click the record button to record the script, complete the operation of opening Sogou search, searching the salary of the test position, and then stop and play back. (When playing back, garbled characters will be caused by coding reasons, so it needs to manually adjust garbled characters.)

9.4. Adding Verification Points Verification points are used to verify whether the script is executed according to the test idea and determine whether there are problems in the execution of the script

Badboy parameterization the so-called parameterization refers to that a parameter of a request is set multiple values in advance. When a specific request is made, the preset value is obtained. The parameters set in different business scenarios are inconsistent.

9.6. Exporting the Jmeter script

9.7. Verify the tests by importing badboy generated scripts into Jmeter

9.8. badboy concurrent test select Tools Run Background

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

  1. Jmeter extension – Displays memory renderings

Jmeter itself is not capable of showing memory, CPU, and throughput, but you can add these capabilities to Jmeter by adding plug-ins

www.cnblogs.com/imyalost/p/…

JMeter ServerAgent monitors resources

10.1. When the Linux server service is pressed, the running status of the server can be observed by adding plug-ins. 1. Resource Preparation 2. Environment Preparation 3. Resource Monitoring 1. Universal web disk: this time required plug-ins: JMeterPlugins – Extras. Jar JMeterPlugins – Standard. Jar ServerAgent – 2.2.1 Place jmeterplugins-extras. jar and jmeterplugins-standard. jar in the apache-jmeters-3.0lib \ext directory Prepare the environment. ServerAgent Service port The default port number is 4444. You need to configure the firewall to block this port. Vi /etc/sysconfig/iptables, add iptables -i INPUT -p TCP –dport 4444 -j ACCEPT

Java -jar./CMDRunner. Jar –tool PerfMonAgent –udp-port 7777 –tcp-port 7777 Port 7777 also needs to set firewall rules and use Telnet to locally test whether it is accessible

10.2. Listening on the Windows PC

Enable server listening on the server

jp@gc – Bytes Throughput Over Time: Throughput in different times (Bytes) display (chart) In the aggregation report, the Throughput is displayed according to the number of requests. For example, 1.9 requests are sent per SEC. The display here is a chart in Bytes, representing how many Bytes are sent per second

jp@gc – Hits per Second is the number of requests received per Second by the Web server, as detailed in the performance Test – Common Performance Metrics (1) blog post

jp@gc – PerfMon Metrics Collector: Server performance monitoring controls, including CPU, Memory, Network, I/O, etc. (this function is used to start startAgent on the server to listen to) select CPU, Memory, Network I/O, etc

  1. Jmeter database stress test

1. Start JMeter, open the interface tool, add a thread group, and add the driver

2, add a JDBC Connection Configuration, Connection pool Configuration file. [Add] — [Config component] — [JDBC Connection Configuration]

Variable Name: indicates the connection pool Name. JDBC Request uses this name to obtain the connection pool configuration. You can fill in the name at will, but it is better to have specific business meaning for easy understanding and memorability.

Others can be default, can be adjusted according to the actual situation to optimize the performance.

The Database URL: data link URL, format: JDBC: mysql: / / localhost: 3306 / host

Mysql > show global variables like ‘port’ show global variables like ‘port’

JDBC Driver Class: Driver name. Fixed: com. Mysql. JDBC Driver

Username: Username

Passowrd: Password Adds a JDBC Request.

3, right-click thread group [add] – [Sampler] – [JDBC Request]

Select Statement Updata Statement Prepared Select Statement (Placeholders are supported.) Prepared Update Statement: precompiled Update statements. Rollback Rollback Rollback Rollback Rollback Rollback

Parameter values: indicates the Parameter value. Parameterize values in SQL statements. So the input: localhost, root

Paramter types: indicates the parameter type. You can check the parameters of the database. Here are two CHAR,CHAR type.

Variable names: Variable names. That is, the filtered values are placed in variables. For example, the three columns of data are divided into variables: A,B, and C (in practice, the names must have practical meaning).

Result variable name: indicates the name of the stored variable. Store the entire result in a variable. Name: rs

Query Timeouts: timeout period.

  1. Jmeter regular expression extraction

12.1. Badboy recording script

12.2. Export the script to JMeter

12.3. Playback Fails – Session expires

12.4. View the returned information and search for userSession

Using the Jmeter regular extractor, you can extract the required content from the response result of the request, so as to achieve association. Association refers to the data dependence relationship between requests, and the data that needs to be sent back from the previous request needs to be retrieved from the next request

Position 1: Name and comment Regular expression describes a pattern of string matches. It can be used to check if a string contains a substring, replace a matched substring, or extract a substring from a string that matches a condition, etc. Character description

  • Matches the preceding subexpression zero or more times. For example, zo* matches “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 preceding subexpression zero or once. For example, “do (es)?” Matches “do”, “does”, and “doxy”. ? Equivalent to {0,1}. () marks the start and end of a subexpression. Subexpressions can be retrieved for later use. Matches any single character except newline \n. To match., use.

You construct regular expressions the same way you create mathematical expressions. That is, multiple metacharacters and operators can combine small 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 selection between characters, or any combination of all of these components. Position 2: Settings related to regular expression extraction

(1) Reference name: the next request to reference the parameter name, such as fill in title, can be used to reference it. (2) Regular expression: () : the enclosed part is to be extracted. . : Matches any string. + : one or more times. ? : Don’t be greedy and stop after the first match is found. (3) Template: use? If you have more than one regular expression in a regular expression, you can refer to it with {title}. (2) Regular expression: () : the enclosed part is to be extracted. . : Matches any string. + : one or more times. ? : Don’t be greedy and stop after the first match is found. (3) Template: use? If you have more than one regular expression in a regular expression, you can refer to it by title. (2) Regular expression: () : the enclosed part is to be extracted. . : Matches any string. + : one or more times. ? : Don’t be greedy and stop after the first match is found. (3) Template: use? By reference, if there are multiple regular expressions in a regular expression, it can be 2? 3 and so on, indicating the number of values resolved to title. For example, the number of values resolved to the title. For example, the number of values resolved to the title. For example, 1$indicates the first value parsed. (4) Matching number: 0 indicates random value, 1 indicates all value, usually 0 (5) default value: If the parameter does not get a value, it is given a value by default.