Jmeter分佈式壓力測試

安裝

下載地址:http://jmeter.apache.org/download_jmeter.cgi

 

安裝前提(因爲jmeter依賴於java所以必須先配置好java

下載後解壓:

 tar -xvzf apache-jmeter-3.1.tgz

 

Jmeter參數

-h, --help

                print usage information and exit

#打印幫助信息 

        -v, --version

                print the version information and exit

          #打印版本信息

        -p, --propfile {argument}

                the jmeter property file to use

          #運行時指定property文件,默認是使用JMETER_HOME/bin目錄下的jmeter.properties,如果用戶自定義有其它的配置,在這裏加上

          #用法如下: -p user.properties

        -q, --addprop {argument}

                additional property file(s)

          #其它配置文件,如JVM參數等等

        -t, --testfile {argument}

                the jmeter test(.jmx) file to run

          #要運行的jmeter腳本

        -j, --jmeterlogfile {argument}

                the jmeter log file

          #指定記錄jmeter log的文件,默認爲jmeter.log

        -l, --logfile {argument}

                the file to log samples to

          #記錄採樣器Log的文件

        -n, --nongui

                run JMeter in nongui mode

          #以nongui模式運行jmeter

        -s, --server

                run the JMeter server

          #運行JMeter server

        -H, --proxyHost {argument}

                Set a proxy server for JMeter to use

          #代理服務器地址

        -P, --proxyPort {argument}

                Set proxy server port for JMeter to use

          #代理服務器端口

        -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

          #定義額外的Jmeter屬性

        -G, --globalproperty (argument)[=(value)]

                Define Global properties (sent to servers)

                e.g. -Gport=123

                 or -Gglobal.properties

          #定義發送給server的全局屬性

         #如:-Gport=123 或者-Gglobal.properties(指定監聽server的端口)

        -D, --systemproperty {argument}={value}

                Define additional System properties

          #定義系統屬性

        -S, --systemPropertyFile {filename}

                a property file to be added as System properties

#通過指定的property文件定義系統屬性

        -L, --loglevel {argument}={value}

                Define loglevel: [category=]level 

                e.g. jorphan=INFO or jmeter.util=DEBUG

          #定義日誌等級

        -r, --runremote (non-GUI only)

                Start remote servers (as defined by the jmeter property remote_hosts)

          #啓動遠程server(在jmeter property中定義好的remote_hosts),公在non-gui模式下此參數才生效

        -R, --remotestart  server1,... (non-GUI only)

                Start these remote servers (overrides remote_hosts)

          #啓動遠程server(如果使用此參數,將會忽略jmeter property中定義的remote_hosts)

        -d, --homedir {argument}

                the jmeter home directory to use

                #Jmeter運行的主目錄

        -X, --remoteexit

                Exit the remote servers at end of test (non-GUI)

          #測試結束時,退出(在non-gui模式下)


 

 配置jmeter client & server

瞭解了上面的各個參數後,開始配置分佈式測試

先看一下官方文檔是怎麼說的,中文爲我添加的註釋:

1. the firewalls on the systems are turned off.#1.關閉防火牆

2. all the clients are on the same subnet.#2.所有的客戶端都在同一個子網內

3. 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 or 10 ip address, there shouldn't be any problems.#3.server也必須在同一子網內如果使用192.x.x.x或者10.x.x.x這樣的IP地址,如果server沒有使用192或者10這樣的IP地址,(server同client不在同一子網內)將不會有任何問題

4. Make sure JMeter can access the server.#4.確保Jmeter可以訪問到server

5. Make sure you use the same version of JMeter on all the systems. Mixing versions may not work

correctly.#5.確保各系統的Jmeter版本保持一致,不同版本的Jmeter將不能很好的工作

 

一些術語的解釋:

· master,以GUI模式運行,同時控制測試的運行,在這裏就是client,啓動腳本所在的那臺機器。

· slave,運行jmeter-server並從master接收指令、向目標服務器發送請求

設置jmeter-server:

用文本編輯器打開JMETER_HOME/bin目錄下的jmeter.properties文件,添加運行jmeter-server的主機IPremote-hosts

remote_hosts=10.0.0.158, 10.0.0.140,localhost

如果你不希望你的客戶端也作爲jmeter-server運行的話,把localhost從上面的配置中移除。

這裏要注意:建議不用localhost而是使用實際的IP,否則容易報錯。

 

 

實戰階段:

一、在客戶端以gui模式啓動jmeter,然後打開或者創建一個測試腳本


二、從gui模式啓動所有的遠程server,方法:運行-遠程全部啓動,看下圖,也可以單獨啓動某一個jmeter-server


三、使用no-gui方式進行壓力測試

jmeter -t "JMS Point-to-Point.jmx" -n -l testresult.csv -r
-t:從哪個jmx啓動

-n:以no-gui的方式進行壓力測試

-l:記錄log

-r:啓動遠程server(在jmeter property中定義好的remote_hosts),公在non-gui模式下此參數才生效

至此,以經通過non-gui模式運行Jmeter分佈式測試了

這裏有一點小貼士:以分佈式運行Jmeter,是在所有的server上運行同樣的測試腳本,也就是說,如果你打算1s起100個線程,如果你用5臺機器進行分佈式測試,那麼將腳本調試至1s起20個線程,否則則是1s起了500個線程,這樣可能跟你的預期有所差別

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章