Only spawn one search queue in actix-web

This commit is contained in:
Tamo 2024-08-27 17:19:25 +02:00
parent 9a756cf2c5
commit 41aa1e1424
5 changed files with 49 additions and 10 deletions

View file

@ -1,8 +1,10 @@
#![allow(dead_code)]
use std::marker::PhantomData;
use std::num::NonZeroUsize;
use std::path::Path;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use actix_http::body::MessageBody;
@ -11,6 +13,7 @@ use actix_web::http::StatusCode;
use byte_unit::{Byte, Unit};
use clap::Parser;
use meilisearch::option::{IndexerOpts, MaxMemory, MaxThreads, Opt};
use meilisearch::search_queue::SearchQueue;
use meilisearch::{analytics, create_app, setup_meilisearch, SubscriberForSecondLayer};
use once_cell::sync::Lazy;
use tempfile::TempDir;
@ -53,7 +56,13 @@ impl Server<Owned> {
let options = default_settings(dir.path());
let (index_scheduler, auth) = setup_meilisearch(&options).unwrap();
let service = Service { index_scheduler, auth, options, api_key: None };
let service = Service {
index_scheduler,
auth,
search_queue: Self::new_search_queue(&options),
options,
api_key: None,
};
Server { service, _dir: Some(dir), _marker: PhantomData }
}
@ -68,7 +77,13 @@ impl Server<Owned> {
options.master_key = Some("MASTER_KEY".to_string());
let (index_scheduler, auth) = setup_meilisearch(&options).unwrap();
let service = Service { index_scheduler, auth, options, api_key: None };
let service = Service {
index_scheduler,
auth,
search_queue: Self::new_search_queue(&options),
options,
api_key: None,
};
Server { service, _dir: Some(dir), _marker: PhantomData }
}
@ -81,7 +96,13 @@ impl Server<Owned> {
pub async fn new_with_options(options: Opt) -> Result<Self, anyhow::Error> {
let (index_scheduler, auth) = setup_meilisearch(&options)?;
let service = Service { index_scheduler, auth, options, api_key: None };
let service = Service {
index_scheduler,
auth,
search_queue: Self::new_search_queue(&options),
options,
api_key: None,
};
Ok(Server { service, _dir: None, _marker: PhantomData })
}
@ -256,6 +277,12 @@ impl Server<Shared> {
}
impl<State> Server<State> {
fn new_search_queue(options: &Opt) -> Arc<SearchQueue> {
let search_queue =
SearchQueue::new(options.experimental_search_queue_size, NonZeroUsize::new(1).unwrap());
Arc::new(search_queue)
}
pub async fn init_web_app(
&self,
) -> impl actix_web::dev::Service<
@ -279,6 +306,7 @@ impl<State> Server<State> {
actix_web::test::init_service(create_app(
self.service.index_scheduler.clone().into(),
self.service.auth.clone().into(),
self.service.search_queue.clone().into(),
self.service.options.clone(),
(route_layer_handle, stderr_layer_handle),
analytics::MockAnalytics::new(&self.service.options),