diff --git a/crates/index-scheduler/src/index_mapper/index_map.rs b/crates/index-scheduler/src/index_mapper/index_map.rs index 480dafa7c..efc11d6a2 100644 --- a/crates/index-scheduler/src/index_mapper/index_map.rs +++ b/crates/index-scheduler/src/index_mapper/index_map.rs @@ -1,4 +1,5 @@ use std::collections::BTreeMap; +use std::env::VarError; use std::path::Path; use std::time::Duration; @@ -300,9 +301,19 @@ fn create_or_open_index( enable_mdb_writemap: bool, map_size: usize, ) -> Result { + use std::str::FromStr; + let mut options = EnvOpenOptions::new(); options.map_size(clamp_to_page_size(map_size)); - options.max_readers(1024); + + let max_readers = match std::env::var("MEILI_INDEX_MAX_READERS") { + Ok(value) => u32::from_str(&value).unwrap(), + Err(VarError::NotPresent) => 100 * 1024, + Err(VarError::NotUnicode(value)) => { + panic!("Invalid unicode for the `MEILI_INDEX_MAX_READERS` env var: {value:?}") + } + }; + options.max_readers(max_readers); if enable_mdb_writemap { unsafe { options.flags(EnvFlags::WRITE_MAP) }; }