Compare commits

..

1 Commits

Author SHA1 Message Date
b3952e8b3d Only spawn request threads if necessary 2024-06-18 15:34:39 +02:00
2 changed files with 11 additions and 27 deletions

View File

@ -34,7 +34,7 @@ impl ThreadPoolNoAbort {
}
#[derive(Error, Debug)]
#[error("A panic occurred. Read the logs to find more information about it")]
#[error("A panic occured. Read the logs to find more information about it")]
pub struct PanicCatched;
#[derive(Default)]
@ -61,28 +61,9 @@ impl ThreadPoolNoAbortBuilder {
pub fn build(mut self) -> Result<ThreadPoolNoAbort, rayon::ThreadPoolBuildError> {
let pool_catched_panic = Arc::new(AtomicBool::new(false));
self.0 = self.0.panic_handler({
let catched_panic = Arc::downgrade(&pool_catched_panic);
move |_result| {
if let Some(catched_panic) = catched_panic.upgrade() {
catched_panic.store(true, Ordering::SeqCst)
}
}
let catched_panic = pool_catched_panic.clone();
move |_result| catched_panic.store(true, Ordering::SeqCst)
});
Ok(ThreadPoolNoAbort { thread_pool: self.0.build()?, pool_catched_panic })
}
}
#[cfg(test)]
mod test {
use std::sync::Arc;
use crate::ThreadPoolNoAbortBuilder;
#[test]
fn drop_pool() {
let pool = ThreadPoolNoAbortBuilder::new().num_threads(10).build().unwrap();
let caught_panic = Arc::downgrade(&pool.pool_catched_panic);
drop(pool);
assert_eq!(caught_panic.strong_count(), 0);
}
}

View File

@ -229,12 +229,15 @@ fn send_original_documents_data(
let documents_chunk_cloned = original_documents_chunk.clone();
let lmdb_writer_sx_cloned = lmdb_writer_sx.clone();
let request_threads = ThreadPoolNoAbortBuilder::new()
.num_threads(crate::vector::REQUEST_PARALLELISM)
.thread_name(|index| format!("embedding-request-{index}"))
.build()?;
let new_embedding_configs = settings_diff.new.embedding_configs.clone();
if settings_diff.reindex_vectors() || !settings_diff.settings_update_only() {
if (settings_diff.reindex_vectors() || !settings_diff.settings_update_only())
&& new_embedding_configs.get_default().is_some()
{
let request_threads = ThreadPoolNoAbortBuilder::new()
.num_threads(crate::vector::REQUEST_PARALLELISM)
.thread_name(|index| format!("embedding-request-{index}"))
.build()?;
let settings_diff = settings_diff.clone();
rayon::spawn(move || {
for (name, (embedder, prompt)) in settings_diff.new.embedding_configs.clone() {