From 7c943afc2b307e327009e0cc59034a9e6af37a1a Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sun, 15 Dec 2024 15:09:41 -0800 Subject: [PATCH] server: attempt concurrency with graphql::search and fail --- notmuch/src/lib.rs | 2 ++ server/src/graphql.rs | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/notmuch/src/lib.rs b/notmuch/src/lib.rs index 7cf18b5..fe5704a 100644 --- a/notmuch/src/lib.rs +++ b/notmuch/src/lib.rs @@ -465,6 +465,8 @@ pub struct Notmuch { config_path: Option, } +// TODO: rewrite to use tokio::process::Command and make everything async to see if that helps with +// concurrency being more parallel. impl Notmuch { pub fn with_config>(config_path: P) -> Notmuch { Notmuch { diff --git a/server/src/graphql.rs b/server/src/graphql.rs index 1211447..5c84e12 100644 --- a/server/src/graphql.rs +++ b/server/src/graphql.rs @@ -9,6 +9,7 @@ use log::info; use notmuch::Notmuch; use serde::{Deserialize, Serialize}; use sqlx::postgres::PgPool; +use tokio::join; use tracing::instrument; use crate::{config::Config, newsreader, nm, tantivy::TantivyConnection, Query}; @@ -286,6 +287,8 @@ impl QueryRoot { Ok(total) } + // TODO: this function doesn't get parallelism, possibly because notmuch is sync and blocks, + // rewrite that with tokio::process:Command #[instrument(skip_all, fields(query=query))] async fn search<'ctx>( &self, @@ -328,18 +331,17 @@ impl QueryRoot { let query: Query = query.parse()?; info!("newsreader_query {query:?}"); - let newsreader_results = newsreader_search( + let newsreader_fut = newsreader_search( pool, newsreader_after, newsreader_before, first, last, &query, - ) - .await?; - let notmuch_results = - notmuch_search(nm, notmuch_after, notmuch_before, first, last, &query).await?; - let tantivy_results = tantivy_search( + ); + let notmuch_fut = + notmuch_search(nm, notmuch_after, notmuch_before, first, last, &query); + let tantivy_fut = tantivy_search( tantivy, pool, tantivy_after, @@ -347,8 +349,13 @@ impl QueryRoot { first, last, &query, - ) - .await?; + ); + let (newsreader_results, notmuch_results, tantivy_results) = + join!(newsreader_fut, notmuch_fut, tantivy_fut); + + let newsreader_results = newsreader_results?; + let notmuch_results = notmuch_results?; + let tantivy_results = tantivy_results?; info!( "newsreader_results ({}) notmuch_results ({}) tantivy_results ({})", newsreader_results.len(),