Skip to content

Commit

Permalink
Run new query planner off of Tokio threads (#5998)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin authored Sep 17, 2024
1 parent 30f3004 commit b443ad0
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions apollo-router/src/query_planner/bridge_query_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,32 +288,41 @@ impl PlannerMode {
}
Ok(success)
}
PlannerMode::Rust(rust) => {
let start = Instant::now();

let result = operation
.as_deref()
.map(|n| Name::new(n).map_err(FederationError::from))
.transpose()
.and_then(|operation| rust.build_query_plan(&doc.executable, operation))
.map_err(|e| QueryPlannerError::FederationError(e.to_string()));

let elapsed = start.elapsed().as_secs_f64();
metric_query_planning_plan_duration(RUST_QP_MODE, elapsed);

let plan = result?;
PlannerMode::Rust(rust_planner) => {
let doc = doc.clone();
let rust_planner = rust_planner.clone();
let (plan, mut root_node) = tokio::task::spawn_blocking(move || {
let start = Instant::now();

let result = operation
.as_deref()
.map(|n| Name::new(n).map_err(FederationError::from))
.transpose()
.and_then(|operation| {
rust_planner.build_query_plan(&doc.executable, operation)
})
.map_err(|e| QueryPlannerError::FederationError(e.to_string()));

let elapsed = start.elapsed().as_secs_f64();
metric_query_planning_plan_duration(RUST_QP_MODE, elapsed);

result.map(|plan| {
let root_node = convert_root_query_plan_node(&plan);
(plan, root_node)
})
})
.await
.expect("query planner panicked")?;
if let Some(node) = &mut root_node {
init_query_plan_root_node(node)?;
}

// Dummy value overwritten below in `BrigeQueryPlanner::plan`
let usage_reporting = UsageReporting {
stats_report_key: Default::default(),
referenced_fields_by_type: Default::default(),
};

let mut root_node = convert_root_query_plan_node(&plan);
if let Some(node) = &mut root_node {
init_query_plan_root_node(node)?;
}

Ok(PlanSuccess {
usage_reporting,
data: QueryPlanResult {
Expand Down

0 comments on commit b443ad0

Please sign in to comment.