Skip to content

Commit 5d7d046

Browse files
committed
graph: Clamp LoadManager's kill_rate and probability to drop query
Make sure that boht the kill_rate and the probability with which we drop a query stay between 0 and 1. Trying to call thread_rng().gen_bool(p) with a p outside of [0,1] causes a panic
1 parent 8ccfa9a commit 5d7d046

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

graph/src/data/graphql/effort.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl LoadManager {
337337
// Kill random queries in case we have no queries, or not enough queries
338338
// that cause at least 20% of the effort
339339
let kill_rate = self.update_kill_rate(kill_rate, last_update, overloaded, wait_ms);
340-
thread_rng().gen_bool(kill_rate * query_effort / total_effort)
340+
thread_rng().gen_bool((kill_rate * query_effort / total_effort).min(1.0).max(0.0))
341341
}
342342

343343
fn overloaded(&self) -> (bool, Duration) {
@@ -367,8 +367,8 @@ impl LoadManager {
367367
if now.saturating_duration_since(last_update) > *KILL_RATE_UPDATE_INTERVAL {
368368
// Update the kill_rate
369369
if overloaded {
370-
kill_rate = kill_rate + KILL_RATE_STEP * (1.0 - kill_rate);
371-
} else {
370+
kill_rate = (kill_rate + KILL_RATE_STEP * (1.0 - kill_rate)).min(1.0);
371+
} else if kill_rate > KILL_RATE_STEP {
372372
kill_rate = (kill_rate - KILL_RATE_STEP).max(0.0);
373373
}
374374
let event = {

0 commit comments

Comments
 (0)