use tracing::debug; use crate::Result; /// This is needed for opening lots of file descriptors, which tends to /// happen more often when using RocksDB and making lots of federation /// connections at startup. The soft limit is usually 1024, and the hard /// limit is usually 512000; I've personally seen it hit >2000. /// /// * /// * #[cfg(unix)] pub fn maximize_fd_limit() -> Result<(), nix::errno::Errno> { use nix::sys::resource::{getrlimit, setrlimit, Resource::RLIMIT_NOFILE as NOFILE}; let (soft_limit, hard_limit) = getrlimit(NOFILE)?; if soft_limit < hard_limit { setrlimit(NOFILE, hard_limit, hard_limit)?; assert_eq!((hard_limit, hard_limit), getrlimit(NOFILE)?, "getrlimit != setrlimit"); debug!(to = hard_limit, from = soft_limit, "Raised RLIMIT_NOFILE",); } Ok(()) } /// Get the number of threads which could execute in parallel based on the /// hardware and administrative constraints of this system. This value should be /// used to hint the size of thread-pools and divide-and-conquer algorithms. /// /// * #[must_use] pub fn available_parallelism() -> usize { std::thread::available_parallelism() .expect("Unable to query for available parallelism.") .get() }