Jmeter 基于Docker 实现分布式测试

基于Docker 实现分布式测试

  • 制作Jmeter基础镜像
  • 制作工作节点镜像
  • 启动工作节点
  • 启动控制节点
  • 遇到的问题

使用Docker 部署Jmeter非常方便,可以省略软件的安装以及配置,比如jdk、jmeter。需要部署多个工作节点可以节省时间。

在这里插入图片描述

  1. 控制节点(Master-主节点)只有一个,可以使用图形化的界面,方便操作
  2. 工作节点(Slave-从节点)使用Docker部署Jmeter镜像,工作节点的数量越多越好。
  3. 控制节点使用RMI 调用工作节点
  4. 控制节点测试计划设置的线程数量约等于工作节点宿主机能同时工作的线程数,这样能真实模拟用户同时发起的请求,压测的结果也准确些

制作Jmeter基础镜像

  1. 下载jmeter安装包 https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.6.3.tgz
  2. 编写 Dockerfile
FROM openjdk:8-jdk-alpine3.9
ARG JMETER_VERSION=5.6.3# 设置工作目录
WORKDIR /opt/jmeter# 复制 Jmeter
COPY apache-jmeter-${JMETER_VERSION}.tgz   ./# 安装
RUN tar -xvzf apache-jmeter-$JMETER_VERSION.tgz \&& rm apache-jmeter-$JMETER_VERSION.tgz# 设置环境变量
ENV JMETER_HOME /opt/jmeter/apache-jmeter-$JMETER_VERSION/
ENV PATH="$JMETER_HOME/bin:${PATH}"
  1. 文件目录关系如下
root@ubuntu:/home/chengdu/jmeter/docker# tree
.
├── apache-jmeter-5.6.3.tgz
├── Dockerfile
└── worker└── Dockerfile.worker
  1. 执行编译镜像命令
docker build -t jmeter:5.6.3 .
  1. 查看镜像是否编译成功
root@ubuntu:/home/chengdu/jmeter/docker# docker images|grep jmeter
jmeter                   5.6.3             37a73dacbe58   4 hours ago     342MB
jmeter-5.6.3             worker            80ae9383e488   4 hours ago     342MB

制作工作节点镜像

基于第一步的基础镜像制作

FROM jmeter:5.6.3# 默认使用1099端口,可以用参数覆盖
ARG RMI_PORT=1099
ARG LOCAL_PORT=50000ENTRYPOINT $JMETER_HOME/bin/jmeter-server \-Dserver_port=${RMI_PORT} \-Dserver.rmi.localport=${LOCAL_PORT} \-Djava.rmi.server.hostname=${HOST_IP} \-Jserver.rmi.ssl.disable=true

保存为 Dockerfile.worker,运行编译镜像命令

docker build -f Dockerfile.worker -t jmeter-5.6.3:worker .

启动工作节点

启动3个工作节点,注意,HOST_IP 变量可以填写宿主机的IP确保控制节点的网络能当前的宿主机

docker run -p 1099:1099 -p 50000:50000 -e RMI_PORT=1099 -e LOCAL_PORT=50000 -e HOST_IP=192.168.230.128 -it -d --name jmeter-worker-01 jmeter-5.6.3:workerdocker run -p 1100:1100 -p 50001:50001 -e RMI_PORT=1100 -e LOCAL_PORT=50001 -e HOST_IP=192.168.230.128 -it -d --name jmeter-worker-02 jmeter-5.6.3:workerdocker run -p 1101:1101 -p 50002:50002 -e RMI_PORT=1101 -e LOCAL_PORT=50002 -e HOST_IP=192.168.230.128 -it -d --name jmeter-worker-03 jmeter-5.6.3:worker

查看是容器否启动成功了 docker ps
在这里插入图片描述

启动控制节点

  1. 修该 jmeter.properties 的 remote_hosts 配置
remote_hosts = 192.168.230.128:1099,192.168.230.128:1100,192.168.230.128:1101
  1. 启动控制节点,windows 直接点击 jmeter.bat,启动成功之后会看到3个配置的节点
    在这里插入图片描述
  2. 点击远程启动所有
  3. 在容器中查看执行日志
    docker exec -it 98300e4cdea0 /bin/sh 进入容器shell 终端,可以看到有一个日志文件 jmeter-server.log
root@ubuntu:/home/chengdu/jmeter/docker/worker# docker exec -it 98300e4cdea0 /bin/sh
/opt/jmeter # ls
apache-jmeter-5.6.3  jmeter-server.log
/opt/jmeter # tail -200f jmeter-server.log
tail: invalid number '200f'
/opt/jmeter # tail -200 jmeter-server.log
2024-02-03 08:26:26,214 INFO o.a.j.u.JMeterUtils: Setting Locale to en_EN
2024-02-03 08:26:26,295 INFO o.a.j.JMeter: Loading user properties from: /opt/jmeter/apache-jmeter-5.6.3/bin/user.properties
2024-02-03 08:26:26,296 INFO o.a.j.JMeter: Loading system properties from: /opt/jmeter/apache-jmeter-5.6.3/bin/system.properties
2024-02-03 08:26:26,296 INFO o.a.j.JMeter: Setting System property: server_port=1099
2024-02-03 08:26:26,297 INFO o.a.j.JMeter: Setting System property: server_port=1101
2024-02-03 08:26:26,297 INFO o.a.j.JMeter: Setting System property: server.rmi.localport=50002
2024-02-03 08:26:26,297 INFO o.a.j.JMeter: Setting System property: java.rmi.server.hostname=192.168.230.128
2024-02-03 08:26:26,297 INFO o.a.j.JMeter: Setting JMeter property: server.rmi.ssl.disable=true
2024-02-03 08:26:26,324 INFO o.a.j.JMeter: Copyright (c) 1998-2024 The Apache Software Foundation
2024-02-03 08:26:26,324 INFO o.a.j.JMeter: Version 5.6.3
2024-02-03 08:26:26,324 INFO o.a.j.JMeter: java.version=1.8.0_212
2024-02-03 08:26:26,324 INFO o.a.j.JMeter: java.vm.name=OpenJDK 64-Bit Server VM
2024-02-03 08:26:26,324 INFO o.a.j.JMeter: os.name=Linux
2024-02-03 08:26:26,324 INFO o.a.j.JMeter: os.arch=amd64
2024-02-03 08:26:26,325 INFO o.a.j.JMeter: os.version=5.15.0-71-generic
2024-02-03 08:26:26,325 INFO o.a.j.JMeter: file.encoding=UTF-8
2024-02-03 08:26:26,325 INFO o.a.j.JMeter: java.awt.headless=true
2024-02-03 08:26:26,325 INFO o.a.j.JMeter: Max memory     =1073741824
2024-02-03 08:26:26,325 INFO o.a.j.JMeter: Available Processors =2
2024-02-03 08:26:26,342 INFO o.a.j.JMeter: Default Locale=English (EN)
2024-02-03 08:26:26,343 INFO o.a.j.JMeter: JMeter  Locale=English (EN)
2024-02-03 08:26:26,343 INFO o.a.j.JMeter: JMeterHome=/opt/jmeter/apache-jmeter-5.6.3
2024-02-03 08:26:26,343 INFO o.a.j.JMeter: user.dir  =/opt/jmeter
2024-02-03 08:26:26,343 INFO o.a.j.JMeter: PWD       =/opt/jmeter
2024-02-03 08:26:26,344 INFO o.a.j.JMeter: IP: 172.17.0.4 Name: 98300e4cdea0 FullName: 98300e4cdea0
2024-02-03 08:26:26,444 INFO o.a.j.r.RmiUtils: Disabling SSL for RMI as server.rmi.ssl.disable is set to 'true'
2024-02-03 08:26:26,444 INFO o.a.j.r.RmiUtils: Disabling SSL for RMI as server.rmi.ssl.disable is set to 'true'
2024-02-03 08:26:26,579 INFO o.a.j.e.RemoteJMeterEngineImpl: Starting backing engine on 1101
2024-02-03 08:26:26,579 INFO o.a.j.r.RmiUtils: Resolving by name the value of System property 'java.rmi.server.hostname': 192.168.230.128
2024-02-03 08:26:26,580 INFO o.a.j.r.RmiUtils: Local IP address=192.168.230.128
2024-02-03 08:26:26,580 INFO o.a.j.e.RemoteJMeterEngineImpl: IP address is a site-local address; this may cause problems with remote access.Can be overridden by defining the system property 'java.rmi.server.hostname' - see jmeter-server script file
2024-02-03 08:26:26,581 INFO o.a.j.e.RemoteJMeterEngineImpl: Creating RMI registry (server.rmi.create=true)
2024-02-03 08:26:26,581 INFO o.a.j.r.RmiUtils: Disabling SSL for RMI as server.rmi.ssl.disable is set to 'true'
2024-02-03 08:26:26,581 INFO o.a.j.r.RmiUtils: Disabling SSL for RMI as server.rmi.ssl.disable is set to 'true'
2024-02-03 08:26:26,589 INFO o.a.j.e.RemoteJMeterEngineImpl: Bound to RMI registry on port 1101
2024-02-03 08:30:46,724 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2024-02-03 08:30:46,984 INFO o.a.j.s.BatchSampleSender: Using batching for this run. Thresholds: num=100, time=60000
2024-02-03 08:30:46,985 INFO o.a.j.s.DataStrippingSampleSender: Using DataStrippingSampleSender for this run with stripAlsoOnError: true
2024-02-03 08:30:46,986 INFO o.a.j.s.BatchSampleSender: Using batching for this run. Thresholds: num=100, time=60000
2024-02-03 08:30:46,986 INFO o.a.j.s.DataStrippingSampleSender: Using DataStrippingSampleSender for this run with stripAlsoOnError: true
2024-02-03 08:30:47,111 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/html is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
2024-02-03 08:30:47,112 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for application/xhtml+xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
2024-02-03 08:30:47,112 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for application/xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
2024-02-03 08:30:47,115 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
2024-02-03 08:30:47,121 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/vnd.wap.wml is org.apache.jmeter.protocol.http.parser.RegexpHTMLParser
2024-02-03 08:30:47,121 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/css is org.apache.jmeter.protocol.http.parser.CssParser
2024-02-03 08:30:47,214 INFO o.a.j.p.h.c.CookieManager: Settings: Delete null: true Check: true Allow variable: true Save: false Prefix: COOKIE_
2024-02-03 08:30:47,227 INFO o.a.j.s.BatchSampleSender: Using batching for this run. Thresholds: num=100, time=60000
2024-02-03 08:30:47,227 INFO o.a.j.s.DataStrippingSampleSender: Using DataStrippingSampleSender for this run with stripAlsoOnError: true
2024-02-03 08:30:47,310 INFO o.a.j.e.RemoteJMeterEngineImpl: Creating JMeter engine on host 192.168.230.128:1101 base '.'
2024-02-03 08:30:47,310 INFO o.a.j.e.RemoteJMeterEngineImpl: Remote client host: 192.168.230.1
2024-02-03 08:30:47,339 INFO o.a.j.s.FileServer: Default base='/opt/jmeter'
2024-02-03 08:30:47,357 INFO o.a.j.s.FileServer: Set new base='.'
2024-02-03 08:30:47,364 INFO o.a.j.e.StandardJMeterEngine: Applying properties {}
2024-02-03 08:30:47,413 INFO o.a.j.e.RemoteJMeterEngineImpl: Running test
2024-02-03 08:30:47,461 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2024-02-03 08:30:47,462 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2024-02-03 08:30:47,541 INFO o.a.j.e.u.CompoundVariable: Note: Function class names must contain the string: '.functions.'
2024-02-03 08:30:47,541 INFO o.a.j.e.u.CompoundVariable: Note: Function class names must not contain the string: '.gui.'
2024-02-03 08:30:51,297 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : 分布式测试
2024-02-03 08:30:51,298 INFO o.a.j.e.StandardJMeterEngine: Starting 10 threads for group 分布式测试.
2024-02-03 08:30:51,298 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2024-02-03 08:30:51,298 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=10 ramp-up=1 delayedStart=false
2024-02-03 08:30:51,449 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2024-02-03 08:30:51,450 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2024-02-03 08:30:51,516 INFO o.a.j.t.JMeterThread: Thread started: 192.168.230.128:1101-分布式测试 1-1
2024-02-03 08:30:51,592 INFO o.a.j.t.JMeterThread: Thread started: 192.168.230.128:1101-分布式测试 1-2
2024-02-03 08:30:51,681 INFO o.a.j.t.JMeterThread: Thread started: 192.168.230.128:1101-分布式测试 1-3
2024-02-03 08:30:51,761 INFO o.a.j.t.JMeterThread: Thread started: 192.168.230.128:1101-分布式测试 1-4
2024-02-03 08:30:51,853 INFO o.a.j.t.JMeterThread: Thread started: 192.168.230.128:1101-分布式测试 1-5
2024-02-03 08:30:51,857 INFO o.a.j.p.h.s.HTTPHCAbstractImpl: Local host = 98300e4cdea0
2024-02-03 08:30:51,925 INFO o.a.j.t.JMeterThread: Thread started: 192.168.230.128:1101-分布式测试 1-6
2024-02-03 08:30:51,950 INFO o.a.j.p.h.s.HTTPHC4Impl: HTTP request retry count = 0
2024-02-03 08:30:51,972 INFO o.a.j.s.SampleResult: Note: Sample TimeStamps are START times
2024-02-03 08:30:51,972 INFO o.a.j.s.SampleResult: sampleresult.default.encoding is set to UTF-8
2024-02-03 08:30:51,972 INFO o.a.j.s.SampleResult: sampleresult.useNanoTime=true
2024-02-03 08:30:51,974 INFO o.a.j.s.SampleResult: sampleresult.nanoThreadSleep=5000
2024-02-03 08:30:52,023 INFO o.a.j.t.JMeterThread: Thread started: 192.168.230.128:1101-分布式测试 1-7
2024-02-03 08:30:52,122 INFO o.a.j.t.JMeterThread: Thread started: 192.168.230.128:1101-分布式测试 1-8
2024-02-03 08:30:52,192 INFO o.a.j.t.JMeterThread: Thread started: 192.168.230.128:1101-分布式测试 1-9
2024-02-03 08:30:52,297 INFO o.a.j.t.JMeterThread: Thread started: 192.168.230.128:1101-分布式测试 1-10
2024-02-03 08:30:53,189 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.230.128:1101-分布式测试 1-3
2024-02-03 08:30:53,190 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.230.128:1101-分布式测试 1-3
2024-02-03 08:30:53,217 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.230.128:1101-分布式测试 1-10
2024-02-03 08:30:53,217 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.230.128:1101-分布式测试 1-10
2024-02-03 08:30:53,218 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.230.128:1101-分布式测试 1-2
2024-02-03 08:30:53,227 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.230.128:1101-分布式测试 1-2
2024-02-03 08:30:53,243 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.230.128:1101-分布式测试 1-6
2024-02-03 08:30:53,243 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.230.128:1101-分布式测试 1-6
2024-02-03 08:30:53,245 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.230.128:1101-分布式测试 1-1
2024-02-03 08:30:53,246 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.230.128:1101-分布式测试 1-1
2024-02-03 08:30:53,246 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.230.128:1101-分布式测试 1-7
2024-02-03 08:30:53,246 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.230.128:1101-分布式测试 1-7
2024-02-03 08:30:53,250 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.230.128:1101-分布式测试 1-4
2024-02-03 08:30:53,352 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.230.128:1101-分布式测试 1-4
2024-02-03 08:30:53,354 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.230.128:1101-分布式测试 1-5
2024-02-03 08:30:53,354 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.230.128:1101-分布式测试 1-5
2024-02-03 08:30:53,428 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.230.128:1101-分布式测试 1-8
2024-02-03 08:30:53,430 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.230.128:1101-分布式测试 1-8
2024-02-03 08:30:53,469 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.230.128:1101-分布式测试 1-9
2024-02-03 08:30:53,469 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.230.128:1101-分布式测试 1-9
2024-02-03 08:30:53,476 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2024-02-03 08:30:53,476 INFO o.a.j.s.DataStrippingSampleSender: Test Ended on 192.168.230.128:1101
2024-02-03 08:30:53,477 INFO o.a.j.s.BatchSampleSender: Test Ended on 192.168.230.128:1101
2024-02-03 08:30:53,545 INFO o.a.j.s.DataStrippingSampleSender: Test Ended on 192.168.230.128:1101
2024-02-03 08:30:53,546 INFO o.a.j.s.BatchSampleSender: Test Ended on 192.168.230.128:1101
2024-02-03 08:30:53,567 INFO o.a.j.s.DataStrippingSampleSender: Test Ended on 192.168.230.128:1101
2024-02-03 08:30:53,567 INFO o.a.j.s.BatchSampleSender: Test Ended on 192.168.230.128:1101
2024-02-03 08:30:53,589 INFO o.a.j.e.StandardJMeterEngine: Test has ended on host 192.168.230.128:1101
  1. 查看运行结果
    在这里插入图片描述

遇到的问题

  1. 宿主机和容器网络不通,需要Docker重置网络,步骤
# 停止所有容器
root@ubuntu:/home/chengdu/jmeter/docker/worker# docker stop $(docker ps -aq)
7aa491cf6145
67f090336f59
5c456dd2242a
# 移除网桥
docker network rm bridge
# 重启docker服务,重新生成网桥
sudo service docker restart

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/457616.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

数据库触发器

在实际开发中,我们经常会遇到这样的情况:有 2 个或者多个相互关联的表,如 商品信息 和 库存信息 分 别存放在 2 个不同的数据表中,我们在添加一条新商品记录的时候,为了保证数据的完整性,必须同时…

服务器被黑,安装Linux RootKit木马

前言 疫情还没有结束,放假只能猫家里继续分析和研究最新的攻击技术和样本了,正好前段时间群里有人说服务器被黑,然后扔了个样本在群里,今天咱就拿这个样本开刀,给大家研究一下这个样本究竟是个啥,顺便也给…

工业以太网交换机引领现代工厂自动化新潮流

随着科技的飞速发展,现代工厂正迎来一场前所未有的自动化变革,而工业以太网交换机的崭新角色正是这场变革的关键组成部分。本文将深入探讨工业以太网交换机与现代工厂自动化的紧密集成,探讨这一集成如何推动工业生产的智能化、效率提升以及未…

【教学类-47-01】UIBOT+IDM下载儿童古诗+修改文件名

背景需求: 去年12月,我去了其他幼儿园参观,这是一个传统文化德育教育特色的学校,在“古典集市”展示活动中,小班中班大班孩子共同现场念诵《元日》《静夜思》包含了演唱版本和儿歌念诵版本。 我马上也要当班主任了&a…

分享66个行业PPT,总有一款适合您

分享66个行业PPT,总有一款适合您 66个行业PPT下载链接:https://pan.baidu.com/s/1kcUOfR_xtH9CAJC12prcTw?pwd8888 提取码:8888 Python采集代码下载链接:采集代码.zip - 蓝奏云 学习知识费力气,收集整理更不易。知…

矩阵的正定(positive definite)性质的作用

1. 定义 注意,本文中正定和半正定矩阵不要求是对称或Hermite的。 2. 性质 3. 作用 (1)Axb直接法求解 cholesky实对称正定矩阵求解复共轭对称正定矩阵求解LDL实对称非正定矩阵求解复共轭对称非正定矩阵求解复对称矩阵求解LU实非对称矩阵求解…

[晓理紫]AI专属会议截稿时间订阅

AI专属会议截稿时间订阅 关注{晓理紫|小李子},每日更新最新AI专属会议信息,如感兴趣,请转发给有需要的同学,谢谢支持!! 如果你感觉对你有所帮助,请关注我,每日准时为你推送最新AI专属…

pycharm deployment 灰色 一直无法点击

我的development的配置如下,我看了很多教程一直不知道为什么一直是灰色的, 文件夹配置: 如果你这里 Autodect,那么你Mapping 的文件夹应该是应该省略这个前缀的,例如我下面,我应该将本地文件夹映射到/home…

【经典项目】Java实现打地鼠小游戏(附源码)

一、游戏回顾 打地鼠游戏是一款简单而有趣的反应游戏。游戏中,你需要在地洞中出现的地鼠出现时迅速点击它们,以获得分数。以下是一般的打地鼠游戏玩法介绍: 准备阶段:游戏开始时,你会看到一个由多个地洞组成的游戏界面…

用python编写爬虫,爬取房产信息

题目 报告要求 工程报告链接放在这里 https://download.csdn.net/download/Samature/88816284使用 1.安装jupyter notebook 2.用jupyter notebook打开工程里的ipynb文件,再run all就行 注意事项 可能遇到的bug 暂无,有的话私信我

C:\Users\ShuYixiao>mysql ‘mysql‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件

这个错误信息表明 mysql 命令在你的系统中没有被识别。这通常意味着 MySQL 没有安装在你的电脑上,或者它的可执行文件路径没有添加到系统的环境变量中。以下是一些解决这个问题的步骤: 确认 MySQL 是否已安装: 如果你还没有安装 MySQL&#x…

Oracle Vagrant Box 扩展根文件系统

需求 默认的Oracle Database 19c Vagrant Box的磁盘为34GB。 最近在做数据库升级实验,加之导入AWR dump数据,导致空间不够。 因此需要对磁盘进行扩容。 扩容方法1:预先扩容 此方法参考文档Vagrant, how to specify the disk size?。 指…