ApacheのJMeterは負荷テストや性能テストのための純粋なJavaのオープンソースソフトウェアです。動作は視覚ページのJMeterを用いて行われる紙の先行シートに記載され、Webアプリケーションのテストのために、同様にストレステスト物品は、例えば、非グラフィカルに測定された圧力の方法を記載しています。
環境の準備
アパッチのJMeterは、インストールの方法の概要は、以下を見つけることができます:
- https://liumiaocn.blog.csdn.net/article/details/101264380
JMeterの非GUIモード
デフォルトで-n非GUIモードで指定されたJMeterはJMeterのGUIインタフェースを開始していますが、起動時にも、次の情報が添付されています。
liumiaocn:apache-jmeter-5.1.1 liumiao$ bin/jmeter -j /tmp/jmeter-master.log
================================================================================
Don't use GUI mode for load testing !, only for Test creation and Test debugging.
For load testing, use CLI Mode (was NON GUI):
jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]
& increase Java Heap to meet your test requirements:
Modify current env variable HEAP="-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m" in the jmeter batch file
Check : https://jmeter.apache.org/usermanual/best-practices.html
================================================================================
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
非GUIモード対GUIモード
GUIモードを使用する場合、非GUIモードを使用しているとき?
注意は、負荷テストのためのGUIモードを使用していない、非常に明確にされています!唯一のテストまたはテストセットをデバッグするか、GUIモードを生成するために使用される場合です。
非GUIモードを使用する方法
次のようにコマンドパラメータを使用しました:
コマンドを実行します。JMeterの-n -t [JMXファイル] -l [結果ファイル] -e -o [テストレポートカタログ]
使用例
ストレステストアプリケーション準備
使用ポートに8088は、例が下に示されている(他の方法でも使用することができる)ドッカーアプリケーションnginxのローカルマシンを起動します。
liumiaocn:~ liumiao$ docker images |grep nginx |grep latest
nginx latest e445ab08b2be 2 months ago 126MB
liumiaocn:~ liumiao$ docker run -p 8088:80 -d --name=nginx-test nginx:latest
a80fb1a4fc20627891a6bd7394fd79ae9aefb7dc8cf72c12967bc2673a815308
liumiaocn:~ liumiao$
- 1
- 2
- 3
- 4
- 5
curlコマンドを使用するか、または実行されているnginxのを確認するために、ブラウザに指示
liumiaocn:~ liumiao$ curl http://localhost:8088/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
liumiaocn:~ liumiao$
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
文書作成JMX
JMeterの中のコマンドライン非GUIモードでは、JMXファイル情報スレッドグループの設定とテストを格納する、圧力測定は、入力情報であり、JMXファイルを生成する形式がXMLファイルJMXであるため、GUIインターフェイスを使用して生成することができます、おなじみの後も直接生成、編集することができます。
準備の前提を確認するためにテストを準備するには、次の手順を実行します。
-
ステップ1:以下に示すように、テストプログラムに情報選択メニューをスレッドグループを追加します。
-
ステップ2:以下のようにスレッドグループ作成したばかりの、情報選択メニューのサンプラーのHTTPリクエストを追加します。
-
ステップ3:HTTPリクエストを設定します
-
ステップ4:スレッドグループ情報の設定
-
ステップ5:保存したファイルのjmx
JMXファイルの準備ができているので、あなたがこの世代のXML形式に慣れていると思うが、また、直接、自然に次の形式のjmxファイルを生成するのviエディタをすることができます使用することができるならば、あなたはセットを見ることができますスレッドグループの所定数とサイクル数とHTTP要求が設定されているが、XML形式で格納されているJMX以下の文書があります。
liumiaocn:apache-jmeter-5.1.1 liumiao$ cat /tmp/jmeter-nongui-test.jmx
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.1.1 r1855137">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="测试计划" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.tearDown_on_shutdown">true</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">10</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">100</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<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">localhost</stringProp>
<stringProp name="HTTPSampler.port">8088</stringProp>
<stringProp name="HTTPSampler.protocol">http</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/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>
liumiaocn:apache-jmeter-5.1.1 liumiao$
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
圧力測定を実行し、レポートを生成します
コマンドを実行します。JMeterの-n -t [JMXファイル] -l [結果ファイル] -e -o [テストレポートカタログ]
上記のJMX入力ファイルでは、レポートを上記のJMeterの-nコマンドを実行すると発生、-tで指定されました:
liumiaocn:apache-jmeter-5.1.1 liumiao$ bin/jmeter -n -t /tmp/jmeter-nongui-test.jmx -l /tmp/result.jtl -e -o /tmp/jmeter-nongui-rpt
Creating summariser <summary>
Created the tree successfully using /tmp/jmeter-nongui-test.jmx
Starting the test @ Wed Oct 02 11:31:41 CST 2019 (1569987101117)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
summary = 1000 in 00:00:01 = 950.6/s Avg: 13 Min: 1 Max: 67 Err: 0 (0.00%)
Tidying up ... @ Wed Oct 02 11:31:42 CST 2019 (1569987102451)
... end of run
liumiaocn:apache-jmeter-5.1.1 liumiao$
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
結果が確認され
実際には、3つの第1およびビューの2地点の最後の2行を取得するために、チャートのすべての内容は、次のデータの視覚的な表現を見ることができますJTLこの単純なcsvファイルから、あなたはの実装に関する情報を見ることができます
liumiaocn:apache-jmeter-5.1.1 liumiao$ tail -n2 /tmp/result.jtl
1569987102446,2,HTTP请求,200,OK,线程组 1-100,text,true,,850,118,1,1,http://localhost:8088/,2,0,0
1569987102448,1,HTTP请求,200,OK,线程组 1-100,text,true,,850,118,1,1,http://localhost:8088/,1,0,0
liumiaocn:apache-jmeter-5.1.1 liumiao$
liumiaocn:apache-jmeter-5.1.1 liumiao$ head -n3 /tmp/result.jtl
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
1569987101523,67,HTTP请求,200,OK,线程组 1-1,text,true,,850,118,17,17,http://localhost:8088/,67,0,48
1569987101523,67,HTTP请求,200,OK,线程组 1-4,text,true,,850,118,17,17,http://localhost:8088/,67,0,49
liumiaocn:apache-jmeter-5.1.1 liumiao$
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
さらに、ビューの行の合計数からより明らかになるであろ1001(1,000 + 1の試験結果ヘッダ行)、さらに結果を含むであろう「真」は説明の残りのヘッダを除去した後、実行結果がOKであることを示しその結果、1000の正常と異常の結果が測定された圧力には表示されません、完成ラインです。
もちろん、生成されたレポートは、あなたがより直感的な圧力測定結果の要約情報を見ることができます