Jmeter(一)非GUI模式壓測(NON-GUI模式)結果解析TPS


非GUI模式壓測(NON-GUI模式)結果解析TPS

 

准備工作

  1. 從腳本已錄制成功之后開始進行壓測
  2. 安裝Jmeter拓展插件 查看 Transactions per Second https://jmeter-plugins.org/wiki/TransactionsPerSecond/       ←插件地址
  3. 在壓測前先安裝 Nmon監控工具在服務器linux性能監控分析及通過nmon_analyse生成分析報

 

安裝 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

Once everything is ready, you will use Command-line mode (called Non-GUI mode) to run it for the Load Test.

Don't run load test using GUI mode !   
不要使用GUI模式運行負載測試!因為GUI模式的話會占用比較大的內存空間,並發數量上不去等等的問題

Using Non-GUI mode, you can generate a CSV (or XML) file containing results and have JMeter generate an HTML report at end of Load Test. JMeter will by default provide a summary of load test while it's running. 

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的相關命令幫助

 

C:\Users\lamw\Desktop\lamw
λ D:\Jmeter\jmeter-3.1\bin\jmeter -h

 

---------------------------------------------------

上面包含了一些參數 可以輸入 -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模式執行腳本 如下:(每次執行腳本之前都要把jtl文件刪除,report文件夾清空!不然會報錯

--------------------------------------------------

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]

--------------------------------------------------

輸入以下命令直接執行錄制好的腳本文件 D:\Jmeter\apache-jmeter-5.0\apache-jmeter-5.0\jm> #先進入
測試腳本所在的文件目錄
D:\Jmeter\apache-jmeter-5.0\apache-jmeter-5.0\jm>jmeter -n -t Script.jmx -l result.jtl -e -o D:\Jmeter\apache-jmeter-5.0\apache-jmeter-5.0\jm\report
Script.jmx 是腳本名稱
result.jtl 是壓測生成的中間件,可以在jmeter中打開
D:\Jmeter\apache-jmeter-5.0\apache-jmeter-5.0\jm\report  是測試報告的路徑
 
 

 

運行腳本進行壓測

 

 

 

 

 

 

當然,在運行腳本進行壓測的時候 需要在服務器 先執行 采集命令

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秒;

至於監控的方式可以查看上面所講的准備工作第三點。

 

Apache JMeter Distributed Testing Step-by-step

This short tutorial explains how to use multiple systems to perform stress testing. Before we start, there are a couple of things to check.

  • the firewalls on the systems are turned off or correct ports are opened.
  • all the clients are on the same subnet.
  • the server is in the same subnet, if 192.x.x.x or 10.x.x.x IP addresses are used. If the server doesn't use 192.xx or 10.xx IP address, there shouldn't be any problems.
  • Make sure JMeter can access the server.
  • Make sure you use the same version of JMeter and Java on all the systems. Mixing versions will not work correctly.

Once you've made sure the systems are ready, it's time to setup remote testing. The tutorial assumes you already have JMeter installed on all the systems. The way JMeter works is one master controller initiates the test on multiple slave systems.

 

Before we dive into the step-by-step instructions, it's a good idea to define the terms and make sure the definition is clear.

Master
the system running JMeter GUI, which controls the test
Slave
the system running  jmeter-server, which takes commands from the GUI and send requests to the target system(s)
Target
the webserver we plan to stress test

 

 

  1. On the slave systems, go to jmeter/bin directory and execute jmeter-server.bat(jmeter-server on unix).
  2. On master system acting as the console, open windows explorer and go to jmeter/bin directory
  3. Open jmeter.properties in a text editor
  4. Edit the line remote_hosts=127.0.0.1
  5. Add the IP address. For example, if I have JMeter server running on 192.168.30.50:1099, …, 192.168.30.51:1099,the entry would like like this

             :

  1. Start JMeter.
  2. Open the test plan you want to use

 

 Start a single clients

  1. Click Run at the top
  2. Select Remote Start
  3. Select the IP address

Start all clients

 

  1. Click Run at the top
  2. Select Remote Start all or use Ctrl + Shift + R

 

Limitations

There are some basic limitations for distributed testing. Here's the list of the known items in no specific order.

  1. RMI cannot communicate across subnets without a proxy; therefore neither can JMeter without a proxy.
  2. Since version 2.9, JMeter sends all the test results stripping Response data to the controlling console, this allows us to reduce impact on network IO. Ensure you monitor your network traffic so that this trafic does not incur contention
  3. A single JMeter client running on a 2-3 GHz CPU (recent CPU) can handle 1000-2000 threads depending on the type of test.

簡單點的說

Jmeter分布式執行原理:

  1、Jmeter分布式測試時,選擇其中一台作為調度機(master),其它機器做為執行機(slave)。

  2、執行時,master會把腳本發送到每台slave上,slave 拿到腳本后就開始執行,slave執行時不需要啟動GUI,我理解它應該是通過命令行模式執行的。

  3、執行完成后,slave會把結果回傳給master,master會收集所有slave的信息並匯總。

術語解析

  • master,以GUI模式運行,同時控制測試的運行,在這里就是client,啟動腳本所在的那台機器。
  • slave,運行jmeter-server並從master接收指令、向目標服務器發送請求
  • 設置jmeter-server:

    用文本編輯器打開Jmeter/bin目錄下的jmeter.properties文件,添加運行jmeter-server的主機IP到remote_hosts

remote_hosts=192.168.30.50:1099,192.168.30.51:1099,localhost.....

 

小白解釋分割線

 ----------------------------------------------------------

再白痴點的解釋就是   有 A B C  三台壓力機器,屬於同一個內網IP

A作為 Master

B跟C兩台作為slave

通過A去控制B跟C進行壓測服務器
在壓測的過程中 需要先開啟B跟C的Jmeter的bin目錄下的jmeter-server.bat 服務

然后通過A去進行NON-GUI模式去壓測,B跟C分布式的壓測結果會反饋到A

-----------------------------------------------------------

小白解釋結束線

 

下面進行實戰命令 壓測

通過 jmeter -l 的幫助命令可以查看到

C:\Users\lamw\Desktop\lamw
λ D:\Jmeter\jmeter-3.1\bin\jmeter -l
Error: Missing argument to option -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

Error: Missing argument to option -l

其中

-r, --runremote    

Start remote servers (as defined in remote_hosts)------------------啟動遠程服務器(如remote_hosts中定義)
-R, --remotestart <argument>
Start these remote servers (overrides remote_hosts)-------------------啟動這些遠程服務器(覆蓋remote_hosts)

那么我們就可以去選擇執行所有的配置中的壓測機器

D:\Jmeter\jmeter-3.1\bin\jmeter.bat -n -r -t test.jmx -l test.csv -e -o test

 

可以看到已經成功執行了配置中的2台壓測機

 

PS 如果壓測指標是1000並發數,比如我們現在配置了2台需要達到1000並發數,那么就是一台壓測並發數500即可

 

 

原文地址:https://www.cnblogs.com/Lam7/p/6830449.html 

                  https://www.cnblogs.com/Lam7/p/6833501.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM