feat: add default max readers 32000 (#3465)

This commit is contained in:
Matthias Seitz
2023-06-29 17:01:47 +02:00
committed by GitHub
parent b7c977765c
commit ee322769c9
3 changed files with 21 additions and 9 deletions

View File

@ -11,11 +11,16 @@ use reth_libmdbx::{
SyncMode, RO, RW,
};
use std::{ops::Deref, path::Path};
use tx::Tx;
pub mod cursor;
pub mod tx;
use tx::Tx;
const GIGABYTE: usize = 1024 * 1024 * 1024;
const TERABYTE: usize = GIGABYTE * 1024;
/// MDBX allows up to 32767 readers (`MDBX_READERS_LIMIT`), but we limit it to slightly below that
const DEFAULT_MAX_READERS: u64 = 32_000;
/// Environment used when opening a MDBX environment. RO/RW.
#[derive(Debug)]
@ -52,9 +57,6 @@ impl<E: EnvironmentKind> Database for Env<E> {
}
}
const GIGABYTE: usize = 1024 * 1024 * 1024;
const TERABYTE: usize = GIGABYTE * 1024;
impl<E: EnvironmentKind> Env<E> {
/// Opens the database at the specified path with the given `EnvKind`.
///
@ -85,6 +87,8 @@ impl<E: EnvironmentKind> Env<E> {
coalesce: true,
..Default::default()
})
// configure more readers
.set_max_readers(DEFAULT_MAX_READERS)
.open(path)
.map_err(|e| DatabaseError::FailedToOpen(e.into()))?,
};

View File

@ -114,7 +114,7 @@ pub fn init_db<P: AsRef<std::path::Path>>(path: P) -> eyre::Result<DatabaseEnv>
}
#[cfg(feature = "mdbx")]
{
let db = Env::<WriteMap>::open(rpath, EnvKind::RW)?;
let db = DatabaseEnv::open(rpath, EnvKind::RW)?;
db.create_tables()?;
Ok(db)
}

View File

@ -6,7 +6,6 @@ use crate::{
Mode, Transaction, TransactionKind,
};
use byteorder::{ByteOrder, NativeEndian};
use libc::c_uint;
use mem::size_of;
use std::{
ffi::CString,
@ -376,7 +375,7 @@ where
E: EnvironmentKind,
{
flags: EnvironmentFlags,
max_readers: Option<c_uint>,
max_readers: Option<u64>,
max_dbs: Option<u64>,
rp_augment_limit: Option<u64>,
loose_limit: Option<u64>,
@ -453,6 +452,15 @@ where
}
}
// set max readers if specified
if let Some(max_readers) = self.max_readers {
mdbx_result(ffi::mdbx_env_set_option(
env,
ffi::MDBX_opt_max_readers,
max_readers,
))?;
}
#[cfg(unix)]
fn path_to_bytes<P: AsRef<Path>>(path: P) -> Vec<u8> {
use std::os::unix::ffi::OsStrExt;
@ -544,7 +552,7 @@ where
/// This defines the number of slots in the lock table that is used to track readers in the
/// the environment. The default is 126. Starting a read-only transaction normally ties a lock
/// table slot to the [Transaction] object until it or the [Environment] object is destroyed.
pub fn set_max_readers(&mut self, max_readers: c_uint) -> &mut Self {
pub fn set_max_readers(&mut self, max_readers: u64) -> &mut Self {
self.max_readers = Some(max_readers);
self
}