(1)Windows下以GUI的形式运行JMeter很简单,直接双击jmeter.bat文件即可,这是我们前面一直在做的事情。
但是在双击jmeter.bat启动JMeter时,会弹出如下命令行提示符,如下图所示:
这些英文是什么意思呢?翻译如下:
不要使用GUI模式进行负载测试,只用于测试创建和测试调试。对于负载测试,请使用非GUI模式:
命令如下:
jmeter -n -t [jmx file] -l[results file] -e -o[Path to web report folder]
增加Java堆以满足您的测试要求:在jmeter batch文件中修改当前环境变量 HEAP=”-Xms1g -Xmx1g -XX:MaxMetaspaceSize=256m”
请参考:https://jmeter.apache.org/usermanual/best-practices.html
关于修改Java堆的原因及方法,我们后续介绍,本篇呢,我们先来看看如何以非GUI模式运行JMeter
(1)使用“就meter -help”命名查看常用用法
E:\apache-jmeter-4.0\bin>jmeter -help
_ ____ _ ____ _ _ _____ _ __ __ _____ _____ _____ ____
/ \ | _ \ / \ / ___| | | | ____| | | \/ | ____|_ _| ____| _ \
/ _ \ | |_) / _ \| | | |_| | _| _ | | |\/| | _| | | | _| | |_) |
/ ___ \| __/ ___ \ |___| _ | |___ | |_| | | | | |___ | | | |___| _ <
/_/ \_\_| /_/ \_\____|_| |_|_____| \___/|_| |_|_____| |_| |_____|_| \_\ 4.0 r1823414
Copyright (c) 1999-2018 The Apache Software Foundation
//上面是版权信息
To list all command line options, open a command prompt and type:
//打开命令行窗口,输入下面的命令,可以查看所有命令选项
jmeter.bat(Windows)/jmeter.sh(Linux) -?
--------------------------------------------------
To run Apache JMeter in GUI mode, open a command prompt and type:
//如果想以GUI模式运行,使用下面的命令
jmeter.bat(Windows)/jmeter.sh(Linux) [-p property-file]
--------------------------------------------------
To run Apache JMeter in NON_GUI mode:
Open a command prompt (or Unix shell) and type:
//以非GUI模式运行,使用下面的命令
jmeter.bat(Windows)/jmeter.sh(Linux) -n -t test-file [-p property-file] [-l results-file] [-j log-file]
--------------------------------------------------
To run Apache JMeter in NON_GUI mode and generate a report at end :
Open a command prompt (or Unix shell) and type:
//如果在非GUI模式下运行JMeter,最后想生成一个报告的话,使用下面的命令
jmeter.bat(Windows)/jmeter.sh(Linux) -n -t test-file [-p property-file] [-l results-file] [-j log-file] -e -o [Path to output folder]
--------------------------------------------------
To generate a Report from existing CSV file:
Open a command prompt (or Unix shell) and type:
//从一个存在的CSV文件生成报告
jmeter.bat(Windows)/jmeter.sh(Linux) -g [csv results file] -o [path to output folder (empty or not existing)]
--------------------------------------------------
To tell Apache JMeter to use a proxy server:
Open a command prompt and type:
//JMeter使用代理服务器
jmeter.bat(Windows)/jmeter.sh(Linux) -H [your.proxy.server] -P [your proxy server port]
---------------------------------------------------
To run Apache JMeter in server mode:
Open a command prompt and type:
//JMeter以server模式运行
jmeter-server.bat(Windows)/jmeter-server(Linux)
---------------------------------------------------
(2)查看所有命令行参数
E:\apache-jmeter-4.0\bin>jmeter.bat -?
_ ____ _ ____ _ _ _____ _ __ __ _____ _____ _____ ____
/ \ | _ \ / \ / ___| | | | ____| | | \/ | ____|_ _| ____| _ \
/ _ \ | |_) / _ \| | | |_| | _| _ | | |\/| | _| | | | _| | |_) |
/ ___ \| __/ ___ \ |___| _ | |___ | |_| | | | | |___ | | | |___| _ <
/_/ \_\_| /_/ \_\____|_| |_|_____| \___/|_| |_|_____| |_| |_____|_| \_\ 4.0 r1823414
Copyright (c) 1999-2018 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
the jmeter property file to use
-q, --addprop
additional JMeter property file(s)
-t, --testfile
the jmeter test(.jmx) file to run. "-t LAST" will load last
used file
-l, --logfile
the file to log samples to
-i, --jmeterlogconf
jmeter logging configuration file (log4j2.xml)
-j, --jmeterlogfile
jmeter run log file (jmeter.log)
-n, --nongui
run JMeter in nongui mode
-s, --server
run the JMeter server
-H, --proxyHost
Set a proxy server for JMeter to use
-P, --proxyPort
Set proxy server port for JMeter to use
-N, --nonProxyHosts
Set nonproxy host list (e.g. *.apache.org|localhost)
-u, --username
Set username for proxy server that JMeter is to use
-a, --password
Set password for proxy server that JMeter is to use
-J, --jmeterproperty =
Define additional JMeter properties
-G, --globalproperty =
Define Global properties (sent to servers)
e.g. -Gport=123
or -Gglobal.properties
-D, --systemproperty =
Define additional system properties
-S, --systemPropertyFile
additional system property file(s)
-f, --forceDeleteResultFile
force delete existing results files before start the test
-L, --loglevel =
[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
Start these remote servers (overrides remote_hosts)
-d, --homedir
the jmeter home directory to use
-X, --remoteexit
Exit the remote servers at end of test (non-GUI)
-g, --reportonly
generate report dashboard only, from a test results file
-e, --reportatendofloadtests
generate report dashboard after load test
-o, --reportoutputfolder
output folder for report dashboard
(3)JMeter环境变量
顺便解决个问题。如果你打开命令行窗口,直接运行上面的命令,应该会报找不到JMeter的错误,这是因为没有配置环境变量。因为我Windows下面一般双击jmeter.bat文件运行GUI模式,所以一直没配置JMeter的环境变量,要想用JMeter命令的话,可以先cd到jmeter的安装目录的bin目录下面,执行上面的命令就可以了。如果觉得麻烦,那就看看下面的步骤,配置下环境变量
然后重启命令行窗口,即可直接执行jmeter命令。
(4)执行一个最简单的命令
C:\Users\admin>jmeter.bat -n -t E:\Script.jmx -l E:\res.jtl
Creating summariser
Created the tree successfully using E:\Script.jmx
Starting the test @ Tue Mar 20 16:52:12 CST 2018 (1521535932191)
Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
summary = 20 in 00:00:14 = 1.4/s Avg: 3054 Min: 37 Max: 6736 Err: 0 (0.00%)
Tidying up ... @ Tue Mar 20 16:52:27 CST 2018 (1521535947734)
... end of run
打开terminal,进入到bin目录,直接输入命令 sh jmeter即可
或者双击jmeter.sh
命令一致
(1)下载JMeter的tgz包
wget http://mirrors.tuna.tsinghua.edu.cn/apache//jmeter/binaries/apache-jmeter-4.0.tgz
(2)解压缩
[root@Beta-nginx bin]# gunzip apache-jmeter-4.0.tgz
[root@Beta-nginx bin]# tar -xvf apache-jmeter-4.0.tar
(3)运行
jmeter.sh -n -t /test-file/Script.jmx -l ./res-linux.jtl
在使用Jmeter进行性能测试时,如果要求并发比较大,单台电脑的配置(CPU、内存)可能无法支持,这就可以使用JMeter分布式测试。
(1)分布式测试原理
(2)执行机(slave)的配置,我们称之为server
(3)控制机(master)的配置,我们称之为client
从JMeter 4.0开始,需要生成rmi_keystore.jks文件,最简单的方法是,windows下双击bin目录下的create-rmi-keystore.bat文件,即可。然后将该文件上传到server端的bin目录下。
(4)在server端,启动jmeter-server.bat(或者jmeter-server)
(5)在client端,启动jmeter
(6)通过client,连接启动server机
注:分布式部署遇到了一些问题,稍后整理完,更新本篇博客。