One day, your BOSS asks you to do a concurrent performance test for a Google site with 100 users. What should you do?

Maybe your BOSS is a nerd and will ask you the following questions:

1. Jmeter Introduction/Installation

Apache JMeter™ is open source software developed by the Apache organization. It is a typical pure Java application that can be tested on different platforms such as Windows, Linux, or macOS. JMeter is mainly used for functional load testing of applications to measure software performance. It can also be used for other types of testing such as interface testing, API testing, etc.

Preparations before installation

1.1. Download JDK (you need to configure the Java environment before installing JMeter). Go to Oracle’s official website to download JDK.

1.2. Configuring Environment Variables (Not required for Windows and MAC)

1. After the JDK is installed, configure environment variables. Click Computer – Properties – Advanced System Settings, and click Environment Variables.

2. Create JAVA_HOME under the system variable and set the variable value to the local JDK installation path (for example, C: Program Files\Java\jdk1.8.0_202).

3. Edit the Path variable and add %JAVA_HOME%\bin and %JAVA_HOME%\jre\bin to the end

4. Verify that the Java environment is properly configured: Go to the DOS interface and run the Java -version command. If the version number is displayed, the configuration is successful.


Jmeter environment setup

2.1.JMeter download address

Click jump, download without installation, decompression can be used.

2.2. Environment variable Configuration (self-search)

2. Component introduction/operation principle (do a thread design to explain)

X1-x5 is a process of simulating load Y1: simulation process, simulating user request Y2: verifying the accuracy of results (response code /body) Z: collecting test results data

How it works: The basic principle of JMeter is to create a pool of threads. Multiple threads use a sampler to generate a lot of load, verify the accuracy of the results through assertions, and record the results through listeners. If the sampler has a parameter requirement, this can be done by configuring the master/preprocessor. If correlation is needed, it is done with a post-processor. If you want to simulate user scenarios, how many users to simulate, and how long to run, you need to set up thread groups. Simulate concurrency, using timer to complete. To simulate certain scenarios, we need to use the controller to do it.

3. Function introduction

Create threads – Simulate scenarios

1. Create a thread group

3.1. Create a thread group

Right-click on the test plan -> Add -> Thread (User) -> Thread Group.

3.2. Configuring Thread Groups (1) Number of threads: number of virtual users and number of simulated users.

(2) Ramp-up time: indicates the startup time of all virtual users. Indicates the total number of threads initialized in a few seconds.

(3) Cycle times: the cycle times of the request initiated by each thread. If the count is set to 10, the number of threads is 200. The total number of requests is 200 x 10.

(4) Scheduler: it will take effect only after the number of cycles is checked forever.

2. Create a request

4.1. Create AN HTTP request thread group by right-click -> Add -> Sampler ->HTTP Request

4.2. Configuring the HTTP Request (1) Protocol: This parameter is left blank. The default protocol is HTTP.

(2) Server name or IP address: the name or IP address (domain name) of the server to which the request is sent.

(3) Port number: port number of the target server. The default value is 80.

(4)HTTP request: request methods, commonly used GET, POST, Put… And so on.

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

(6) Content encoding: default value ISO8859. If the request parameter contains Chinese characters, enter UTF-8 to prevent garbled characters.

(7) Send parameters with the request: GET request parameters attached to the URL can be added in this way.

(8) Message body data: Write JSON data {” Key “:” Value “} in POST/PUT request.

3. Create a listener

5.1. Add listener thread group right click → Add → Listener → view result tree, aggregate report, etc. (can also be added under the test plan, it listens to multiple thread groups at the same time; Or in the case of an HTTP request, listen for a request)

View the total number of requests, sampler results (status code, response information, etc.), request content, and response data.

5.3. Aggregate reporting

A Sample: total number of tests

B Average: The average response time of a single request

C Median: response time of 50% of users

D90% percentile: Response time of 90% users

E95%percentile: 95% user response time

F99% percentile: response time of 99% users

G Minimum: minimum response time

H Maximum value: the maximum response time

I Exception % : percentage of request exceptions

J Throughput (TPS) : Requests completed per second, throughput = requests/total time

KQPS: query rate per second, number of requests per second

L Receive: The amount of data received per second from the server segment

M Send: The number of requests sent from the client segment per second

4. Add a rear extractor

When multiple interfaces are associated, if you need to log in before planning query, you need to obtain the token of the login interface and transfer it to the next interface. You can use a post-extractor to solve the problem. Common post-extractors: Json extractor, regular expression extractor.

6.1. Adding a JSON extractor

Right click on the HTTP request -> Add -> Post-processor ->JSON extractor

Names of Created variables: Create variable Names for interfaces that need to be associated with references later

JSON Path expressions: Extract the desired value from the response data using $.

Match No.(0 for Random) : indicates the Match number

6.2. Add a regular expression extractor

Right click on the HTTP request -> Add -> Post-processor -> regular expression extractor

5. Set a meeting point

True concurrency does not exist, so in order to achieve a more realistic sense of concurrency, you can set up meeting points where the pressure is needed.

7.1 Adding a Synchronization Timer

Right click on HTTP request -> Add -> Timer -> Synchronize timer.

7.2 Configuring a Synchronization Timer

Number of simulated user groups: when the number of virtual users reaches the specified number, they can access the target url simultaneously.

6. The parameterized

8.1CSV Data File Settings

1. This method is suitable for a wide range of parameters and has greater flexibility.

2. Right-click on the thread group (sampler) and add -> Configure Components ->CSV data file Settings.

File name: Indicates the absolute path where the file is stored.

File encoding: Select UTF-8 when Chinese is involved in the data

Variable name: variable name used for reference, for example, username and password

Ignore the first line: If there is no variable name in the file and you need to read from the first line, select False; If you want to ignore the first line and start reading from the second line, select True.

Delimiter: A delimiter in a file, such as,

Select other items as required or default.

3, use ${variable name} instead of reference.

8.2 User Parameters

1. This parameter is applicable when the value range is small.

2. Right-click on the thread group (sampler) and add -> preprocessor -> User parameters.

8.3 User-defined Variables

1. Generally used for setting parameters that do not need to iterate with the request in Test Plan, such as Host and Port Number.

2. Right-click on the thread group (sampler) to add -> Configure Components -> User-defined variables, add variable name and variable value.

3, use ${variable name} instead of reference.

8.4 Function assistant *

The function ${__Random(,,)} can be used as a complement to other parameterization methods.

7. The recording

Built-in HTTP recording

3.1 Adding an HTTP Proxy Server Test plan Right-click on the test plan → Add → Non-test Component →HPPT proxy Server.

3.2 Configuring the HTTP Proxy Server (TestPlan Creation) (1) Port: the default port is 8888 and can be modified. Ensure that the port is not occupied.

(2) Target controller: Select which thread group to record the script under.

(3) Group: Whether to store recorded scripts in groups.3.3 Configuring THE Requests Filtering mode for the HTTP Proxy Server: Set this parameter manually using a regular expression. Click Add suggestion to exclude, filter useless scripts (such as CSS, JS, BMP)

3.4 Setting the Browser Proxy (Google Chrome is used as an example. Go to system Settings to search for proxy in browser Settings.)

(1) Enable manual proxy setting and enter the proxy address and port number.

Address: address of the jMeter server (127.0.0.1 or localhost for local browser tests).

Port: Match the port number set by the JMeter agent, then click Save.

Recording:

* Note: To record HTTPS scripts, import the CA security certificate:

1) click on options – > SSL manager in JMeter, import the JMeter/bin directory of the certificate file (valid for 7 days commonly, remember to replace) ApacheJMeterTemporaryRootCA. CRT.

In the browser, click Settings, search for Certificates, and import the certificate file to the trusted organization * in certificate Manager

1, HTTP proxy server -> click Start -> pop-up window, click OK.

2. Operate the browser to record the script. After recording, click Stop on the pop-up window.

3. View the recorded script.

Badboy record/playback

Download and install: www.cnblogs.com/xiaogongjin…

1. Enter the address we want to record in the input box

2. Click Record

3. Click to perform operations

4. We can operate and record on the right interface according to the content to be recorded

5. Recording OK, we can export the data. The exported file format is JMX, which can be directly imported into JMeter

Problems encountered and solved:

1. Modify the default recording status

Error message “the current page script error”

Solution: www.pianshen.com/article/297…

reporter

1. Connect to the JDBC database

2. Distributed pressure measurement

3. Monitor server performance indicators

4.BeanShell post-processor, secondary development

Friends can learn by themselves after thorough basic knowledge… Especially the second development of JMeter, start your learning now!!