Stress test tool Apache JMeter: pressure sensing mode in non-GUI mode: 7

Original: stress test tool Apache JMeter: 7: pressure sensing mode in non-GUI mode

Here Insert Picture Description
Apache JMeter is a pure Java open-source software for load testing or performance testing. Operation described in the preceding sheet of paper is performed by using the visual page JMeter, likewise stress test article for testing for Web application, for example, describes a method of non-graphically the measured pressure.

Preparing the Environment

Apache JMeter overview on the method of installation, the following can be found:

  • https://liumiaocn.blog.csdn.net/article/details/101264380

JMeter non-GUI mode

jmeter specified by -n non-GUI mode by default starts JMeter GUI interface, but when you start is also accompanied by the following information:

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 mode vs non-GUI mode

When using the GUI mode, and when using a non-GUI mode?
The Attention has been very clear, do not use the GUI mode for load testing! Only in testing or debugging test set or when it is used to generate GUI mode.

How to use the non-GUI mode

And using the command parameters as follows:

Execute the command: jmeter -n -t [jmx file] -l [results file] -e -o [test report catalog]

Examples of Use

Stress test application ready

In use port 8088 starts a Docker application Nginx local machine (in other ways may also be used), example is shown below:

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

Use the curl command or direct the browser to confirm nginx has been running

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

Document preparation jmx

In the command-line non-GUI mode in JMeter, jmx files store information thread group setting and testing, pressure measurement is input information, and generate jmx file can be generated using the GUI interface, because the format is xml file jmx , once familiar can also be edited directly generate.

Use the following steps to prepare test to verify the premise of preparation:

  • Step 1: Add a thread group in the test program, the information selection menu as shown below:
    Here Insert Picture Description

  • Step 2: Add a sampler HTTP request on a thread group just created, the information selection menu as shown below:
    Here Insert Picture Description

  • Step 3: Set the HTTP request
    Here Insert Picture Description

  • Step 4: Thread group information setting
    Here Insert Picture Description

  • Step 5: Save the resulting file jmx
    Here Insert Picture Description
    so jmx file is ready, if you think you're more familiar with xml format of this generation, but also can directly use the vi editor to generate the following format jmx file naturally can, you can see the set a given number of thread groups and the number of cycles and the HTTP request is set, there are the following documents jmx stored in an XML format.

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

Performing pressure measurements and generate reports

Execute the command: jmeter -n -t [jmx file] -l [results file] -e -o [test report catalog]

In the above-described jmx input file, specified by -t, performing the above-described jmeter -n command and generate reports:

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

The results confirmed

In fact, from jtl this simple csv file, which can see a visual representation of all the contents of the chart, the following data to obtain the first three and last two lines of the 2 point of view, you can see information about the implementation of

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

Further will be more apparent from the total number of lines of view, is 1001 (1000 + 1 test results header rows), further comprising a results ', true,' it indicates that the execution result is OK after the removal of remaining header described results are finished line 1000 normal and abnormal results do not appear in the measured pressure.
Of course, the generated report, you can see the summary information of the pressure measurement result more intuitive
Here Insert Picture Description

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12205364.html