除了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)); } }