Tremendous stress? Build a JMeter distributed pressure measurement environment to deal with it easily!

Table of contents

introduction

Windows environment deployment

1. Install environment variables

2. Configure environment variables

3. Modify the Jmeter configuration file

4. Start jmeter

5. Start the distributed service

Linux environment deployment

1. Install JDK+Jmeter

2. Environment optimization

4. Write Jmeter script

5. Start Jmeter

6. Stop Jmeter

7. Package view test report


introduction

Do you want to improve the performance of your application? Want to make sure it still works under heavy load? Then, you must need a reliable performance testing tool to help you accomplish this task.

JMeter is a widely used performance testing tool, but if your testing requirements become more complex and large, running on a single machine may not meet your needs. So is there a way to improve test efficiency?

Of course there is! It is a wise choice to build a JMeter distributed pressure testing environment. By adding multiple computer nodes, you can distribute the test load to different computers, thereby effectively improving test efficiency and saving a lot of time and effort.

In this article, we will introduce you in detail how to build a JMeter distributed pressure testing environment, and share some practical skills and experiences to help you easily cope with stressful testing tasks. let's start!

Windows environment deployment

1. Install environment variables

Download the JDK, which can be downloaded from the oracle official website

2. Configure environment variables

Install the downloaded JDk, add JAVA_HOME and fill in the JDK storage path (fill in according to your own path), such as C:\Program Files\Java\jdk1.8.0_202

Add JMETER_HOME and fill in the Jmeter storage path (fill in according to your own path), such as D:\office\3.software\jmeter5.1+java1.8\apache-jmeter-5.1.1

Add CLASSPATH and add the following at the end

;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%JMETER_HOME\lib\ext\ApacheJMeter_core.jar;%JMETER_HOME%\lib\jorphan.jar;%JMETER_HOME%\lib\logkit-2.0.jar

Add Path, add the following content at the end

%JAVA_HOME%\bin
%JAVA_HOME%\jre\bin
%JMETER_HOME%\bin

3. Modify the Jmeter configuration file

Enter D:/**/apache-jmeter-5.3/bin/jmeter.properties in the Jmeter configuration file

server.rmi.ssl.disable=true # Change false to true, remove the # in front

Add a compressor (this step is to add a compressor that needs to be started using Jmeter distribution, IP+port):

remote_hosts=xxx.168.xxxx.2:1099,xxxx.168.xxx.3:1099,xxxx.168.xx.4:1099

4. Start jmeter

Please see the following article to use the Jmeter tool: Getting Started with Jmeter Pressure Measurement Tool

5. Start the distributed service

Start the client jmeter-server.bat on the slave machine (compressor)

As shown in the figure below, the slave has been started.

After the slave machine is started, choose to run on the master, remote start/remote start all, and then the distributed multiple slave machines can be pressure tested together.

Linux environment deployment

1. Install JDK+Jmeter

Before installing jmeter, you need to install jdk first, download jdk (you can use the following address to download, or you can go to the official website to download, the official website needs to log in to oracle)

Link: https://pan.baidu.com/s/1Gu5pwMxyxGxN3X94E5NKYg?pwd=ai6j

(Intranet deployment only needs to manually upload the JDK and Jmter packages to the intranet for decompression, and the rest of the steps remain unchanged)

Unzip jdk, and install it to the /usr/local/java/ directory (the installation path is based on personal preference, but it must match the address in the environment variable)

tar -zxvf jdk-8u181-linux-x64.tar.gz

Configure environment variables, modify the configuration file vi /etc/profile, and add the following at the end of the text

JAVA_HOME=/usr/local/java/jdk1.8.0_181
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH

make the environment variable take effect

source /etc/profile

Verify that the jdk configuration is successful

java -version

Install Jmeter directly using the command

wget https://mirrors.bfsu.edu.cn/apache//jmeter/binaries/apache-jmeter-5.4.3.tgz

If it is an intranet environment, you need to manually upload the Jmeter installation package and download the latest version of Jmeter

Unzip jmeter, and install it to the /usr/local directory (the installation path is based on personal preference, but it must match the address in the environment variable)

tar -zxf apache-jmeter-5.4.3.tgz

Create script directory: /root/jmeter/scripts, #Address of script upload

Create a report directory: /root/jmeter/report, #Report generation storage directory

Configure the jmeter environment variable, vi /etc/profile, add the following at the end of the text

export JMETER_HOME=/usr/local/apache-jmeter-5.4.3
export CLASSPATH=$JMETER_HOME/lib/ext/ApacheJMeter_core.jar:$JMETER_HOME/lib/jorphan.jar:$CLASSPATH
export PATH=$JMETER_HOME/bin:$PATH

make the environment variable take effect

source /etc/profile

Verify jmeter configuration is successful

jmeter --version

2. Environment optimization

1. Configure the memory used by jmeter, modify it according to the actual server and test demand, the maximum is half of the server memory

vi /usr/local/apache-jmeter-5.4.3/bin/jmeter

2. Optimize linux memory parameters and modify the limits.conf file:

vi /etc/security/limits.conf

Finally add (different operating systems may be different, the following is centos):

*               soft    nofile            102400
*               hard    nofile            102400
*               soft    nproc             65535
*               hard    nproc             65535

Re-open the SSH terminal and execute the following command to check whether it takes effect

ulimit -n

3. Modify the Linux kernel parameters and modify the /etc/sysctl.conf file:

vi  /etc/sysctl.conf

and add the following:

net.ipv4.tcp_syncookies = 0
fs.file-max = 12553500
fs.nr_open = 12453500
kernel.shmall= 1048576
kernel.shmmax = 1887436
kernel.msgmax = 65536
kernel.sysrq = 0
kernel.pid_max= 65536
net.core.netdev_max_backlog = 2000000
net.core.rmem_default = 699040
net.core.rmem_max = 50331648
net.core.wmem_default = 131072
net.core.wmem_max = 33554432
net.core.somaxconn = 65535
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_mem = 1048576 1572864 2097152
net.ipv4.tcp_rmem = 4096 4194304 8388608
net.ipv4.tcp_wmem = 4096 4194304 8388608
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_window_scaling = 1
vm.swappiness = 0
#TCP connection recovery
net.ipv4.tcp_max_tw_buckets = 6000000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.route.max_size = 5242880
net.ipv4.ip_forward = 1
#0表示不开启检查时间错,建议设置0
net.ipv4.tcp_timestamps = 0
#开启对于TCP时间戳的支持,若该项设置为0,则下面一项设置不起作用
#TCP connection manager
net.ipv4.tcp_max_syn_backlog = 655360
net.ipv4.tcp_syn_retries = 6
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 6
#TCP keepalive
net.ipv4.ip_local_port_range = 1025 65534
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3

Enter the following command to make the kernel parameters take effect:

sysctl -p

3. Modify the Jmeter configuration file

Enter D:/**/apache-jmeter-5.3/bin/jmeter.properties in the Jmeter configuration file

server.rmi.ssl.disable=true # Change false to true, remove the # in front

Add a load machine (this step is to add a load machine that needs to be started using Jmeter distribution, IP+port):

remote_hosts=xxx.168.xxxx.2:1099,xxxx.168.xxx.3:1099,xxxx.168.xx.4:1099

4. Write Jmeter script

Debug the Jmeter script to be tested through Windows, save it as a ****.jmx file, and upload it to the Linux service.

5. Start Jmeter

1) Start the services on the slaves (all stress testing machines) respectively, the command is as follows (multiple network cards need to specify ip)

nohup jmeter-server -Djava.rmi.server.hostname=172.168.xxx.2 &  #压测机IP

2) Start the master, execute the following command to start jmeter

jmeter -r -n -t ***.jmx -l test.jtl
参数说明:
-n 非 GUI 模式 -> 在非 GUI 模式下运行 JMeter
-t 测试文件 -> 要运行的 JMeter 测试脚本文件
-l 日志文件 -> 记录结果的文件
-r 代表全部agent启动并参与测试

3) If you want to start the specified compressor, execute the following command

jmeter -n -t ***.jmx -l test.jtl -R xxxx.168.xx,xxxx.168.xx,xxxx.168.xx
参数说明:
-n 非 GUI 模式 -> 在非 GUI 模式下运行 JMeter
-t 测试文件 -> 要运行的 JMeter 测试脚本文件
-l 日志文件 -> 记录结果的文件
-R 指定的agent启动并参与测试

6. Stop Jmeter

Go to the bin directory of JMeter and enter ./shutdown.shthe command to stop the script

Note: If you want to terminate the stress test during the distributed stress test, do not press ctrl + c to forcibly terminate the program on Linux, so that you will know that after the main program hangs, the slave machine does not receive the execution, and it will continue run. When you run the script from the master again, the slave will still run in the program of the previous script, so you need to kill the process.

7. Package view test report

Pack the report under linux into zip, and then export it to windows to view the index.html test report

 

write at the end

This post ends here, and finally, I hope that friends who read this post can gain something.

It's all here, remember to support Sanlian.

-------------------------------------------------

How to download the full version of the document:

These materials should be the most comprehensive and complete preparation warehouse for friends who are engaged in [software testing]. This warehouse has also accompanied me through the most difficult journey, and I hope it can help you too! All of the above can be shared.

 

Interact with me in the comment area or privately ❤ me [Software Testing and Learning] to get it, no thanks for taking it away.

 

Guess you like

Origin blog.csdn.net/weixin_67553250/article/details/130952401