除了Grinder引擎提供的進程斜坡以外,nGrinder 3.3還支持線程斜坡。由於進程是很是昂貴的資源,在單個核心機器中,大約10是可執行進程的最大計數。所以,到目前爲止,流程漸變只支持很是有限的漸變(從0到10)。在nGrinder 3.3中,能夠經過配置啓用線程斜坡。由於每一個進程能夠執行100多個線程,這使得過渡比進程過渡很是平穩。性能
經過在右上角選擇線程並在vuser部分提供足夠的線程數,圖表將顯示平滑的漸變圖表。執行測試以後,您能夠在詳細的報告中看到以下結果。隨着時間的推移,vuser的數量也在增長,TPS也在增長。測試
3.3版本以前的nGrinder支持進程漸變做爲默認特性。若是用戶但願逐步增長負載,那麼用戶能夠在測試配置頁面的過渡面板上設置許多進程以及如何增長它們。google
這是一個漸進的過程。若是您喜歡在過渡過程當中執行10個步驟,那麼您應該將流程計數設置爲至少10個步驟。若是須要更多,應該設置更多進程數量。線程
可是,這些流程須要調用大量資源。代理中的100個進程是不現實的。這會致使代理機器內存不足錯誤。代理
假設你想知道系統從哪一個TPS水平開始飽和。code
在這種狀況下,您可使用線程級別漸變。您只須要在腳本中添加如下代碼。進程
# -*- coding:utf-8 -*- # A simple example using the HTTP plugin that shows the retrieval of a # single page via HTTP. # # This script is auto generated by ngrinder. # from net.grinder.script.Grinder import grinder from net.grinder.script import Test from net.grinder.plugin.http import HTTPRequest from net.grinder.plugin.http import HTTPPluginControl from HTTPClient import NVPair control = HTTPPluginControl.getConnectionDefaults() control.setTimeout(30000) test1 = Test(1, "Test1") request1 = HTTPRequest(); test1.record(request1) class TestRunner: def initialSleep( self ): sleepTime = grinder.threadNumber * 1000 # 1 seconds per thread grinder.sleep(sleepTime, 0) def __call__( self ): if grinder.runNumber == 0: self.initialSleep() grinder.statistics.delayReports=True result = request1.GET("http://www.google.com") if result.getText().find("Google") != -1 : grinder.statistics.forLastTest.success = 1 else : grinder.statistics.forLastTest.success = 0
若是您使用的是nGrinder 3.2.3或更高版本,那麼應該在代碼中加入sleep邏輯。ip
/** * A simple example using the HTTP plugin that shows the retrieval of a * single page via HTTP. * * This script is auto generated by ngrinder. * * @author ${userName} */ @RunWith(GrinderRunner) class Test1 { public static GTest test; public static HTTPRequest request; @BeforeProcess public static void beforeClass() { test = new GTest(1, "aa000000"); request = new HTTPRequest(); test.record(request); grinder.logger.info("before process."); } @BeforeThread public void beforeThread() { grinder.statistics.delayReports=true; grinder.logger.info("before thread."); } public void initialSleep() { grinder.sleep(grinder.threadNumber * 1000, 0) } @Test public void test(){ if (grinder.runNumber == 0) { initialSleep() } HTTPResponse result = request.GET("http://www.google.com"); if (result.statusCode == 301 || result.statusCode == 302) { grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode); } else { assertThat(result.statusCode, is(200)); } }