Skip to content

Commit

Permalink
Tokio needs descriptors for timers and more
Browse files Browse the repository at this point in the history
  • Loading branch information
jedisct1 committed Jun 24, 2022
1 parent ae5195c commit 936ff9f
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,27 +523,23 @@ fn set_limits(config: &Config) -> Result<(), Error> {
#[cfg(target_family = "unix")]
fn set_limits(config: &Config) -> Result<(), Error> {
use rlimit::Resource;
let nb_descriptors = 2u32
let nb_descriptors = 4u32
.saturating_mul(
config
.tcp_max_active_connections
.saturating_add(config.udp_max_active_connections)
.saturating_add(config.listen_addrs.len() as u32),
)
.saturating_add(16);
if Resource::NOFILE
.set(nb_descriptors as _, nb_descriptors as _)
.is_err()
{
let (_soft, hard) = Resource::NOFILE.get()?;
if nb_descriptors as u64 > hard as u64 {
warn!(
"Unable to set the number of open files to {}. The hard limit is {}",
nb_descriptors, hard
);
}
Resource::NOFILE.set(hard, hard)?;
let (_soft, hard) = Resource::NOFILE.get()?;
if nb_descriptors as u64 > hard as u64 {
warn!(
"Unable to set the number of open files to {}. The hard limit is {}",
nb_descriptors, hard
);
}
let nb_descriptors = std::cmp::max(nb_descriptors as _, hard);
Resource::NOFILE.set(nb_descriptors, nb_descriptors)?;
Ok(())
}

Expand Down

0 comments on commit 936ff9f

Please sign in to comment.