Jmeter (38) - From entry to advanced level - Detailed explanation of running JMeter from the command line (detailed tutorial)

1 Introduction

  A previous article introduced how to generate a test report. Careful friends or classmates can see that Hong Ge does not start Jmeter to generate a test report on the gui page. Instead, he uses the command line to generate the test report after setting and saving it on the gui page. Test report. In this article, Brother Hong will introduce in detail why the command line is used instead of the GUI, and the meaning of some parameters at startup.

2. Why do we need to execute the script from the command line?

  This article introduces how to run JMeter from the command line. Let's first talk about why we need to execute the script from the command line. During daily testing, we found that when a large number of concurrencies occur, the jmeterGUI interface will be down and stuck for a long time. In this case We need to use the command line to execute the script (non-GUI is also called no Mode). Using non-GUI mode, that is, command line mode to run the JMeter test script can greatly reduce the required system resources. There are mainly three points:

1) The graphical interface consumes more resources, such as CPU and memory, which can easily cause the press to reach a bottleneck, thus affecting the test results.

2) The graphical interface does not support large-scale load tests and performance tests. When concurrency is large, jmeter will crash.

3) Command line testing supports continuous integration. The command line method can configure scripts to Jenkins to implement continuous integration and create automated tests. For example, put it on a CI tool like Jenkins.

3. Specific steps

This is mainly for children or friends who do not know how to code scripts. They can first debug the script successfully on the graphical interface, and then run the script in non-GUI mode, also called no Mode.

1. Open the JMeter graphical interface by double-clicking jmeter.bat

2. Create a Thread Group on the default Test Plan

3. Add a Sampler to the Thread Group and select HTTP Request

4. Add a View Results Tree above the Thread Group

5. Click Run, a pop-up dialog box will ask whether to save, click Yes, save the script to the desktop, Test Plant And Report.jmx

6. Check whether the response code in the View Results Tree is 200.

7. If the test passes, it means that there is no problem with the test script. We choose to delete the View Results Tree here.

8. Close the current JMeter dialog box

9. Open cmd and switch to the JMeter installation path through the cd command.

For example: cd C:\apache-jmeter-3.2\bin

10. Enter the command to start executing the test

If you want to learn automated testing, I recommend a set of videos to you. This video can be said to be the number one automated testing tutorial on the entire network played by Bilibili. The number of people online at the same time has reached 1,000, and there are also notes that can be collected and communicated with various channels. Master technical communication: 798478386   

[Updated] A complete collection of the most detailed practical tutorials on Python interface automation testing taught by Bilibili (the latest practical version)_bilibili_bilibili [Updated] A complete collection of the most detailed practical tutorials on Python interface automated testing taught by Bilibili (practical version) The latest version) has a total of 200 videos, including: 1. Why interface automation should be done for interface automation, 2. Overall view of request for interface automation, 3. Interface practice for interface automation, etc. For more exciting videos from UP master, please follow the UP account . icon-default.png?t=N7T8https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337

 Description of the content in the red box in the picture above: 

summary =  60 in 00:00:05:在5秒内产生的总请求数是60个,其中的时间段是从脚本运行开始计算到当前时间为止,一般在脚本运行过程中主要关注 “summary=” 信息即可

11.8/s:系统每秒处理的请求数,相当于TPS

Avg:   83:平均响应时间

Min:   43:最小响应时间

Max:  248:最大响应时间

Err:     0 (0.00%):错误数/率

Active: 100:活动的线程数

4. Command line parameters

4.1 Common formats for running commands

jmeter -n -t [jmx script path] -l [test output file path]

Parameter explanation:

-n: 表示 non gui mode,就是非图形化模式
 
-t: 即testplan,后跟要运行的jmeter脚本的路径和脚本名称。
 
    若指定路径下没有指定名称的脚本,则自动创建。
 
    若没有路径只写脚本名称,则默认是在当前目录查找或创建。
 
-l: 后跟输出结果文件路径和结果文件名称。
 
    若指定路径下没有指定名称的脚本,则自动创建,可以生成csv或者jtl文件。
    
    若只写脚本名称,则默认是在当前目录查找或创建。
 
示例:jmeter -n -t testplan.jmx -l test.jtl
 
示例含义:以命令行模式运行当前目录下的testplan.jmx文件,并在当前目录下输出日志文件test.jtl

Other parameters:

jmeter -n -t test.jmx -R 10.6.5.31,10.6.5.32 -l log.jtl

jmeter -n -t test.jmx -l  log.jtl -H 192.168.1.1 -P 8080
 
-r/R 远程执行 -> 启动远程服务,即分布式执行多台压力机
 
-H 代理主机 -> 设置 JMeter 使用的代理主机
  
-P 代理端口 -> 设置 JMeter 使用的代理主机的端口号
 
使用-R指定节点时,要首先在这些节点上启动jmeter-server的服务

Test Results:

A html.cvs file will be generated on the desktop. This file has exactly 60 lines and the content is as follows:

picture

5.Linux system runs jmeter command line

Copy the edited script to Linux

1. Use the command to execute the script:

jmeter -n -t bugfree-create.jmx -l test.jtl 

Note: If the environment variable of Jmeter is not set, you need to check whether the current directory is under the bin directory of jmetet when executing the script.

Operation diagram:

2. View the running results

(1) Move the test.jtl file generated by running the script to the windows system (note: Jmeter and JDK installed under windows must be consistent with Linux)

(2) Open Jmeter under the windows system, create a thread group, and add a listener under the thread group, as shown below:

 (3) Click the browse button on the interface and add the files everywhere to see the script test report, as shown below:

6. Run jmeter command line under windows system

Running the command line under Windows is the same as under Linux, except that it is run through the cmd command line tool. Moreover, the previous article introduced by Brother Hong was about running the Jmeter command line under windows. Brother Hong will not go into details here.

7. Summary

When using jmeter for stress testing, a memory overflow outfmenmory error was reported after a period of time, causing jmeter to freeze. First, try adding JVM_ARGS="-Xmx2048m -Xms2048m -Xmn256m -XX:PermSize=128m -Xss256k" in jmeter.bat. , but as a result, the running time increased, but eventually a memory overflow was reported. After Baidu changed the following settings according to the suggestions of netizens, jmeter no longer stuck:

1. In Windows environment, modify jmeter.bat :

set HEAP=-Xms256m -Xmx256m
set NEW=-XX:NewSize=128m -XX:MaxNewSize=128m
改为:
set HEAP=-Xms256m -Xmx1024m
set NEW=-XX:NewSize=128m -XX:MaxNewSize=512m

According to experience , the heap is set to at most half of the physical memory, and the default setting is 512M. If the heap exceeds half of the physical memory, jmeter may run slowly, or even memory overflow occurs, because java consumes more memory and takes up more CPU.

Note: Xmx of JDK32-bit computer cannot exceed 1500m, the maximum is 1378m. Otherwise, an error will be reported when starting Jmeter:

2. In Linux environment, modify jmeter.sh:

java $JVM_ARGS -Xms1G -Xmx5G -XX:MaxPermSize=512m -Dapple.laf.useScreenMenuBar=true -jar `dirname $0`/ApacheJMeter.jar "$@"

3. If you check the number of JDK bits

# java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Server VM (build 20.1-b02, mixed mode)

如果是64位的话,最后一行会显示64-Bit
#java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

8.Expand

8.1 Modify configuration file

If this is the first time you use the command line to execute a test script, the output you see may be similar to the following:

picture

This information only tells us that the execution was successful. But I want to see more results from this test, what should I do? This can be solved by modifying the jmeter.properties configuration file:


#---------------------------------------------------------------------------
# Results file configuration
#---------------------------------------------------------------------------

# This section helps determine how result data will be saved.
# The commented out values are the defaults.

# legitimate values: xml, csv, db.  Only xml and csv are currently supported.
#jmeter.save.saveservice.output_format=csv

# The below properties are true when field should be saved; false otherwise
#
# assertion_results_failure_message only affects CSV output
#jmeter.save.saveservice.assertion_results_failure_message=true
#
# legitimate values: none, first, all
#jmeter.save.saveservice.assertion_results=none
#
#jmeter.save.saveservice.data_type=true
#jmeter.save.saveservice.label=true
#jmeter.save.saveservice.response_code=true
# response_data is not currently supported for CSV output
#jmeter.save.saveservice.response_data=false
# Save ResponseData for failed samples
#jmeter.save.saveservice.response_data.on_error=false
#jmeter.save.saveservice.response_message=true
#jmeter.save.saveservice.successful=true
#jmeter.save.saveservice.thread_name=true
#jmeter.save.saveservice.time=true
#jmeter.save.saveservice.subresults=true
#jmeter.save.saveservice.assertions=true
#jmeter.save.saveservice.latency=true
# Only available with HttpClient4
#jmeter.save.saveservice.connect_time=true
#jmeter.save.saveservice.samplerData=false
#jmeter.save.saveservice.responseHeaders=false
#jmeter.save.saveservice.requestHeaders=false
#jmeter.save.saveservice.encoding=false
#jmeter.save.saveservice.bytes=true
# Only available with HttpClient4
#jmeter.save.saveservice.sent_bytes=true
#jmeter.save.saveservice.url=true
#jmeter.save.saveservice.filename=false
#jmeter.save.saveservice.hostname=false
#jmeter.save.saveservice.thread_counts=true
#jmeter.save.saveservice.sample_count=false
#jmeter.save.saveservice.idle_time=true

# Timestamp format - this only affects CSV output files
# legitimate values: none, ms, or a format suitable for SimpleDateFormat
#jmeter.save.saveservice.timestamp_format=ms
#jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSS

# For use with Comma-separated value (CSV) files or other formats
# where the fields' values are separated by specified delimiters.
# Default:
#jmeter.save.saveservice.default_delimiter=,
# For TAB, one can use:
#jmeter.save.saveservice.default_delimiter=\t

# Only applies to CSV format files:
# Print field names as first line in CSV
#jmeter.save.saveservice.print_field_names=true

# Optional list of JMeter variable names whose values are to be saved in the result data files.
# Use commas to separate the names. For example:
#sample_variables=SESSION_ID,REFERENCE
# N.B. The current implementation saves the values in XML as attributes,
# so the names must be valid XML names.
# By default JMeter sends the variable to all servers
# to ensure that the correct data is available at the client.

# Optional xml processing instruction for line 2 of the file:
# Example:
#jmeter.save.saveservice.xml_pi=<?xml-stylesheet type="text/xsl" href="../extras/jmeter-results-detail-report.xsl"?>
# Default value:
#jmeter.save.saveservice.xml_pi=

# Prefix used to identify filenames that are relative to the current base
#jmeter.save.saveservice.base_prefix=~/

# AutoFlush on each line written in XML or CSV output
# Setting this to true will result in less test results data loss in case of Crash
# but with impact on performances, particularly for intensive tests (low or no pauses)
# Since JMeter 2.10, this is false by default
#jmeter.save.saveservice.autoflush=false
将上面的内容复制到user.properties文件中,然后注释打开,并且值修改成true,就会打开该条记录,jmeter就会将对应的信息输出到我们指定的jtl文件中(不过这样会在压测过程中产生大量的日志文件,真正压测时,最好不要开太多的日志记录),然后可以在结果文件中查看详细的信息。但是我们想在脚本执行的过程中实时查看结果信息,要怎么做呢?同样是将jmeter.properties文件中一下内容复制到user.properties文件中修改配置文件jmeter.properties。
#---------------------------------------------------------------------------
# Summariser - Generate Summary Results - configuration (mainly applies to non-GUI mode)
#---------------------------------------------------------------------------
#
# Comment the following property to disable the default non-GUI summariser
# [or change the value to rename it]
# (applies to non-GUI mode only)
summariser.name=summary
#
# interval between summaries (in seconds) default 30 seconds
#summariser.interval=30
#
# Write messages to log file
#summariser.log=true
#
# Write messages to System.out
#summariser.out=true

# Ignore SampleResults generated by TransactionControllers
# defaults to true
#summariser.ignore_transaction_controller_sample_result=true

 

Open the above three configuration items summariser.name, summariser.interval, summariser.out, save and re-run jmeter. You should be able to see the statistical information in the shell, as shown in the following figure:

Note: If the environment variable of Jmeter is not set, you need to check whether the current directory is under the bin directory of jmetet when executing the script.

Remote engines have been started
    Waiting for possible shutdown message on port 4445
    summary +   3036 in     3s = 1001.6/s Avg:    25 Min:    14 Max:    58 Err:  3036 (100.00%) Active: 61 Started: 58 Finished: 0
    summary +  25670 in  10.3s = 2494.7/s Avg:    61 Min:    11 Max:   190 Err: 25670 (100.00%) Active: 261 Started: 258 Finished: 0
    summary =  28706 in  13.1s = 2192.0/s Avg:    57 Min:    11 Max:   190 Err: 28706 (100.00%)
    summary +  27300 in  10.3s = 2654.9/s Avg:   129 Min:    10 Max:   407 Err: 27300 (100.00%) Active: 461 Started: 458 Finished: 0
    summary =  56006 in  23.1s = 2426.7/s Avg:    92 Min:    10 Max:   407 Err: 56006 (100.00%)
    summary +  27200 in  10.4s = 2606.1/s Avg:   202 Min:    10 Max:   528 Err: 27200 (100.00%) Active: 660 Started: 657 Finished: 0
    summary =  83206 in  33.1s = 2512.8/s Avg:   128 Min:    10 Max:   528 Err: 83206 (100.00%)
    summary +  26300 in    11s = 2478.3/s Avg:   284 Min:    11 Max:   702 Err: 26300 (100.00%) Active: 861 Started: 858 Finished: 0
    summary = 109506 in  43.1s = 2541.1/s Avg:   166 Min:    10 Max:   702 Err: 109506 (100.00%)
    summary +  26200 in    11s = 2439.0/s Avg:   355 Min:    10 Max:   866 Err: 26200 (100.00%) Active: 1000 Started: 997 Finished: 0
    summary = 135706 in  53.1s = 2556.0/s Avg:   202 Min:    10 Max:   866 Err: 135706 (100.00%)

The error rate here is 100%, which should be 0% under normal circumstances.

The information displayed here is equivalent to the information displayed by the aggregation report component under the GUI interface. There are two main types of information: summary + and summary =, and other items are similar.

summary +   4386 in 00:00:30:在30秒内增加了4386个请求,其中时间间隔由配置文件中的interval统计频率的值决定

summary =  27455 in 00:03:12:在3分12秒内产生的总请求数是27455个,其中的时间段是从脚本运行开始计算到当前时间为止,一般在脚本运行过程中主要关注 “summary=” 信息即可

146.2/s:系统每秒处理的请求数,相当于TPS

Avg:   684:平均响应时间

Min:   201:最小响应时间

Max:  1499:最大响应时间

Err:     0 (0.00%):错误数/率

Active: 100:活动的线程数

 

8.2 File path

1. File path in command line

Example: jmeter -n -t testplan.jmx -l test.jtl

By default, JMeter searches for script files in the current directory and records logs in the current directory. For example, if you execute the above command in the C:\tools\apache-jmeter-3.0\bin directory, JMeter will look for the test.jmx script in this directory and put the execution results in this directory. If your script is in another directory and you want to put the execution results in another folder, you need to tell JMeter using the absolute path, for example:

C:\tools\apache-jmeter-3.0\bin>jmeter -n -t e:\addCustomer.jmx -l e:\addCustomer.jtl

Guess you like

Origin blog.csdn.net/Faith_Lzt/article/details/132791470