Gatling throttle with my own extention of gatling Action and action builder

267 views
Skip to first unread message

Alastair Vella

unread,
Jan 26, 2017, 5:28:14 AM1/26/17
to Gatling User Group
Hi,

I extended the gatling action builder to write my own steps from where to place an http call. In other words I am using my own client. The test works fine with ramping users over a period of time.

but when I try to throttle it is not considered. I am still producing a lot of request per second as if there is no throtling. I tried using the gatling http client instead of my implementation and throttling works fine, 
so it is probably something from my implementation.

below find my implementation.

thanks in advance.

setUp(dep1.inject(rampUsers(users) over(rampup minutes))).throttle(jumpToRps(1), holdFor(duration minutes)).maxDuration(duration minutes)

val dep1: ScenarioBuilder = new ScenarioLotusAuthsDecide().performTest(duration)

def performTest(duration: Long) = {
scenario("test")
.during(duration minutes) {
exec(ActionBuilder("Action", url))
}
}

case class ActionBuilder(functionName: String,  url: String) extends ActionBuilder {

override def build(ctx: ScenarioContext, next: Action): Action = {
val statsEngine = ctx.coreComponents.statsEngine
ActionActor(next, statsEngine, functionName, cardId, url)
}
}

case class ActionActor(next: Action, statsEngine: StatsEngine, functionName: String,  url: String)
extends ActionActor[Params, Decision] {
private val MAXIMUM_AUTH_ID_LENGTH = 15

override def name: String = "Auth Decide Actor"


override def prepareRequest(): Params = {
buildRequest()
}

override def executeRequest(request: Params): Response[Decision] =
client
.placeCall(request)

}


trait LotusActionActor[REQ <: Message, RESP] extends ChainableAction {
def next: Action

def name: String

def statsEngine: StatsEngine

def functionName: String

def prepareRequest(): MessageRequest[REQ]

def executeRequest(request: MessageRequest[REQ]): Response[RESP]

override def execute(session: Session): Unit = {
val request = prepareRequest()
val executionResult = timedExecution(request)
printExceptionDetails(executionResult.exception)
val updatedSession = if (executionResult.exception == null) session.markAsSucceeded else session.markAsFailed
statsEngine.logResponse(session, functionName, executionResult.responseTimings, updatedSession.status, None, None)
next ! updatedSession
}

private def timedExecution(request: MessageRequest[REQ]): ExecutionResult = {
val startTime = now()
try {
executeRequest(request)
val endTime = now()
new ExecutionResult(null, ResponseTimings(startTime, endTime))
} catch {
case exception: Exception =>
val endTime = now()
new ExecutionResult(exception, ResponseTimings(startTime, endTime))
}
}

private def printExceptionDetails(exception: Exception): Unit = {
exception match {
case null =>
case e: ConflictException => println("Received conflict : " + e.getConflictResponse.getMessage)
case e: ExternalException => println("Error received : " + e.getMessage)
case _ => println("Error occurred while executing: " + exception.getMessage)
}
}

@inline
private def now() = System.currentTimeMillis()

private class ExecutionResult(val exception: Exception, val responseTimings: ResponseTimings)


Reply all
Reply to author
Forward
0 new messages