Accept the max readers param by env var and increase it

This commit is contained in:
Kerollmops 2025-01-28 14:48:01 +01:00
parent e20b91210d
commit 426ea5aa97
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F

View File

@ -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<Index> {
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) };
}