(15 | JMeter场景运行)
- JMeter场景运行分两种方式,为GUI(运行界面)方式、命令窗口方式;
- 而基于运行架构分本地化运行、远程运行。
1 GUI运行
1.1 本地化运行
- 
即运行本地一台JMeter机器,所有的请求从一台机器发出; 
- 
如下是本地一个测试计划:  
- 
运行前快捷菜单如下:  
- 
本地点击  ,运行后菜单栏如下,点击stop可以停止运行: ,运行后菜单栏如下,点击stop可以停止运行:

- 另外如下图显示,0代表没有线程异常,0/50中分子代表当前运行的线程为0,总共50个线程;
 
1.2 远程运行
1.2.1 简单概述
- 是用一台JMeter控制机(Master)控制远程的多台机器(Slave)来产生负载;
- Master与Slave的通信是通过RMI方式完成;
- Slave上运行Agent程序(启动命名为%JAVA_HOME%\bin\jmeter-server.bat);
- Master上运行远程负载机。
1.2.2 详细说明
- 在%JAVA_HOME%\bin下找到ApacheJMeter.jar与jmeter-server.bat;
- 运行jmeter-server.bat来启动Agent,Agent程序由ApacheJMeter.jar中的程序来实现;
- 在连接远程远程机器之前,先要进行配置,告诉JMeter要连接哪些机器;
- 可打开jmeter.properties,搜索remote_hosts,找到如下内容:
#---------------------------------------------------------------------------
# Remote hosts and RMI configuration
#---------------------------------------------------------------------------
# Remote Hosts - comma delimited
remote_hosts=127.0.0.1
#remote_hosts=localhost:1099,localhost:2010
# RMI port to be used by the server (must start rmiregistry with same port)
#server_port=1099
- 在remote_hosts=后加上远程JMeter负载机的IP即可,多个IP用逗号隔开(重启JMeter才会生效该配置文件);
- 远程运行的脚本若有参数化文件,脚本有依赖包时,需要把这些参数文件、依赖包拷贝到远程机器上。
2 非GUI运行
2.1 概述
- 非GUI方式运行时没有JMeter界面,在命令行窗口通过命令实现;
- 使用此运行方式的原因是:
因为JMeter可视化界面及监听器动态展示结果比较消耗负载机资源,在打并发情况下GUI方式会导致负载机资源紧张,会对性能测试结果造成影响。
2.2 运行方式
# 1:
java -jar %JAVA_HOME%\bin\ApacheJMeter.jar -n -t %JAVA_HOME%\script\xx.jmx -r -l result.jtl
# 2:
%JAVA_HOME%\bin\jmeter -n -t %JAVA_HOME%\script\xx.jmx -l %JAVA_HOME%\result\result.jtl
2.3 运行参数
2.3.1 参数查看
- 使用jmeter.bat -?查看参数说明:
C:\Users\Administrator>jmeter.bat -?
    _    ____   _    ____ _   _ _____       _ __  __ _____ _____ _____ ____
   / \  |  _ \ / \  / ___| | | | ____|     | |  \/  | ____|_   _| ____|  _ \
  / _ \ | |_) / _ \| |   | |_| |  _|    _  | | |\/| |  _|   | | |  _| | |_) |
 / ___ \|  __/ ___ \ |___|  _  | |___  | |_| | |  | | |___  | | | |___|  _ <
/_/   \_\_| /_/   \_\____|_| |_|_____|  \___/|_|  |_|_____| |_| |_____|_| \_\ 5.3
Copyright (c) 1999-2020 The Apache Software Foundation
        --?
                print command line options and exit
        -h, --help
                print usage information and exit
        -v, --version
                print the version information and exit
        -p, --propfile <argument>
                the jmeter property file to use
        -q, --addprop <argument>
                additional JMeter property file(s)
        -t, --testfile <argument>
                the jmeter test(.jmx) file to run. "-t LAST" will load last
                used file
        -l, --logfile <argument>
                the file to log samples to
        -i, --jmeterlogconf <argument>
                jmeter logging configuration file (log4j2.xml)
        -j, --jmeterlogfile <argument>
                jmeter run log file (jmeter.log)
        -n, --nongui
                run JMeter in nongui mode
        -s, --server
                run the JMeter server
        -E, --proxyScheme <argument>
                Set a proxy scheme to use for the proxy server
        -H, --proxyHost <argument>
                Set a proxy server for JMeter to use
        -P, --proxyPort <argument>
                Set proxy server port for JMeter to use
        -N, --nonProxyHosts <argument>
                Set nonproxy host list (e.g. *.apache.org|localhost)
        -u, --username <argument>
                Set username for proxy server that JMeter is to use
        -a, --password <argument>
                Set password for proxy server that JMeter is to use
        -J, --jmeterproperty <argument>=<value>
                Define additional JMeter properties
        -G, --globalproperty <argument>=<value>
                Define Global properties (sent to servers)
                e.g. -Gport=123
                 or -Gglobal.properties
        -D, --systemproperty <argument>=<value>
                Define additional system properties
        -S, --systemPropertyFile <argument>
                additional system property file(s)
        -f, --forceDeleteResultFile
                force delete existing results files and web report folder if
                 present before starting the test
        -L, --loglevel <argument>=<value>
                [category=]level e.g. jorphan=INFO, jmeter.util=DEBUG or com
                .example.foo=WARN
        -r, --runremote
                Start remote servers (as defined in remote_hosts)
        -R, --remotestart <argument>
                Start these remote servers (overrides remote_hosts)
        -d, --homedir <argument>
                the jmeter home directory to use
        -X, --remoteexit
                Exit the remote servers at end of test (non-GUI)
        -g, --reportonly <argument>
                generate report dashboard only, from a test results file
        -e, --reportatendofloadtests
                generate report dashboard after load test
        -o, --reportoutputfolder <argument>
                output folder for report dashboard
2.3.2 部分参数说明
| 参数 | 说明 | 
|---|---|
| -n | 非GUI方式运行 | 
| -t | 指定运行的测试脚本地址和名称 | 
| -h | 查看帮助 | 
| -v | 查看版本 | 
| -p | 指定读取JMeter属性文件 | 
| -l | 记录测试结果到文件,指定文件地址和名称 | 
| -s | 以服务器方式运行,即远程方式 | 
| -H | 设置代理,一般写代理IP | 
| -P | 设置代理端口 | 
| -u | 代理账号 | 
| -a | 代理口令 | 
| -J | 定义JMeter属性 ,等同 jmeter.properties | 
| -G | 定义JMeter全局属性 ,等同 Global.properties | 
| -D | 定义系统属性,指定加载系统属性文件 | 
| -L | 定义JMeter日志级别 | 
| -r | 开启远程负载机 ,机器列表在 jmeter.properties中指定 | 
| -R | 开启远程负载机,可指定负载机IP | 
| -d | 指定JMeter Home目录 | 
| -X | 停止远程执行 | 










