Stress testing tool Apache JMeter: 6: to build a distributed test environment

Original: stress test tool Apache JMeter: 6: to build a distributed test environment

Here Insert Picture Description
Apache JMeter is a pure Java open-source software for load testing or performance testing. This article by a specific test examples to explain how to use JMeter to build a distributed test environment, combined with a specific example to show the following method to perform stress testing JMeter in a distributed environment.

Preparing the Environment

Apache JMeter overview on the method of installation, the following can be found:

  • https://liumiaocn.blog.csdn.net/article/details/101264380

Distributed Test

And other master-slave designs, both roles, as shown below, Master node is responsible for forwarding and control, the Slave node responsible for implementation.
Here Insert Picture Description

Environment Settings

  • Host environment
liumiaocn:apache-jmeter-5.1.1 liumiao$ uname -a
Darwin liumiaocn 18.0.0 Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64
liumiaocn:apache-jmeter-5.1.1 liumiao$

  
  
  • 1
  • 2
  • 3

Note: Because it is theoretically Java application environment, it will not affect the host.

  • Distributed test environment
    used herein, a Master node, three main distributed test environment from the Slave nodes 3 formed, for ease of presentation using the same machine, the specific configuration is shown below
Types of IP port Explanation
Master node 192.168.31.242 - Master control for the node
Slave nodes -1 192.168.31.242 31099 Slave node 1 for measuring the pressure
Slave node -2 192.168.31.242 31020 Slave nodes are used for pressure measurement 2
Slave nodes -3 192.168.31.242 31021 Slave nodes are used to measure the pressure-3

Slave node set and start

In the JMeter bin directory, there are (execute scripts under windows) named jmeter-server (executing the script under linux or unix) and called jmeter-server.bat, this file can be used directly, but in fact, in the current this version, the script is still very simple, is to call the script jmeter more direct and flexible to jmeter-server as an example:

liumiaocn:bin root# tail -n1 jmeter-server
${DIRNAME}/jmeter ${RMI_HOST_DEF} -Dserver_port=${SERVER_PORT:-1099} -s -j jmeter-server.log "$@"
liumiaocn:bin root# 

  
  
  • 1
  • 2
  • 3

可以看到,其实这个脚本就是通过执行jmeter指定server_port和java.rmi.server.hostname的一个封装,而且日志的名称和路径都写死在了当前目录下,所以实际使用的时候建议直接使用如下命令启动Slave节点的JMeter

启动命令:jmeter -Djava.rmi.server.hostname=机器名或者IP地址 -Dserver_port=端口号 -s -j 日志文件名称

在本文的示例中,只需要分别在启动如下三个jmeter的Slave压测实例即可:

  • Slave节点-1

启动命令:bin/jmeter -Djava.rmi.server.hostname=192.168.31.242 -Dserver_port=31099 -s -j /tmp/jmeter-slave-1.log

  • Slave节点-2

启动命令:bin/jmeter -Djava.rmi.server.hostname=192.168.31.242 -Dserver_port=31020 -s -j /tmp/jmeter-slave-2.log

  • Slave节点-3

启动命令:bin/jmeter -Djava.rmi.server.hostname=192.168.31.242 -Dserver_port=31021 -s -j /tmp/jmeter-slave-3.log

以Slave节点-1为例,执行日志如下所示:

liumiaocn:apache-jmeter-5.1.1 liumiao$ bin/jmeter -Djava.rmi.server.hostname=192.168.31.242 -Dserver_port=31099 -s -j /tmp/jmeter-slave-1.log
Created remote object: UnicastServerRef2 [liveRef: [endpoint:[192.168.31.242:54607](local),objID:[-11cf5691:16d89ce546a:-7fff, 5500505409593956209]]]

  
  
  • 1
  • 2

Master节点设定与启动

最简单地设定方法下,Master节点只需要设定jmeter.properties中的remote_hosts即可。

  • 文件名称:jmeter.properties/user.properties
  • 所在目录:bin/
  • 修改项目:remote_hosts
  • 修改内容:设定Slave节点连接信息,格式为"IP地址:端口号",多个Slave节点的情况下,中间以逗号进行分割。
    本文设定示例如下所示:
remote_hosts=192.168.31.242:31099,192.168.31.242:31020,192.168.31.242:31021

  
  
  • 1

启动JMeter的Master节点

liumiaocn:apache-jmeter-5.1.1 liumiao$ bin/jmeter -j /tmp/jmeter-master.log
================================================================================
Don't use GUI mode for load testing !, only for Test creation and Test debugging.
For load testing, use CLI Mode (was NON GUI):
   jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]
& increase Java Heap to meet your test requirements:
   Modify current env variable HEAP="-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m" in the jmeter batch file
Check : https://jmeter.apache.org/usermanual/best-practices.html
================================================================================

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 结果确认
    正确设定的情况下,在GUI界面的 运行 -> 远程启动 子菜单中能够看到三个Slave节点的信息,具体如下所示:
    Here Insert Picture Description

分布式测试实例

事前准备

这里我们直接测试本地启动的nginx的Web服务为例,进行分布式测试示例说明,详细的测试相关的步骤可以参看如下内容

  • https://liumiaocn.blog.csdn.net/article/details/101596482

测试线程组设定为100,循环次数设定为10
Here Insert Picture Description
HTTP请求设定如下
Here Insert Picture Description

测试执行

上述压测的例子,是通过100个线程组进行10次循环的例子,我们这里分别在三个Slave节点上执行来确认效果。

执行方法:GUI界面的 运行 -> 远程启动 -> 选择对应的Slave节点即可
Here Insert Picture Description
分别选中三个节点,将上诉100x10的测试在三个Slave节点上分别执行。

结果确认

可以分别在三个启动的Slave节点的终端上进行日志确认,日志示例如下所示

  • Slave节点-1
liumiaocn:apache-jmeter-5.1.1 liumiao$ bin/jmeter -Djava.rmi.server.hostname=192.168.31.242 -Dserver_port=31099 -s -j /tmp/jmeter-slave-1.log
Created remote object: UnicastServerRef2 [liveRef: [endpoint:[192.168.31.242:58561](local),objID:[434e9282:16d89e44409:-7fff, -2787220660178629740]]]
Starting the test on host 192.168.31.242:31099 @ Wed Oct 02 08:35:23 CST 2019 (1569976523090)
Finished the test on host 192.168.31.242:31099 @ Wed Oct 02 08:35:24 CST 2019 (1569976524468)

  
  
  • 1
  • 2
  • 3
  • 4
  • Slave节点-2
liumiaocn:apache-jmeter-5.1.1 liumiao$ bin/jmeter -Djava.rmi.server.hostname=192.168.31.242 -Dserver_port=31020 -s -j /tmp/jmeter-slave-2.log
Created remote object: UnicastServerRef2 [liveRef: [endpoint:[192.168.31.242:58566](local),objID:[-728b31bf:16d89e45b1f:-7fff, -3170786169118547704]]]
Starting the test on host 192.168.31.242:31020 @ Wed Oct 02 08:35:28 CST 2019 (1569976528964)
Finished the test on host 192.168.31.242:31020 @ Wed Oct 02 08:35:31 CST 2019 (1569976531245)

  
  
  • 1
  • 2
  • 3
  • 4
  • Slave节点-3
^Cliumiaocn:apache-jmeter-5.1.1 liumiao$ bin/jmeter -Djava.rmi.server.hostname=192.168.31.242 -Dserver_port=31021 -s -j /tmp/jmeter-slav3.log
Created remote object: UnicastServerRef2 [liveRef: [endpoint:[192.168.31.242:58570](local),objID:[-45d3de23:16d89e468ca:-7fff, 5972975523351273653]]]
Starting the test on host 192.168.31.242:31021 @ Wed Oct 02 08:35:35 CST 2019 (1569976535306)
Finished the test on host 192.168.31.242:31021 @ Wed Oct 02 08:35:36 CST 2019 (1569976536673)

  
  
  • 1
  • 2
  • 3
  • 4

聚合报告信息如下所示
Here Insert Picture Description
可以看到"#样本"的数量为3000,说明HTTP请求的测试执行了3000次,而这三千次是通过分别在三个节点上执行一次而得到的。

常见问题对应

问题现象

提示java.io.FileNotFoundException: rmi_keystore.jks (No such file or directory)错误信息

liumiaocn:apache-jmeter-5.1.1 liumiao$ bin/jmeter -Dserver_port=11099 -s -j /tmp/jmeter-slave-1.log
Server failed to start: java.rmi.server.ExportException: Listen failed on port: 0; nested exception is: 
	java.io.FileNotFoundException: rmi_keystore.jks (No such file or directory)
An error occurred: Listen failed on port: 0; nested exception is: 
	java.io.FileNotFoundException: rmi_keystore.jks (No such file or directory)
liumiaocn:apache-jmeter-5.1.1 liumiao$ bin/jmeter -Dserver_port=1099 -s -j /tmp/jmeter-slave-1.log
Server failed to start: java.rmi.server.ExportException: Listen failed on port: 0; nested exception is: 
	java.io.FileNotFoundException: rmi_keystore.jks (No such file or directory)
An error occurred: Listen failed on port: 0; nested exception is: 
	java.io.FileNotFoundException: rmi_keystore.jks (No such file or directory)
liumiaocn:apache-jmeter-5.1.1 liumiao$

  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

原因

未设定ssh相关配置

对应方法

server.rmi.ssl.disable缺省值为false,将server.rmi.ssl.disable设定为true即可

  • File name: jmeter.properties/user.properties, user.properties proposed changes to the set covering more reasonable
  • Directory: bin /
  • Modify the project: server.rmi.ssl.disable
  • Content: the set point changes to true

Note: Another way passed through -Dserver.rmi.ssl.disable = true can be set.

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12205355.html