- 性能測試計划
- 性能測試用例
- 錄制腳本
- 性能測試結果
- 性能測試報告
- 性能測試監控報告
准備工作
- 從腳本已錄制成功之后開始進行壓測
- 安裝Jmeter拓展插件 查看 Transactions per Second https://jmeter-plugins.org/wiki/TransactionsPerSecond/ ←插件地址
- 在壓測前先安裝 Nmon監控工具在服務器linux性能監控分析及通過nmon_analyse生成分析報表
PS :安裝 TPS教程
解壓安裝
將 jpgc-graphs-basic-2.0.zip 解壓縮后只有一個 lib 目錄,該目錄下有一個 ext 文件夾和一個 jmeter-plugins-cmn-jmeter-0.3.jar 包,ext 文件夾中有 jmeter-plugins-graphs-basic-2.0.jar 和 jmeter-plugins-manager-0.10.jar 包。將 lib 目錄下的 jmeter-plugins-cmn-jmeter-0.3.jar 拷貝到 %JMeter%/lib 目錄下,將 ext 目錄下的 jmeter-plugins-graphs-basic-2.0.jar 和 jmeter-plugins-manager-0.10.jar 拷貝到 %JMeter%/lib/ext 目錄下,重啟 JMeter,發現已經支持 TPS、TRT 等視圖了:

TPS導入解析測試報告
導入之后就可以看到 TPS數據了
取至Jmeter官方文檔
1.0.2 Load Test running
Once your Test Plan is ready, you can start your Load Test. The first step is to configure the injectors that will run JMeter, this as for any other Load Testing tool includes:
- Correct machine sizing in terms of CPU, memory and network
- OS Tuning
- Java setup: Ensure you install the latest version of Java supported by JMeter
- Correct sizing of Java Heap. By default JMeter runs with a heap of 512MB, this might not be enough for your test and depends on your test plan and number of threads you want to run
Don't run load test using GUI mode !
不要使用GUI模式運行負載測試!因為GUI模式的話會占用比較大的內存空間,並發數量上不去等等的問題
You can also have real-time results during your test using Backend Listener.
NON-GUI模式允許得到結果后可以在后端監聽器的測試期間獲得實時結果。這句話如何理解呢,見上面“TPS導入解析測試報告”
Running JMeter
To run Apache JMeter in NON_GUI
直接進入腳本路徑,輸入 Jmeter的啟動路徑
可以查看到Jmeter的相關命令幫助
小七的Jmeter路徑是安裝在D:\Jmeter\jmeter-3.1 所以直接進入bin目錄下 找到jmeter 查看H幫助文檔
C:\Users\lamw\Desktop\lamw
λ D:\Jmeter\jmeter-3.1\bin\jmeter -h
Writing log file to: C:\Users\lamw\Desktop\lamw\jmeter.log
_ ____ _ ____ _ _ _____ _ __ __ _____ _____ _____ ____ / \ | _ \ / \ / ___| | | | ____| | | \/ | ____|_ _| ____| _ \ / _ \ | |_) / _ \| | | |_| | _| _ | | |\/| | _| | | | _| | |_) | / ___ \| __/ ___ \ |___| _ | |___ | |_| | | | | |___ | | | |___| _ < /_/ \_\_| /_/ \_\____|_| |_|_____| \___/|_| |_|_____| |_| |_____|_| \_\ 3.1 r1770033
Copyright (c) 1999-2016 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:
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:
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:
jmeter.bat(Windows)/jmeter.sh(Linux) -n -t test-file [-p property-file] [-l results-file] [-j log-file] -e -o [Path to o
utput folder]
--------------------------------------------------
To generate a Report from existing CSV file:
Open a command prompt (or Unix shell) and type:
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.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.bat(Windows)/jmeter-server(Linux)
---------------------------------------------------
上面包含了一些參數 可以輸入 -l 查看
C:\Users\lamw\Desktop\lamw λ D:\Jmeter\jmeter-3.1\bin\jmeter -l 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 -l, --logfile <argument> the file to log samples to -j, --jmeterlogfile <argument> jmeter run log file (jmeter.log) -n, --nongui run JMeter in nongui mode -s, --server run the JMeter 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) -L, --loglevel <argument>=<value> [category=]level e.g. jorphan=INFO or jmeter.util=DEBUG -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
下面我們就采用 NON_GUI模式執行腳本 如下:
-------------------------------------------------- To run Apache JMeter in NON_GUI mode and generate a report at end : Open a command prompt (or Unix shell) and type: jmeter.bat(Windows)/jmeter.sh(Linux) -n -t test-file [-p property-file] [-l results-file] [-j log-file] -e -o [Path to o utput folder] --------------------------------------------------
輸入以下命令直接執行錄制好的腳本文件
C:\Users\lamw\Desktop\lamw λ D:\Jmeter\jmeter-3.1\bin\jmeter.bat -n -t test.jmx -l test_report_01.csv -e -o test_report_01
命令解析:
C:\Users\lamw\Desktop\lamw 這個是測試腳本所在的文件目錄

D:\Jmeter\jmeter-3.1\bin\jmeter.bat --------Jmeter.bat 的執行路徑
-n, --nongui -------------以nongui模式執行
run JMeter in nongui mode
-t, --testfile <argument>-------------壓測腳本文件jmx
the jmeter test(.jmx) file to run
-l, --logfile <argument>-------------將樣本記錄到的文件
the file to log samples to
-e, --reportatendofloadtests------------ 在加載測試后生成報告儀表板
generate report dashboard after load test
-o, --reportoutputfolder <argument>---------------- 報告儀表板的輸出文件夾
output folder for report dashboard
運行腳本進行壓測
當然,在運行腳本進行壓測的時候 需要在服務器 先執行 采集命令
ps -ef | grep nmon 查看采集數據的進程
[root@lamw /home/lam7/nmon]# ps -ef | grep nmon
[root@lamw /home/lam7/nmon]# nmon -f -s 1 -c 60
-f 表示生成的數據文件名中有時間;
-t 輸出中包括占用率較高的進程;
-s 1 表示每 1 秒采集一次數據;
-c 60 表示采集 60 次,1s*60=60秒;
至於監控的方式可以查看上面所講的准備工作第三點