Skip to content

Commit 1d12880

Browse files
committed
graph: Correctly calculate the relative effort of a query
We used to compare the average execution time of a query to the average total execution time, but that comparison is meaningless, and does not indicate how much of the total workload is caused by that query - it's entirely possible to have a total average execution time of 50ms and a single query that takes 5s on average. Rather than using averages, we now use the total time that a query took during the window and compare it to the total time for all queries to determine the fraction of the total effort caused by that query.
1 parent 8943669 commit 1d12880

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

graph/src/data/graphql/effort.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,8 @@ impl QueryEffort {
9494
/// for the query
9595
pub fn current_effort(&self, shape_hash: u64) -> (Option<Duration>, Duration) {
9696
let inner = self.inner.read().unwrap();
97-
let total_effort = inner.total.average().unwrap_or(*ZERO_DURATION);
98-
let query_effort = inner
99-
.effort
100-
.get(&shape_hash)
101-
.and_then(|stats| stats.average());
97+
let total_effort = inner.total.duration();
98+
let query_effort = inner.effort.get(&shape_hash).map(|stats| stats.duration());
10299
(query_effort, total_effort)
103100
}
104101
}
@@ -330,7 +327,8 @@ impl LoadManager {
330327
warn!(self.logger, "Jailing query";
331328
"query" => query,
332329
"query_effort_ms" => query_effort,
333-
"total_effort_ms" => total_effort);
330+
"total_effort_ms" => total_effort,
331+
"ratio" => format!("{:.4}", query_effort/total_effort));
334332
self.jailed_queries.write().unwrap().insert(shape_hash);
335333
return true;
336334
}
@@ -392,7 +390,7 @@ impl LoadManager {
392390
info!(self.logger, "Query overload still happening";
393391
"duration_ms" => duration.as_millis(),
394392
"wait_ms" => wait_ms.as_millis(),
395-
"kill_rate" => kill_rate,
393+
"kill_rate" => format!("{:.4}", kill_rate),
396394
"event" => "ongoing");
397395
}
398396
Start => {

0 commit comments

Comments
 (0)