# Throttling based on error rates

**URL:** <https://community.gatling.io/t/throttling-based-on-error-rates/3760>\
**Category:** Gatling (Open-Source)\
**Created:** [June 8, 2017, 8:40pm UTC](https://community.gatling.io/t/throttling-based-on-error-rates/3760 "2017-06-08T20:40:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richie\_Vos](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@Richie\_Vos](https://community.gatling.io/u/Richie_Vos)\
**Post date:** [June 8, 2017, 8:40pm UTC](https://community.gatling.io/t/throttling-based-on-error-rates/3760/1 "2017-06-08T20:40:47Z")

</div>

I’m looking into Gatling, and am attempting to integrate feedback into the throttling mechanism, in particular I’d like to stop a throughput ramp based on error rates. I know this has been talked about before, but the [latest post on the matter I can find is from 9/2015](https://groups.google.com/forum/#!searchin/gatling/throttle$20error%7Csort:relevance/gatling/ecw4DKieTBk/Ue2wNJnzBwAJ), so I figured it’s fair game to ask again.

I’m not sure how this would be properly implemented, but as an initial pass I was hoping to dynamically update the throttle’s rps as errors come in. As a simple definition, let’s say that any time a scenario’s status is KO, the maximum rps would be set to the current rps. In pseudo-gatling, I was going to try and do something like:

> class BasicSimulation extends Simulation {  
> val httpConf = http.baseURL(“[http://computer-database.gatling.io](http://computer-database.gatling.io)”)
> 
> **val throttleStep = reachRps(1000) in (10 minutes)**
> 
> val scn = scenario(“BasicSimulation”)  
> .exec(http(“request\_1”)  
> .get(“/”)  
> .check(status).in(200 to 399))  
> .exec(session =\> {  
> if (session.status != OK) {  
> **val newCap = somehowComputeCurrentRps()**  
> **throttleStep.target = newCap**  
> }  
> })
> 
> setUp(  
> scn.inject(atOnceUsers(1000))  
> )  
> .throttle(throttleStep)  
> .protocols(httpConf)  
> }

Meaning, I inject a throttle into the simulation, and I’d dynamically adjust its target as I hit errors. In practice I’d want this logic to be more complicated, but I haven’t figured out exactly what I’d want to do (it’ll depend on what I can do). It’ll probably involve something like checking general error rates and if they’re out of spec go backwards in time until they go back in.

I have a feeling I could get this to work if I defined my own ThrottleStep implementation, but since ThrottleStep is a sealed trait, that’d require me to build my own custom version of Gatling, which I’d like to avoid doing. I’m also completely fine with it not being a generally applicable solution, since I can imagine this getting quite complicated when trying to handle a complicated throttle chain.

Any pointers on how one could hack this into a simulation? I’m not really looking for a solution that involves me manually watching graphs/log files to look for errors. Nor am I looking for a solution that completely aborts the Gatling run.

Thanks!
