JMeter Remote Test|Distributed testing

环境

CentOS 7.2
JMeter 3.2

Topologie

image.png
  • (Client|Master): the system running Jmeter which controls the slave remote (and doesn't send any request)
  • (Server|Slave|Remote) Node: the system running JMeter in server mod (jmeter-server), which takes commands from the client and send the test plan requests to the target system(s)
  • Target: the server to stress test

Configure Client Node

JMeter uses Java RMI [Remote Method Invocation] to interact with objects in a distributed network.
JMeter master and slave communicate as shown in the below picture.

image.png
  • remote_hosts: in client JMeter machine,add value of JMeter servers IP address. Multiple servers can be added comma-delimited. A more convenient way to specify remote host is from command line. Use -R command line to specify which remote host to use

  • client.rmi.localport: Specify client.rmi.localport in jmeter.properties file (for example - client.rmi.localport=25000). This is the port on which the local JMeter instance will listen for the Remote Method Invocation (i.e. RMI connections) from the slave nodes. Results would be sent to client from slave nodes on this port

Configure Server Nodes

Server nodes should be running same version of JMeter and java as client

Test datafiles are not sent across by client, hence they should be available in appropriate directory in each server. You can keep test data file in /bin folder in each JMeter server. It gets you rid of specifying full qualified path of test data file on each server instance.

To use different values for properties use corresponding values for user.properties and system.properties on each server

  • server.rmi.localport: By default, RMI uses a dynamic port for the JMeter server engine. This may cause issues with firewalls, so with versions of JMeter after 2.3.2 you can define the JMeter property server.rmi.localport to control this port number. To use a specific port for the JMeter server engine, define server.rmi.localport property before starting the server

JMeter/RMI requires:
a connection from the client to the server. Default port 1099.
and a reverse connection in order to return results from the server to the client. This will use a high-numbered port controlled by jmeter property “client.rmi.localport”

Prerequisites

All the nodes (client and servers):

  • are running the same version of JMeter.
  • are running the same version of Java. For JMeter 2.9, Java 6 runtime or higher
  • have extra test data files available in the appropriate directory
    are on the same subnet
  • can communicate (the firewalls must be turned off of set up to allow the connections)
  • must be started with the same property (file and command line option)

JMeter安装

下载解压即可。

wget https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-3.2.tgz
tar -xzf apache-jmeter-3.2.tgz

JMeter命令

-h 帮助 -> 打印出有用的信息并退出
-n 非 GUI 模式 -> 在非 GUI 模式下运行 JMeter
-t 测试文件 -> 要运行的 JMeter 测试脚本文件
-l 日志文件 -> 记录结果的文件
-r 远程执行 -> 启动远程服务
-H 代理主机 -> 设置 JMeter 使用的代理主机
-P 代理端口 -> 设置 JMeter 使用的代理主机的端口号

$ jmeter -n -t test1.jmx -l logfile1.jtl -H 192.168.1.1 -P 8080

方案1

client,server均采用手动部署方式,方便调试查错。

启动server:

[root@VM_1_111_centos bin]# ./jmeter-server -Djava.rmi.server.hostname=10.0.1.111
Created remote object: UnicastServerRef [liveRef: [endpoint:[10.0.1.111:36522](local),objID:[-77441bd0:15bf138f424:-7fff, -7104802513269301355]]]

启动client:

[root@VM_1_246_centos bin]# ./jmeter -n -t baidu-test.jmx -R10.0.1.111:31099 -Djava.rmi.server.hostname=10.0.1.246
Creating summariser <summary>
Created the tree successfully using baidu-test.jmx
Configuring remote engine: 10.0.1.111:31099
Starting remote engines
Starting the test @ Wed May 10 15:19:58 CST 2017 (1494400798945)
Remote engines have been started
Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
summary +      1 in 00:00:01 =    1.9/s Avg:   374 Min:   374 Max:   374 Err:     0 (0.00%) Active: 1 Started: 1 Finished: 0
summary =      1 in 00:00:01 =    1.9/s Avg:   374 Min:   374 Max:   374 Err:     0 (0.00%)
Tidying up remote @ Wed May 10 15:20:00 CST 2017 (1494400800718)
... end of run

可以看到server上的调用信息:

Starting the test on host 10.0.1.111:31099 @ Wed May 10 15:19:59 CST 2017 (1494400799839)
Finished the test on host 10.0.1.111:31099 @ Wed May 10 15:20:00 CST 2017 (1494400800740)

方案2

压测需要部署大量server节点,采用docker部署。

生成JMeter base镜像需要的Dockerfile如下:

# Use Ubuntu
FROM ubuntu
MAINTAINER adeng <xxxxxx@qq.com>

# Install wger & JRE
RUN apt-get clean && \
    apt-get update && \
    apt-get -qy install \
            wget \
            default-jre-headless \
            telnet \
            iputils-ping \
            unzip

# Install jmeter
RUN   mkdir /jmeter \
    && cd /jmeter/ \
    && wget https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-3.2.tgz \
    && tar -xzf apache-jmeter-3.2.tgz \
    && rm apache-jmeter-3.2.tgz \
    && mkdir /jmeter-plugins \
    && cd /jmeter-plugins/ \
    && wget https://jmeter-plugins.org/downloads/file/JMeterPlugins-ExtrasLibs-1.4.0.zip \
    && unzip -o JMeterPlugins-ExtrasLibs-1.4.0.zip -d /jmeter/apache-jmeter-3.2/

# Set Jmeter Home
ENV JMETER_HOME /jmeter/apache-jmeter-3.2/

# Add Jmeter to the Path
ENV PATH $JMETER_HOME/bin:$PATH

生成JMeter slave镜像需要的Dockerfile如下:

FROM malfurionpd/jmeter-base
MAINTAINER adeng <xxxxxx@qq.com>

# Ports to be exposed from the container for JMeter Slaves/Server
EXPOSE 31099 32500

# Application to run on starting the container
ENTRYPOINT $JMETER_HOME/bin/jmeter-server \
                        -Dserver.rmi.localport=32500 \
                        -Dserver_port=31099

可以参考这里在Dockerhub上生成镜像,或者本地生成:

docker build -t malfurionpd/jmeter-slave .

部署三个容器,主机端口直接映射容器expose的端口,client直接远程调用:

[root@VM_1_246_centos bin]# ./jmeter -n -t baidu-test.jmx -R10.0.2.104:31099,10.0.3.248:31099,10.0.3.180:31099 -Djava.rmi.server.hostname=10.0.1.246
Creating summariser <summary>
Created the tree successfully using baidu-test.jmx
Configuring remote engine: 10.0.2.104:31099
Configuring remote engine: 10.0.3.248:31099
Configuring remote engine: 10.0.3.180:31099
Starting remote engines
Starting the test @ Wed May 10 17:09:50 CST 2017 (1494407390007)
Remote engines have been started
Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
summary =      2 in 00:00:01 =    3.7/s Avg:   174 Min:   112 Max:   236 Err:     0 (0.00%)
Tidying up remote @ Wed May 10 17:09:51 CST 2017 (1494407391402)
summary +      1 in 00:00:01 =    0.8/s Avg:   721 Min:   721 Max:   721 Err:     0 (0.00%) Active: 0 Started: 2 Finished: 3
summary =      3 in 00:00:02 =    1.7/s Avg:   356 Min:   112 Max:   721 Err:     0 (0.00%)
Tidying up remote @ Wed May 10 17:09:52 CST 2017 (1494407392649)
... end of run
... end of run

方案3

参考这里,使用Rancher部署测试集群。

坑1

直接执行jmeter-server报错:

[root@localhost bin]# ./jmeter-server

Created remote object: UnicastServerRef [liveRef: [endpoint:[127.0.0.1:39150](local),objID:[-3126fe29:14300b1102e:-7fff, -4078314045196249121]]]
Server failed to start: java.rmi.RemoteException: Cannot start. localhost is a loopback address.
An error occurred: Cannot start. localhost is a loopback address.

解决方法如下:
In latest version, you can run your script with:指定本地IP

./jmeter-server -Djava.rmi.server.hostname=xxx.xxx.xxx.xxx

坑2

使用全容器部署时,不指定Host IP情况下 RMI总是出问题:

root@VM_7_2_centos:/jmeter/apache-jmeter-3.2/bin# ./jmeter -n -t baidu-test.jmx -Djava.rmi.server.hostname=10.0.7.2 -Dclient.rmi.localport=60000 -R10.0.7.14,10.0.7.7
Creating summariser <summary>
Created the tree successfully using baidu-test.jmx
Configuring remote engine: 10.0.7.14
Configuring remote engine: 10.0.7.7
Starting remote engines
Starting the test @ Tue Jun 13 12:59:01 UTC 2017 (1497358741786)
Error in rconfigure() method java.rmi.ConnectIOException: Exception creating connection to: 10.42.37.96; nested exception is:
    java.net.NoRouteToHostException: No route to host (Host unreachable)
Error in rconfigure() method java.rmi.ConnectIOException: Exception creating connection to: 10.42.255.116; nested exception is:
    java.net.NoRouteToHostException: No route to host (Host unreachable)
Remote engines have been started
Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445

解决方法和上边一样,必须想办法指定 ./jmeter-server -Djava.rmi.server.hostname=xxx.xxx.xxx.xxx

参考文章1
参考文章2
参考文章3
参考文章4
参考文章5
参考Docker三部曲之1
参考Docker三部曲之2
参考Docker三部曲之3

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,294评论 6 497
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,780评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,001评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,593评论 1 289
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,687评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,679评论 1 294
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,667评论 3 415
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,426评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,872评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,180评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,346评论 1 345
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,019评论 5 340
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,658评论 3 323
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,268评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,495评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,275评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,207评论 2 352

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,647评论 18 139
  • =========================================================...
    lavor阅读 3,488评论 0 5
  • Redis 配置文件示例 注意:想要读取配置文件,Redis的第一个参数必须是文件的路径 ./redis-serv...
    起个名忒难阅读 1,196评论 0 1
  • 雪白的墙上开始落下块状的墙灰 时间的蛇蜿蜒盘绕 屋顶上爬满青苔的砖瓦开始松动 时间的风悠久吹动 窗棂上纵横交错的木...
    廖丹妮阅读 232评论 0 0
  • :【我的简介很简洁:播音主持在读生。从专业上来说,跟口吃这两个字八竿子打不着。但此口吃非彼口吃,我爱吃,一口一口将...
    林HY阅读 364评论 3 3