1. Hardware and software configuration

The pressure test is carried out by installing JMeter on several servers as Slave and your local computer as Master. Currently, the following servers are available:

  1. 172.20.4.50;
  2. 172.20.4.52;
  3. 172.20.4.53;

1.1. Software configuration

Software to be installed:

  1. Jdk1.8.0_121, jMeter is developed in Java, so it needs JDK environment support;
  2. Apache – jmeter – 3.2;

1.2 Hardware configuration

Because the load test requires a large number of threads to simulate request access to the server, it relies heavily on the CPU and memory of the server.

Server IP Memory capacity (G) CPU information
172.20.4.50 15 Intel(R) Xeon(R) CPU E5506 @ 2.13GHz(octa-core)
172.20.4.52 15 Intel(R) Xeon(R) CPU E5506 @ 2.13GHz(octa-core)
172.20.4.53 15 Intel(R) Xeon(R) CPU E5506 @ 2.13GHz(octa-core)

2. Preparation before using JMeter

Because apache-JMeter-3.2 is installed on the server, you need to install jMeter of the same version locally. There are two main ways to use JMeter:

  1. GUI mode;
  2. In non-GUI mode, you need to record a script and specify a script file on the command line to execute it.

The above two approaches are basically the same, this article will only show you a simple use of the GUI pattern, if you want to understand more, please learn. The use case in this article uses the native as Master and the servers as slaves as an example. If the local performance is not up to the requirements, you can use one of the servers as Master and the other as Slave, so you need to use non-GUI mode for testing.

Note: This article uses Windows 7 as the Master for a brief introduction

2.1. Install JMeter

Before installing JMeter, you need to install JDK1.8.0_121 on Baidu.

Click download, apache-jmeter-3.2.zip

The installation steps are as follows:

  1. Decompress the downloaded package to a specified directory, such as D:\apache-jmeter-3.2;
  2. To configure environment variables, right-click your computer and choose Properties > Advanced System Settings > Advanced > Environment variables. Create a new JMETER_HOME variable in the system variable with the value of the directory in step 1.
  3. Change the Path variable to %JMETER_HOME%\bin after the value of the variable.
  4. Open CMD and run jmeter to start the JMeter GUI.

3. Use of JMeter

This article uses THE HTTP request test as an example, other tests, such as FTP request, please learn.

3.1. Simple use

The simple steps are as follows:

  1. Open CMD and run jmeter to start the JMeter GUI.
  2. To add a test plan, right-click on the test plan -> Add -> Threads(Users) -> Thread groups;
  3. Modify the thread group parameters as required:
A) Number of threads, how many threads are needed for testing; B) ramp-up Period(in seconds), how long it takes for the thread to fully start. If the number of threads is 3, this parameter is 1, then one thread is started every third second, if this parameter is 3, then one thread is started every second; C) Number of cycles, the number of cycles in the whole process; D) Delay Thead createtion until needed; E) The scheduler can control the time of the test plan according to the scheduler, such as the appropriate start, how long the test plan lasts, etc.Copy the code
  1. Add Sampler, thread group (right click) -> Sampler -> HTTP request;
  2. HTTP request parameters are set according to requirements, as shown in Figure 3.1.1;
  3. Add listeners to view result trees and aggregate reports.
  4. Start, view the test results and test specific request details in the listener, as shown in Figure 3.1.2;

3.2. Use distributed servers for pressure testing

Before testing on a distributed server, you need to modify the %JAVA_HOME%\bin\jmeter\bin\jmeter.properties file as follows:

# amend the remote_hosts = 127.0.0.1 # to remote_hosts = 172.20.4.50:1099172.20. 4.52:1099172.20. 4.53:1099Copy the code

Then restart Jemter, use the set test case, and select Remote startup, as shown in Figure 3.2.1. During startup, the results will be returned to the Master machine in batches for display. To reduce resource consumption, the specific result of the request is not returned. If you need to return, you need to configure the server extra.

4, interface pressure measurement skills

In order to meet the pressure test requirements, we need to test the simulated random parameters to avoid the interface cache affecting the test effect. For ordinary random parameters, you can use the built-in methods provided by JMeter directly. In addition to the built-in methods, JMeter also provides a configuration element for reading CSV files, allowing us to read specific parameters directly from the file.

4.1. CSV Data Set Config

After this component is added and configured, as shown in Figure 4.1.1, the variable name set can be directly used in the link of HTTP request, and the usage mode is ${variable name}.

Note that if you need the CSV file as source parameters, so in the case of distributed pressure measuring need to copy the same file to the server in the same directory, the provisional zha/TMP directory everyone to create the folder name to save their own temporary files, and need to be specified in the test plan for the file, otherwise the test to fail.

4.2, BeanShell Preprocessor

On some interfaces, you may need to add a signature, and the source of the signature is a parameter, and the signature string itself is also a parameter. In this case, we need to write a script to dynamically sign the parameters, and then use the signature string as the parameters to request. The specific steps are as follows:

  1. Use Java code to write the tag tool, into a JAR package;
  2. Set the jar package to %JAVA_HOME%\bin\jmeter\lib\ and restart jMeter.
  3. Add the BeanShell Preprocessor and write a script. The example script looks like this:
// Import com.test.m5dutil.md5util; // Import com.test.m5dutil.md5util; Put ("businessid", "1401"); // Businessid (vars), the link parameter, key, value, value, can put, can get vars. String businessid = vars.get("businessid"); String userid = vars.get("userid"); String userid = vars.get("userid"); String key = "dh8si93ihjs92z83mgzv19a75k"; String param = "businessid" + businessid + "&userid" + userid + "&key=" + key; String sign = md5util. encrypt(param, "UTF-8"); String sign = md5util. encrypt(param, "UTF-8"); System.out.println("sign = "+ sign); // Put the signature in vars. Put ("sign", sign);Copy the code

4.3 Resource Monitoring of the server under test

During the test, the resource consumption of the server under test is an important reference indicator. Jmeter provides plug-ins that can monitor the performance indicators of the server under test in real time, including memory, CPU and so on.

The plug-in installation process is as follows:

    1. Download jmeterplugins-extras-1.4.0.zip, jmeterplugins-standard-1.4.0.zip, serverAgent-2.2.1, jmeter-plugins-cmN-jmeter-0.4..jar;
    1. Insert jmeterplugins-extras.jar into apache-jmemeter-3.2 \lib\ext; insert jmeterplugins-extras.jar into apache-jmeter-3.2\lib\ext; insert jmeterplugins-extras.jar into apache-jmeter-3.2\lib\ext.
    1. Jmeterplugins-standard-1.4.0.zip and put the jmeterplugins-standard. jar file in the apache-jmeter-3.2\lib\ext directory.
    1. Jmeters-plugins-cmn-jmeters-0.4. jar is not available in apache-jmeters-3.2, so you need to put the jar file in apache-jmeters-3.2 \lib.
    1. The ServerAgent is directly run on the server under test. The Linux server runs startagent. sh, which is port 4444 by default and can be specified using commands.

    Restart JMeter and add listeners, as shown in Figure 4.3.1. The new listeners that start with jp@gc are from the plug-in you just installed. Then you can listen on the server under test in real time, as shown in Figure 4.3.2.

5. Distributed pressure measurement

Remote start command of pressure test is as follows:

Jmeter -n -t./ get_tv.jmx-r -L. / Results /get_tv_request. jtL-e-O./ Aggregation report -j jmeter_get_TV_ 'yyyyMMddHHmmss' / results /get_movie_request. jtL-e-o./ Aggregation report -j jmeter_get_movie_'yyyyMMddHHmmss'. Log jmeter -n -t / results /get_all_request. jtl-e-o./ Aggregation report -j jmeter_get_all_'yyyyMMddHHmmss'. Log jmeter -n -t Jmx-r-l./ Result/comprehensive_Request. Jtl-e-o./ Polymeric report -j jmeter_comprehensive_'yyyyMMddHHmmss'.logCopy the code

6, summary

Jmeter also has many functions, this article is just a brief introduction, want to further study need to learn.