JMeter分散テストの設定と実行方法

同一LAN内に2台のサーバーを用意し、マスターノードとスレーブノードとして設定します。マスターノードのIPアドレスは172.16.20.134、スレーブノードは172.16.20.146とします。
両マシンに同一バージョンのJMeterおよびJavaをインストールし、スレーブマシンのファイアウォールを無効化してマスターマシンからの接続を確認します。
スレーブマシンのjmeter/binディレクトリでjmeter-server.batを実行し、リモートサービスを起動します。
JMeterスクリプトを作成し、百度へのHTTPリクエストとBeanShellを用いたIPアドレス出力処理を含めます。BeanShellスクリプトの例:
import java.net.InetAddress; InetAddress hostInfo = InetAddress.getLocalHost(); String currentIP = hostInfo.getHostAddress(); System.out.println(currentIP);
マスターノードのjmeter.propertiesファイルにremote_hosts=172.16.20.146:1099を設定します。
コマンドラインで以下のコマンドを実行して分散テストを開始します:
jmeter -n -t distributed_test.jmx -l output.jtl -R 172.16.20.146:1099
<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> <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="変数定義" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> </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">5</stringProp> </elementProp> <stringProp name="ThreadGroup.num_threads">20</stringProp> <stringProp name="ThreadGroup.ramp_time">1</stringProp> </ThreadGroup> <hashTree> <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="百度アクセス" 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.method">GET</stringProp> <boolProp name="HTTPSampler.follow_redirects">true</boolProp> </HTTPSamplerProxy> <hashTree/> <BeanShellSampler guiclass="BeanShellSamplerGui" testclass="BeanShellSampler" testname="IP出力" enabled="true"> <stringProp name="BeanShellSampler.query">import java.net.InetAddress; InetAddress hostInfo = InetAddress.getLocalHost(); String currentIP = hostInfo.getHostAddress(); System.out.println(currentIP);</stringProp> </BeanShellSampler> <hashTree/> <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="結果表示" enabled="true"> <objProp> <name>saveConfig</name> <value class="SampleSaveConfiguration"> <time>true</time> <success>true</success> <threadName>true</threadName> <bytes>true</bytes> </value> </objProp> </ResultCollector> <hashTree/> </hashTree> </hashTree> <WorkBench guiclass="WorkBenchGui" testclass="WorkBench" testname="ワークベンチ" enabled="true"> <boolProp name="WorkBench.save">true</boolProp> </WorkBench> <hashTree/> </hashTree> </jmeterTestPlan>
スレーブマシンのコンソールにローカルIPアドレスが表示され、テストが正常に実行されたことを確認できます。

タグ: JMeter distributed-testing beanshell http-sampler remote-execution

7月16日 18:48 投稿