下载jmeter 传送门

修改配置,建议设置英文

cd apache-jmeter-5.5/bin
vim jmeter.properties
#编码格式为UTF-8
sampleresult.default.encoding=UTF-8
#设置为英文,我这里就默认为英文了
language=en
#设置为中文
#language=zh_CN

apache-jmeter-5.5版本默认最大堆是1G,所以一般来说也是够我们测试了

启动jemeter

打开终端

./jmeter
================================================================================
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
================================================================================
Warning: the font "Times" is not available, so "Lucida Bright" has been substituted, but may have unexpected appearance or behavor. Re-enable the "Times" font to remove this warning.

官方推荐使用CLI.

GUI模式比较适用于测试创建和测试调试;负载测试时,最好是使用CLI
CLI模式能大大缩减所需要的系统资源;
GUI模式,会会消耗大量的内存资源,容易使压力机本身达到瓶颈,从而影响测试结果(例如:查看结果树,会依次把每条请求的结果写入内存,降低性能);
GUI模式,不能支持大型的负载测试与性能测试,并发超大时,JMeter会崩溃;
使用CLI模式执行可以进行自动化脚本编写,并持续集成到Jinkens上自动运行。

我们可以通过简单的GUI来配置我们的接口
image-1658931905042
image-1658931919795
我这里是开300个线程连续压测30秒
最后我们保存该配置到某个文件夹,文件后缀为.jmx

打开终端,进入jmeter目录

wangjin@wangjindembp bin % ./jmeter -n -t /Users/wangjin/test.jmx -l /Users/wangjin/test/results.jtl -e -o /Users/wangjin/test/web_report
Creating summariser <summary>
Created the tree successfully using /Users/wangjin/test.jmx
Starting standalone test @ July 27, 2022 10:26:59 PM CST (1658932019011)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
summary +   1193 in 00:00:01 = 1841.0/s Avg:    40 Min:     0 Max:   425 Err:     0 (0.00%) Active: 199 Started: 199 Finished: 0
summary + 209821 in 00:00:30 = 6994.0/s Avg:    41 Min:     0 Max:   601 Err:     0 (0.00%) Active: 81 Started: 300 Finished: 219
summary = 211014 in 00:00:31 = 6885.1/s Avg:    41 Min:     0 Max:   601 Err:     0 (0.00%)
summary +   5964 in 00:00:01 = 7685.6/s Avg:     3 Min:     0 Max:    27 Err:     0 (0.00%) Active: 0 Started: 300 Finished: 300
summary = 216978 in 00:00:31 = 6904.6/s Avg:    40 Min:     0 Max:   601 Err:     0 (0.00%)
Tidying up ...    @ July 27, 2022 10:27:30 PM CST (1658932050777)
... end of run

等待执行完成后,我们从web_report中打开网页报告index.html

APDEX 0-1的范围,越接近1越完美
image-1658932413436
image-1658932443696

参数介绍


Usage
		--?
                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

执行计划(.jmx)并且生成报告(.jtl)和HTML报告

 ./jmeter -n -t /Users/wangjin/test.jmx -l /Users/wangjin/test/results.jtl -e -o /Users/wangjin/test/web_report
# -t后面是你保存的jmeter文件,一般是以.jmx结尾的
# -l 是你压测的接口结果,一般是以.jtl结尾,该文件可以通过gui查看
# -o 后面跟的是网页版本的报告目录

执行计划(.jmx)只生成报告(.jtl)

 ./jmeter -n -t /Users/wangjin/test.jmx -l /Users/wangjin/test/results.jtl
# -t后面是你保存的jmeter文件,一般是以.jmx结尾的
# -l 是你压测的接口结果,一般是以.jtl结尾,该文件可以通过gui查看

通过报告(.jtl)生成HTML报告

 ./jmeter -g /Users/wangjin/test/results.jtl -o /Users/wangjin/test/web_report
# -t后面是你保存的jmeter文件,一般是以.jmx结尾的
# -l 是你压测的接口结果,一般是以.jtl结尾,该文件可以通过gui查看
打赏
支付宝 微信
下一篇