@@ -50,8 +50,6 @@ lazy_static! {
50
50
// associated with it
51
51
static ref LOAD_MANAGEMENT_DISABLED : bool = * LOAD_THRESHOLD == ZERO_DURATION ;
52
52
53
- static ref KILL_RATE_UPDATE_INTERVAL : Duration = Duration :: from_millis( 1000 ) ;
54
-
55
53
static ref SIMULATE : bool = env:: var( "GRAPH_LOAD_SIMULATE" ) . is_ok( ) ;
56
54
}
57
55
@@ -124,9 +122,6 @@ impl QueryEffortInner {
124
122
}
125
123
}
126
124
127
- // The size of any individual step when we adjust the kill_rate
128
- const KILL_RATE_STEP : f64 = 0.1 ;
129
-
130
125
/// What to log about the state we are currently in
131
126
enum KillStateLogEvent {
132
127
/// Overload is starting right now
@@ -386,15 +381,35 @@ impl LoadManager {
386
381
overloaded : bool ,
387
382
wait_ms : Duration ,
388
383
) -> f64 {
384
+ // The rates by which we increase and decrease the `kill_rate`; when
385
+ // we increase the `kill_rate`, we do that in a way so that we do drop
386
+ // fewer queries as the `kill_rate` approaches 1.0. After `n`
387
+ // consecutive steps of increasing the `kill_rate`, it will
388
+ // be `1 - (1-KILL_RATE_STEP_UP)^n`
389
+ //
390
+ // When we step down, we do that in fixed size steps to move away from
391
+ // dropping queries fairly quickly so that after `n` steps of reducing
392
+ // the `kill_rate`, it is at most `1 - n * KILL_RATE_STEP_DOWN`
393
+ //
394
+ // The idea behind this is that we want to be conservative when we drop
395
+ // queries, but aggressive when we reduce the amount of queries we drop
396
+ // to disrupt traffic for as little as possible.
397
+ const KILL_RATE_STEP_UP : f64 = 0.1 ;
398
+ const KILL_RATE_STEP_DOWN : f64 = 2.0 * KILL_RATE_STEP_UP ;
399
+
400
+ lazy_static ! {
401
+ static ref KILL_RATE_UPDATE_INTERVAL : Duration = Duration :: from_millis( 1000 ) ;
402
+ }
403
+
389
404
assert ! ( overloaded || kill_rate > 0.0 ) ;
390
405
391
406
let now = Instant :: now ( ) ;
392
407
if now. saturating_duration_since ( last_update) > * KILL_RATE_UPDATE_INTERVAL {
393
408
// Update the kill_rate
394
409
if overloaded {
395
- kill_rate = ( kill_rate + KILL_RATE_STEP * ( 1.0 - kill_rate) ) . min ( 1.0 ) ;
410
+ kill_rate = ( kill_rate + KILL_RATE_STEP_UP * ( 1.0 - kill_rate) ) . min ( 1.0 ) ;
396
411
} else {
397
- kill_rate = ( kill_rate - 2.0 * KILL_RATE_STEP ) . max ( 0.0 ) ;
412
+ kill_rate = ( kill_rate - KILL_RATE_STEP_DOWN ) . max ( 0.0 ) ;
398
413
}
399
414
let event = {
400
415
let mut state = self . kill_state . write ( ) . unwrap ( ) ;
0 commit comments