jmeter test--stress test

1. Preparations

Stress testing is required before the functions of the server are launched to reduce the probability of problems in the production environment after release. jmeter is one such tool. This tutorial is done on a mac.

1) install java

jmeter is written in java, you need to install java environment, just install jdk.

Official website to download Java Downloads | Oracle

2) Download jmeter

​​​​​​Apache JMeter - Download Apache JMeter

Download the latest tgz package and unzip it after downloading

3) start jmeter

Enter the decompressed bin directory, start jmeter through sh jmeter on the terminal, and the jmeter graphical operation interface will pop up

4) Switch to Chinese

选择options->choose language-->chinese(simpsimplified)

Do not close the terminal window after startup and the GUI window of jmeter

2. use

2.1 Thread Group

2.1.1 Create a thread group

      The process is: test plan ---> (right click) add --> thread ---> thread group. as follows:

2.1.2 Configuration parameters 

 The meaning of each parameter is as follows:

1) The action to be executed after the sampler error

  • Continue: A certain request fails, and other requests continue to execute. This choice is more in line with the actual situation when the amount of concurrency is large, and the failure of one request does not affect other requests.
  • Start the next process cycle: the request after encountering an error will not be executed, and will wait for the next round to start execution. If the thread group contains login and logout requests, and the login request fails, the logout request will not be executed until the next iteration
  • Stop thread: Stop the thread when an error is encountered. If there are 10 threads in the thread group, if a request of one of the threads encounters an error, the thread will stop and no longer execute, and the remaining 9 threads will continue to execute.
  • Stop the test: If a request of a certain thread fails, stop all threads, that is, stop the entire test, but the remaining requests in the thread will still be executed before stopping.
  • Immediately stop the test: Encounter an error and immediately hold up all threads, that is, the entire test.

2) Thread attributes

  • Number of threads: one thread is equivalent to one virtual user
  • Ramp-up time: The time interval between thread startup and running, in seconds, that is, how long it takes for all threads to start. For example, if there are 10 threads and the ramp-up is 20s, then 2 threads will be started per second. If not written, the default value will be 0, that is, all threads will understand to start after they are created.
  • Number of cycles: the number of requests for each thread, enter 1 to request 1 time, check forever to always request

3) Delay creating the scene until needed

  • Check: If the ramp-up of 10 threads is 20s, start a request every 2s
  • Unchecked: Start all threads after the test plan starts, but do not execute the following request immediately, but all threads are ready, but only one thread starts running the request in the second second

Which one to choose in actual operation does not affect the test results

4) Scheduler

  • Duration: How long the test plan lasts
  • Start delay: When the start button is clicked, only the creation is initialized, the thread is not run, and it is allowed to wait for the delay time to expire.

When the number of cycles and the duration exist in the thread group at the same time, the setting of the duration will not be executed. When setting the duration, the number of loops should be ticked Forever.

2.2 HTTP request

2.2.1 Add HTTP request

add process

     Thread Group---"Add----"Sampler----"HTTP Request. as follows

2.2.2 Configuration parameters

 

You can directly copy your own url into the path, select the http request method, and then copy and paste the request data in the message body data. Here I have only selected these few.

The parameters are as follows:

1) web server

  • Protocol: http request to the target server, it can be http or https, the default is http
  • Server name or IP: the target server or IP sent by the http request, you can leave it blank and put it in the path together
  • Port number: the port number of the target server, the default port of http is 80, the default port of https is 443, you can leave it blank, and put it in the path together

2) http request

  • Method: The method of the http request, you can choose get, post, head, put, etc.
  • Path: target url path, you can put the complete url here together
  • Content encoding: encoding method, the default is ISO-8859-1, and the general configuration is utf-8
  • Automatic redirection: When redirection is automatically redirected, it is only for GET and head requests. Automatic redirection can automatically jump to the final target page, but jmeter does not record the content of the redirection process (you can only see the redirection in the view result tree after the response content)
  • Follow redirection: When redirecting, jmeter records the content of the redirection process, and viewing the result tree can not only see the content of the redirected response, but also the content of the redirected money
  • Use keep-alive: selected by default. Use keep-alive for http communication between jmeter and the target server
  • Use multipart/from-data for post: When sending an http post request, use use multipart/from-data to send, which is not selected by default
  • Parameters: Send parameters together with the request, send them in the request, you can copy and paste the request information in the request body data in the parameters

2.3 Add view result tree

1) add

Right click on the thread group --> Add ---> Listener ---> View the result tree

2) Settings

 Select the display type of the result, request and response data, generally choose text or json

2.4 run

Click the green triangle start button to start

 Then click on an http request to see the returned analysis and status.

3. Report Analysis

Right-click the thread group --> Add ---> Listener ---> Summary report, you can view it

Chinese garbled

 

Guess you like

Origin blog.csdn.net/qq_38196982/article/details/123496595