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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 关于IntelliJ Idea搭建javaweb项目出现的Error filterStart错误解决

    关于IntelliJ Idea搭建javaweb项目出现的Error filterStart错误解决随着java行业的快速发展,我们用的开发工具也从eclipse转到了IntelliJIdea,我相信很多朋友在用idea的时候都出过各种问题,今天我要说的这个问题,也是我耗费了一天时间才找到问题的缘由。          因为公司需要,我用idea搭建了一个Struts2+mybatis+spring的项目,因为之前没怎么用过idea,所以搭建的时候遇到了很多问题。在pom文件里把需要的

    2022年7月11日
    50
  • ldd 和ldconfig

    ldd 和ldconfig一、ldconfigldconfig是一个动态链接库管理命令,为了让动态链接库为系统所共享,还需运行动态链接库的管理命令–ldconfig。ldconfig命令的用途,主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下,搜索出可共享的动态链接库(格式如前介绍,lib*.so*),进而创建出动态装入程序(ld.so)所需的连

    2022年6月11日
    54
  • 现代文译为古文(形容环境幽静雅致的古诗)

    现代文译为古文(形容环境幽静雅致的古诗)1.今文:身不由己古译:向来心是看客心,奈何人是剧中人。2.今文:我们越来越陌生了古译:相達何必曾相识,再看君卿已陌路。3.今文:我也不想你,你也就别想我了,古译:我断不思量,你莫思量我。4.今文:物是人非,我们回不去了,古译:柳絮随风各西东,人事无非已不同。5.今文:每时每刻都在想你古译:思君如流水,何有穷已时。6.今文:再看熟悉的地方,一切物是人非古译:青瓦长忆旧时雨,朱伞深巷无故人…

    2022年4月18日
    67
  • NLP-结巴分词

    NLP-结巴分词结巴分词结巴分词是有国内程序员(https://github.com/fxsjy/jieba)做的一个分词工具,刚开始是Python版本的,后来由anderscui(https://github.com/anderscui/jieba.NET)移植到.Net上面。结巴分词的分词过程大致为:·前缀词典(Trie):用于存储主词典,也可以动态增删词条,这个词典可以理解为jieba所“知道”的词,或者说已登录词;·有向无环图(DAG):通过前缀词典,可以找出句子所有可能的成词结果;·最大概率

    2022年6月24日
    39
  • redis——持久化方式RDB与AOF分析

    redis——持久化方式RDB与AOF分析

    2021年11月4日
    37
  • 怎么解决dede首页网址自动加上index.html

    怎么解决dede首页网址自动加上index.html

    2021年10月7日
    44

发表回复

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

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