Skip to content

Commit 6b4beaf

Browse files
committed
graph: Explain a little more on how we adjust the kill_rate
Also, pull constants only needed in update_kill_rate into the function
1 parent c376226 commit 6b4beaf

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

graph/src/data/graphql/effort.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ lazy_static! {
5050
// associated with it
5151
static ref LOAD_MANAGEMENT_DISABLED: bool = *LOAD_THRESHOLD == ZERO_DURATION;
5252

53-
static ref KILL_RATE_UPDATE_INTERVAL: Duration = Duration::from_millis(1000);
54-
5553
static ref SIMULATE: bool = env::var("GRAPH_LOAD_SIMULATE").is_ok();
5654
}
5755

@@ -124,9 +122,6 @@ impl QueryEffortInner {
124122
}
125123
}
126124

127-
// The size of any individual step when we adjust the kill_rate
128-
const KILL_RATE_STEP: f64 = 0.1;
129-
130125
/// What to log about the state we are currently in
131126
enum KillStateLogEvent {
132127
/// Overload is starting right now
@@ -386,15 +381,35 @@ impl LoadManager {
386381
overloaded: bool,
387382
wait_ms: Duration,
388383
) -> 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+
389404
assert!(overloaded || kill_rate > 0.0);
390405

391406
let now = Instant::now();
392407
if now.saturating_duration_since(last_update) > *KILL_RATE_UPDATE_INTERVAL {
393408
// Update the kill_rate
394409
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);
396411
} 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);
398413
}
399414
let event = {
400415
let mut state = self.kill_state.write().unwrap();

0 commit comments

Comments
 (0)