jmeter 分布式测试

jmeter 分布式测试

 

 

1、准备2台在同一个局域网内的机器,一台作为master主控机,一台作为slave 执行机

  master机器ip:172.16.20.134

  slave机器ip:172.16.20.146

2、在2台机器上安装同样版本的jmeter 和 java

3、关闭slave机器的防火墙,从master 机器能ping通到slave机器上

4、slave 机器进入jmeter\bin 目录,点击 jmeter-server.bat,启动jmeter remote 服务

  jmeter 分布式测试

5、编辑好jmeter 脚本,脚本功能,1)打开百度页面,2)一个beanshell脚本,打印本机ip。bean脚本:

jmeter 分布式测试

 

import java.net.InetAddress;
InetAddress addr = InetAddress.getLocalHost();  
String ip=addr.getHostAddress().toString(); //获取本机ip  
String hostName=addr.getHostName().toString(); //获取本机计算机名称  
System.out.println(ip);

整个jmeter脚本如下:

<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="3.2" jmeter="3.3 r1808647">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="测试计划" enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="线程组" enabled="true">
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器" enabled="true">
          <boolProp name="LoopController.continue_forever">false</boolProp>
          <stringProp name="LoopController.loops">2</stringProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">10</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <longProp name="ThreadGroup.start_time">1528965503000</longProp>
        <longProp name="ThreadGroup.end_time">1528965503000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </ThreadGroup>
      <hashTree>
        <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP请求" enabled="true">
          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
            <collectionProp name="Arguments.arguments"/>
          </elementProp>
          <stringProp name="HTTPSampler.domain">www.baidu.com</stringProp>
          <stringProp name="HTTPSampler.port">443</stringProp>
          <stringProp name="HTTPSampler.protocol">https</stringProp>
          <stringProp name="HTTPSampler.contentEncoding"></stringProp>
          <stringProp name="HTTPSampler.path"></stringProp>
          <stringProp name="HTTPSampler.method">GET</stringProp>
          <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
          <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
          <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
          <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
          <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
          <stringProp name="HTTPSampler.connect_timeout"></stringProp>
          <stringProp name="HTTPSampler.response_timeout"></stringProp>
        </HTTPSamplerProxy>
        <hashTree/>
        <BeanShellSampler guiclass="BeanShellSamplerGui" testclass="BeanShellSampler" testname="BeanShell Sampler" enabled="true">
          <stringProp name="BeanShellSampler.query">import java.net.InetAddress;
InetAddress addr = InetAddress.getLocalHost();  
String ip=addr.getHostAddress().toString(); //获取本机ip  
String hostName=addr.getHostName().toString(); //获取本机计算机名称  
System.out.println(ip);</stringProp>
          <stringProp name="BeanShellSampler.filename"></stringProp>
          <stringProp name="BeanShellSampler.parameters"></stringProp>
          <boolProp name="BeanShellSampler.resetInterpreter">false</boolProp>
        </BeanShellSampler>
        <hashTree/>
        <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="察看结果树" enabled="true">
          <boolProp name="ResultCollector.error_logging">false</boolProp>
          <objProp>
            <name>saveConfig</name>
            <value class="SampleSaveConfiguration">
              <time>true</time>
              <latency>true</latency>
              <timestamp>true</timestamp>
              <success>true</success>
              <label>true</label>
              <code>true</code>
              <message>true</message>
              <threadName>true</threadName>
              <dataType>true</dataType>
              <encoding>false</encoding>
              <assertions>true</assertions>
              <subresults>true</subresults>
              <responseData>false</responseData>
              <samplerData>false</samplerData>
              <xml>false</xml>
              <fieldNames>true</fieldNames>
              <responseHeaders>false</responseHeaders>
              <requestHeaders>false</requestHeaders>
              <responseDataOnError>false</responseDataOnError>
              <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
              <assertionsResultsToSave>0</assertionsResultsToSave>
              <bytes>true</bytes>
              <sentBytes>true</sentBytes>
              <threadCounts>true</threadCounts>
              <idleTime>true</idleTime>
              <connectTime>true</connectTime>
            </value>
          </objProp>
          <stringProp name="filename"></stringProp>
        </ResultCollector>
        <hashTree/>
        <ResultCollector guiclass="StatGraphVisualizer" testclass="ResultCollector" testname="Aggregate Graph" enabled="true">
          <boolProp name="ResultCollector.error_logging">false</boolProp>
          <objProp>
            <name>saveConfig</name>
            <value class="SampleSaveConfiguration">
              <time>true</time>
              <latency>true</latency>
              <timestamp>true</timestamp>
              <success>true</success>
              <label>true</label>
              <code>true</code>
              <message>true</message>
              <threadName>true</threadName>
              <dataType>true</dataType>
              <encoding>false</encoding>
              <assertions>true</assertions>
              <subresults>true</subresults>
              <responseData>false</responseData>
              <samplerData>false</samplerData>
              <xml>false</xml>
              <fieldNames>true</fieldNames>
              <responseHeaders>false</responseHeaders>
              <requestHeaders>false</requestHeaders>
              <responseDataOnError>false</responseDataOnError>
              <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
              <assertionsResultsToSave>0</assertionsResultsToSave>
              <bytes>true</bytes>
              <sentBytes>true</sentBytes>
              <threadCounts>true</threadCounts>
              <idleTime>true</idleTime>
              <connectTime>true</connectTime>
            </value>
          </objProp>
          <stringProp name="filename"></stringProp>
        </ResultCollector>
        <hashTree/>
      </hashTree>
    </hashTree>
    <WorkBench guiclass="WorkBenchGui" testclass="WorkBench" testname="工作台" enabled="true">
      <boolProp name="WorkBench.save">true</boolProp>
    </WorkBench>
    <hashTree/>
  </hashTree>
</jmeterTestPlan>

6、master 主控机打开jmeter\bin\jmeter.properties 文件, 设置   remote_hosts=172.16.20.146:1099  

7、执行命令:jmeter -n -t baidu.jmx -l result.jtl -R 172.16.20.146:1099

jmeter 分布式测试

slave 机器执行结果,在salve 机器的console上打印了本机ip,调用成功

jmeter 分布式测试

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/101606.html原文链接:https://javaforall.net

(0)
上一篇 2021年6月6日 下午9:00
下一篇 2021年6月6日 下午10:00


相关推荐

  • Eureka集群原理

    Eureka集群原理问题:微服务RPC远程服务调用最核心的是什么?高可用,试想你的注册中心只有一个onlyone,它出故障了那就呵呵o( ̄︶ ̄)o了,会导致整个微服务环境不可用。解决办法:搭建Eureka注册中心集群,实现负载均衡+故障容错Eureka集群的原理:互相注册,相互守望。一个Eureka集群包含7001和7002等许多服务,在这个集群中,7001指向其他所有服务…

    2022年5月28日
    43
  • HTTP协议

    HTTP协议

    2022年1月21日
    56
  • http协议与tcp协议区别[通俗易懂]

    http协议与tcp协议区别[通俗易懂]http协议与tcp协议区别1、性质不同:http是一个简单的请求-响应协议。TCP是一种面向连接的、可靠的、基于字节流的传输层通信协议。2、连接不同:TCP连接到不同但互连的计算机通信网络的主计算机中的成对进程之间依靠TCP提供可靠的通信服务。http通常运行在TCP之上。指定了客户端可能发送给服务器什么样的消息以及得到什么样的响应。3、功能不同:当应用层向TCP层发送用于网间传输的、用8位字节表示的数据流,TCP则把数据流分割成适当长度的报文段,最大传输段大小(MSS)通常受该计算机连接的网

    2026年1月30日
    3
  • 一个Android健身APP源码(类似KEEP、FEEL、轻+、减约、薄荷等)[通俗易懂]

    一个Android健身APP源码(类似KEEP、FEEL、轻+、减约、薄荷等)[通俗易懂]一个Android健身APP源码这是一个Android毕业设计,模仿KEEP、FEEL、轻+、减约、薄荷等制作的健身APP,并且有社交功能。使用AndroidStudio开发,后台为tomcat“肌撕裂者”应用开发工具AndroidStudio安卓最低版本15(IceCream)Android4.0安卓编译版本

    2022年5月12日
    103
  • 这篇不讨好任何人的回忆录,记录了我从双非学校到BAT/TMD六offer的原因

    这篇不讨好任何人的回忆录,记录了我从双非学校到BAT/TMD六offer的原因注:给我想个新名字好不好呀,采用了直接发百元红包!没别的,想让大家认识兔兔rabbit,说一下自己的经验教训,应该会对很多人有帮助。一、前言在今年,我要毕业了,基本结束了大学生活,踏入了工作环境,觉得是时候写一个总结,给这段时光一个交代,也让多年后的我,还能回忆起这段经历,不忘初心。想起小学作文有个结构叫“总分总”,那我就先来简单的总结一下这两个环境吧。二、我的学校和工作学校,说实话,出了省就很少人知道的学校,学生基本和一流互联网公司无缘,如果范围缩小到后端开发,我觉得可以把基本去掉.

    2025年11月22日
    3
  • Win10怎么添加开机启动项?Win10添加开机自动运行软件三种方法

    Win10怎么添加开机启动项?Win10添加开机自动运行软件三种方法Win10 管理开机启动项的方法相信大家已经非常熟悉 msconfig 命令各系统都通用 那么很多用户发觉 Win10 和 Win7XP 等系统不同 没有启动文件夹 那么我们怎么添加开机启动项呢 如晨软件或程序没有开机启动设置的话 是的 在 Win10 中添加开机启动项虽然麻烦了些 但是还是可以设置的 下面小编就分享几种方法 方法一 开机启动文件夹 1 我们打开文件夹 C Users 用户 Administ

    2026年3月26日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号