node: Increase process ulimit on start
Users have been having issues with the process soft file limit. We set that to a reasonably high value to avoid problems.
This commit is contained in:
parent
76302ffec0
commit
045b3e7175
|
|
@ -2361,6 +2361,7 @@ dependencies = [
|
|||
"cyphernet",
|
||||
"fastrand",
|
||||
"git2",
|
||||
"libc",
|
||||
"localtime",
|
||||
"log",
|
||||
"multibase",
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ $ rad config
|
|||
"routingMaxAge": 604800,
|
||||
"gossipMaxAge": 1209600,
|
||||
"fetchConcurrency": 1,
|
||||
"maxOpenFiles": 4096,
|
||||
"rate": {
|
||||
"inbound": {
|
||||
"fillRate": 0.2,
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ mod routes {
|
|||
"routingMaxAge": 604800,
|
||||
"gossipMaxAge": 1209600,
|
||||
"fetchConcurrency": 1,
|
||||
"maxOpenFiles": 4096,
|
||||
"rate": {
|
||||
"inbound": {
|
||||
"fillRate": 0.2,
|
||||
|
|
|
|||
|
|
@ -108,6 +108,10 @@ fn execute() -> anyhow::Result<()> {
|
|||
config.listen.clone()
|
||||
};
|
||||
|
||||
if let Err(e) = radicle::io::set_file_limit(config.limits.max_open_files as u64) {
|
||||
log::warn!(target: "node", "Unable to set process open file limit: {e}");
|
||||
}
|
||||
|
||||
let (notify, signals) = chan::bounded(1);
|
||||
signals::install(notify)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ cyphernet = { version = "0.4.1", features = ["tor", "dns", "p2p-ed25519"] }
|
|||
fastrand = { version = "2.0.0" }
|
||||
multibase = { version = "0.9.1" }
|
||||
localtime = { version = "1.2.0", features = ["serde"] }
|
||||
libc = { version = "0.2" }
|
||||
log = { version = "0.4.17", features = ["std"] }
|
||||
nonempty = { version = "0.8.1", features = ["serialize"] }
|
||||
once_cell = { version = "1.13" }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
use std::io;
|
||||
|
||||
use libc::{getrlimit, rlimit, setrlimit, RLIMIT_NOFILE};
|
||||
|
||||
/// Sets the open file limit to the given value, or the maximum allowed value.
|
||||
pub fn set_file_limit(n: u64) -> io::Result<u64> {
|
||||
let mut rlim = rlimit {
|
||||
rlim_cur: 0, // Initial soft limit value
|
||||
rlim_max: 0, // Initial hard limit value
|
||||
};
|
||||
// Get the current limits.
|
||||
unsafe {
|
||||
if getrlimit(RLIMIT_NOFILE, &mut rlim) != 0 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
// Set the soft limit to the given value, up to the hard limit.
|
||||
rlim.rlim_cur = n.min(rlim.rlim_max);
|
||||
unsafe {
|
||||
if setrlimit(RLIMIT_NOFILE, &rlim as *const rlimit) != 0 {
|
||||
return Err(io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
Ok(rlim.rlim_cur)
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ pub mod collections;
|
|||
pub mod explorer;
|
||||
pub mod git;
|
||||
pub mod identity;
|
||||
pub mod io;
|
||||
#[cfg(feature = "logger")]
|
||||
pub mod logger;
|
||||
pub mod node;
|
||||
|
|
|
|||
|
|
@ -80,6 +80,8 @@ pub struct Limits {
|
|||
pub gossip_max_age: LocalDuration,
|
||||
/// Maximum number of concurrent fetches per per connection.
|
||||
pub fetch_concurrency: usize,
|
||||
/// Maximum number of open files.
|
||||
pub max_open_files: usize,
|
||||
/// Rate limitter settings.
|
||||
#[serde(default)]
|
||||
pub rate: RateLimits,
|
||||
|
|
@ -92,6 +94,7 @@ impl Default for Limits {
|
|||
routing_max_age: LocalDuration::from_mins(7 * 24 * 60), // One week
|
||||
gossip_max_age: LocalDuration::from_mins(2 * 7 * 24 * 60), // Two weeks
|
||||
fetch_concurrency: 1,
|
||||
max_open_files: 4096,
|
||||
rate: RateLimits::default(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue