The purpose of this document is to teach you how to install JMeter and use JMeter to crimp the HTTP interface of your service

Windows installation jmeter

Install the JDK

You can skip this step if you already have Java installed on your computer

We will download the JDK installation package first. Here we recommend the official JDK download address of Java version 8

Below this [version number has the difference does not matter, anyway is the first table inside the Windows version

After the next step down double-click install, I recommend directly to the next step install to the default location, anyway, it is not big.

The current Java installation package seems to write the environment variables for us, so I didn’t change the environment variables after the installation anyway.

Install the jmeter

To download

Jmeter official download address

Under this

Jmeter doesn’t need to be installed. Just put the package where you want it and unzip it.

After decompression, a folder named apache-jmeter-5.4.1 will be generated in this directory. Double-click to enter the bin folder, double-click apachejmeter. jar or jmeter.bat in this directory to open JMeter.

At this point we are finished installing JMeter.

Jmeter is just installed in English by default. I will directly post the menu path of language modification here. You can find the path according to this option.

The use of Jmeter

Jmeter has many more powerful features, but this document only covers the ones I used for my own pressure tests, so you can explore other features if you’re interested.

Right-click the test plan in the upper left corner and select Add – Thread – Thread Group

Right-click the newly created thread group and select Add – Sampler -HTTP Request

Right-click the HTTP request you just created and select Add – Listener – Aggregate Report

All right, that’s all set up, so let’s talk about it

Select the thread group first

We’ll see a switch to the thread group interface on the right

The thread group interface controls the concurrency and duration of the pressure test. Settings here apply to all HTTP requests under this thread group

Let’s select HTTP request again on the left

As you can see, the HTTP request screen switches to the right

If we have interface to upload files, then we need to click the “File Upload” TAB in the middle

In short, you can build HTTP requests to your interface in the HTTP request interface, just like Postman.

Finally, let’s look at aggregate reports

Click the aggregated report in the tree on the left, and you can see the interface switch to the aggregated report on the right

The Chinese table headers are very easy to understand, I will briefly introduce it

field meaning
# sample The total number of requests actually initiated
The average Total response time of all requests/total requests
The median Assuming the total number of requests is 99, rank the 99 requests in descending order of time, and the 50th request takes the median \n. Assuming the total number of requests is 100, rank the 100 requests in descending order of time, and the average time of the 50th and 51st requests is the median \n as expressed in the following three table headers. We could call the median the 50% percentile.
90% percentile It is calculated in the same way as the median, except that it takes the 90th-ranked request \n, which can also be interpreted as 90% of requests with response times less than or equal to this value
95% percentile It is calculated in the same way as the median, except that it takes the 95th percentile of requests \n, which can also be interpreted as 95% of requests with response times less than or equal to this value
99% percentile It is calculated in the same way as the median, except that it takes the 99% request \n, which can also be interpreted as 99% request response times less than or equal to this value
The minimum value The shortest response time of all requests
The maximum The longest response time of all requests
Abnormal % To JMeter, an exception means that the HTTP return code is not 200. If the interface can be tuned, even if your program returns an error for some reason, JMeter will still consider the call a success
throughput The core data of our pressure measurement can be roughly understood as the amount of data requested to flow. The goal of our pressure test is to find the concurrency value with the highest throughput

You can create multiple HTTP requests under one thread group, as shown below

You can also set up several thread groups with only one HTTP request under each thread group

Any organization is fine, but note that adjusting concurrency is done in the Thread Groups interface. I personally prefer the following approach, which allows me to adjust the concurrency of each interface.

Another important thing to note is that if you only want to test one interface, be sure to disable other interfaces or thread groups.

If you have already compacted the aggregate report and there is data in the aggregate report, you need to adjust the concurrency number to compacted the report again. Remember to clear the aggregate report, right-click the aggregate report and choose Clear.

Make pressure test plan

We generally use the control variable method, the same interface, the same parameters [including file parameters], the same pressure test time, only the number of concurrent threads is different. Therefore, the general interface parameters will not move after setting, set the duration in the [Thread group] interface and will not move after setting, in the process of pressure measurement according to the need to adjust the [Thread group] interface thread number value.

An interface, you can have a time pressure can also enable multiple interface pressure together at the same time, at the same time enable multiple interfaces, and the multiple interfaces respectively belong to different 】 【 thread group, you can also set different to different thread group concurrency, in order to realize the some interface call less, some interface call more 】 the effect.

Specific went considering with your actual situation.

It is generally recommended to start with a relatively small concurrency, such as if your server CPU is 8 cores or less, it is recommended that the concurrency is 1, 3, 5, 6, 7, 8, of course, if you have a good server configuration or service performance is very good then you can relax a little bit

Pressure measurement’s goal is to find the number of concurrent threads increases but not increase the concurrency of throughput, if there is no increase throughput elucidation service pressure already came, there is always something to the bottleneck, the throughput of concurrency is your biggest the maximum number of concurrent service currently, more than the number then add concurrent, throughput may even fall.

Preparation before manometry

Here is a checklist. Please check item by item before you are ready to start the pressure test

  1. Check whether the IP address, port, request type, and interface path of the interface to be pressed are correct, and whether the interface that does not be pressed is disabled
  2. Check that the interface parameters to be squashed (especially the content type and the use of multipart/form-data for POST) and files are correct
  3. Check that the concurrency Settings are correct
  4. Check whether the concurrent time is set correctly. [Optional]
  5. Check whether the aggregation report is empty. [Optional]
  6. Check whether the pressured service restarts. [Optional]
  7. The pressured service is running properly
  8. Check whether other services on the server where the service is being pressed are shut down

Began to pressure measurement

Click the green arrow to start the pressure test. After the start, the stop button in the red box on the right will light up and become clickable. If you need to stop the pressure test, you can click the Stop button.

We usually set the same parameters and the same duration for the pressure test, so the pressure test duration is controlled by the [duration] parameter of the [Thread Group] interface.

After the pressure test is completed, you can go to the “Aggregation Report” page to view the pressure test result

Use JMeter on Linux

Because Windows has a number of distractions, including network bandwidth and other application competition, we generally recommend running stress tests on Linux.

Install the JDK

Here’s the same download address

Java official JDK download address

This time it’s going to be this

The general Linux is under this, of course, if you have other hardware architecture you can under other

Place jdK-8u291-linux-x64.tar. gz in /usr/lib on the server

-zxvf jdK-8u291-linux-x64.tar. gz: jdk1.8.0_291: jdk1.8.0_291: jdk1.8.0_291: jdk1.8.0_291: jdk1.8.0_291 Run mv./jdk1.8.0_291 JDK to rename it to JDK.

Then we need to modify the environment variables

vim /etc/profile

Add it at the end

#set java env
export JAVA_HOME=/usr/lib/jdk
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
Copy the code

Then :wq can be saved

Run source /etc/profile for the configuration to take effect immediately

To check whether the installation is successful, run the Java -version command to check whether the Java version can be printed

Install the jmeter

Installation file or the above called you under the ZIP, exactly the same, directly used

Copy apache-jmeter-5.4.1.zip to the appropriate location, anywhere. This document uses the /home directory as an example

Run the unzip apache-jmeter-5.4.1.zip command to decompress the package. After the package is decompressed, a folder named jmeter-5.4.1 is generated in this directory

Similar to Windows, JMeter on Linux does not need to be installed as long as it is unzipped

Then we need to modify the environment variables

vim /etc/profile

Add it at the end

Export JMETER = "/ home/JMETER - 5.4.1" export The CLASSPATH = "$JMETER/lib/ext/ApacheJMeter_core jar: $JMETER/lib/jorphan jar: $JMETER/lib/logkit - 2.0. The jar: $CLASSPATH"Copy the code

Then :wq can be saved

Run source /etc/profile for the configuration to take effect immediately

Began to pressure measurement

It is recommended that you set up all the configuration items in JMeter for Windows, including concurrency, interface parameters, etc. (note that if there are files, the file path will change on Linux, so do not change the file path on Windows). Then click file – Save Test Plan at the top to save your test plan in a file

As shown, it will be saved as a JMX file. You can choose the name of the file and the location of the file

Once saved, copy the JMX file to the pressure server, preferably to the /home/jmeter-5.4.1/bin directory, which is also the directory where jMeter will be started. Then copy the JMX file to the same directory, and use vim to edit the JMX file. Find the file path that you set to the file parameter. Change it to the file path that you set to the Linux environment. I just told you to put the file in the same directory as JMX. Save :wq.

At this point we can start the pressure test at /home/jmeter-5.4.1/bin

java -jar ApacheJMeter.jar -n -t test.jmx  -l test.jtl
Copy the code

Jmeter will start running, and it will automatically generate a JTL file in the current directory to write the test results, and then print “End of run”. At this point, we need to copy the JTL file from the server to the Windows version of JMeter. Open the “Aggregated Report” interface and click browseSelect the JTL file we just copied from the server to see the results of our pressure test on the server.