通過(guò)性能測(cè)試配置遞增線(xiàn)程
除了Grinder引擎提供的進(jìn)程斜坡之外,nGrinder 3.3還支持線(xiàn)程斜坡。因?yàn)檫M(jìn)程是非常昂貴的資源,在單個(gè)核心機(jī)器中,大約10是可執(zhí)行進(jìn)程的最大計(jì)數(shù)。因此,到目前為止,流程漸變只支持非常有限的漸變(從0到10)。在nGrinder 3.3中,可以通過(guò)配置啟用線(xiàn)程斜坡。因?yàn)槊總€(gè)進(jìn)程可以執(zhí)行100多個(gè)線(xiàn)程,這使得過(guò)渡比進(jìn)程過(guò)渡非常平穩(wěn)。

通過(guò)在右上角選擇線(xiàn)程并在vuser部分提供足夠的線(xiàn)程數(shù),圖表將顯示平滑的漸變圖表。執(zhí)行測(cè)試之后,您可以在詳細(xì)的報(bào)告中看到如下結(jié)果。隨著時(shí)間的推移,vuser的數(shù)量也在增加,TPS也在增加。

通過(guò)腳本遞增線(xiàn)程
3.3版本之前的nGrinder支持進(jìn)程漸變作為默認(rèn)特性。如果用戶(hù)希望逐步增加負(fù)載,那么用戶(hù)可以在測(cè)試配置頁(yè)面的過(guò)渡面板上設(shè)置許多進(jìn)程以及如何增加它們。

這是一個(gè)漸進(jìn)的過(guò)程。如果您喜歡在過(guò)渡過(guò)程中執(zhí)行10個(gè)步驟,那么您應(yīng)該將流程計(jì)數(shù)設(shè)置為至少10個(gè)步驟。如果需要更多,應(yīng)該設(shè)置更多進(jìn)程數(shù)量。
但是,這些流程需要調(diào)用大量資源。代理中的100個(gè)進(jìn)程是不現(xiàn)實(shí)的。這會(huì)導(dǎo)致代理機(jī)器內(nèi)存不足錯(cuò)誤。
假設(shè)你想知道系統(tǒng)從哪個(gè)TPS水平開(kāi)始飽和。
在這種情況下,您可以使用線(xiàn)程級(jí)別漸變。您只需要在腳本中添加以下代碼。
Jython
# -*- 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
Groovy
如果您使用的是nGrinder 3.2.3或更高版本,那么應(yīng)該在代碼中加入sleep邏輯。
/**
* 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));
}
}