效能測試工具nGrinder介紹
安裝
以linux,這裡採用的版本是centos 6 64bit,效能測試工具不建議在Windows上部署。
下載:
ofollow,noindex">https://github.com/naver/ngrinder/releases/
選擇最後面的war包。
伺服器端啟動:
# java -XX:MaxPermSize=200m -jar ngrinder-controller-3.4.war --port 8058
這樣nGrinder的管理頁面就部署好,你可以簡單的把ngrinder-controller的功能理解為效能測試展示和控制,後面會進行詳細介紹。
開啟網址:
http://183.131.22.113:8058
預設使用者名稱和密碼都為admin

圖片.png
注意:這裡的"Remember me"是短暫停留,頁面關閉之後還是需要重新登陸的。
登入後點擊右上角的admin,選擇"下載代理"

圖片.png
拷貝下載的檔案到agent,現在可以簡單理解為agent的功能為執行效能測試,通常不建議與ngrinder-controller部署在同一臺,同一臺機器也不建議部署多個agent。
客戶端啟動:
# nohup ./run_agent.sh&
快速入門
-
輸入網址
http://172.30.249.160

圖片.png
- 配置

圖片.png
- jython指令碼
點選 REV:HEAD,可以看到jython指令碼

圖片.png
- 執行
點選"複製並執行"

圖片.png
- 檢視結果

圖片.png
點選"詳細測試結果"

圖片.png
參考資料
- 技術支援qq群144081101(程式碼和模型存放)
- 本文最新版本地址
- 本文涉及的python測試開發庫 謝謝點贊!
- 本文相關海量書籍下載
- 2018最佳人工智慧機器學習工具書及下載(持續更新)
- 介面測試面試題.pdf
- 軟體測試精品書籍下載
測試配置
注意agent RAM up配置是基於程序的,一般每個agent有10個程序。
指令碼
首先要配置:grinder.properties,通常在使用者目錄的.ngrinder目錄下。
指令碼使用Grinder指令碼API,參見: http://grinder.sourceforge.net/g3/script-javadoc/index.html
指令碼中的grinder物件是ScriptContext例項,這樣就可以獲取上下文資訊。
Hello World
# Hello World # # A minimal script that tests The Grinder logging facility. # # This script shows the recommended style for scripts, with a # TestRunner class. The script is executed just once by each worker # process and defines the TestRunner class. The Grinder creates an # instance of TestRunner for each worker thread, and repeatedly calls # the instance for each run of that thread. from net.grinder.script.Grinder import grinder from net.grinder.script import Test # A shorter alias for the grinder.logger.info() method. log = grinder.logger.info # Create a Test with a test number and a description. The test will be # automatically registered with The Grinder console if you are using # it. test1 = Test(1, "Log method") # Instrument the info() method with our Test. test1.record(log) # A TestRunner instance is created for each thread. It can be used to # store thread-specific data. class TestRunner: # This method is called for every run. def __call__(self): log("Hello World")
Simple HTTP example
# A simple example using the HTTP plugin that shows the retrieval of a # single page via HTTP. The resulting page is written to a file. # # More complex HTTP scripts are best created with the TCPProxy. from net.grinder.script.Grinder import grinder from net.grinder.script import Test from net.grinder.plugin.http import HTTPRequest test1 = Test(1, "Request resource") request1 = HTTPRequest() test1.record(request1) class TestRunner: def __call__(self): result = request1.GET("http://localhost:7001/") # result is a HTTPClient.HTTPResult. We get the message body # using the getText() method. writeToFile(result.text) # Utility method that writes the given string to a uniquely named file. def writeToFile(text): filename = "%s-page-%d.html" % (grinder.processName, grinder.runNumber) file = open(filename, "w") print >> file, text file.close()
更多指令碼,參見: http://grinder.sourceforge.net/g3/script-gallery.html