Skip to content

Commit

Permalink
adjust file descriptor limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce0203 committed Aug 19, 2024
1 parent 77b205a commit 72ddcb3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pumpkin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ uuid = { version = "1.10", features = ["serde", "v3"]}

tokio.workspace = true
rayon.workspace = true
libc = "0.2.157"
33 changes: 33 additions & 0 deletions pumpkin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ fn main() -> io::Result<()> {
let _profiler = dhat::Profiler::new_heap();
#[cfg(feature = "dhat-heap")]
println!("Using a memory profiler");

adjust_file_descriptor_limits();

let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
Expand Down Expand Up @@ -175,6 +178,36 @@ fn main() -> io::Result<()> {
})
}

fn adjust_file_descriptor_limits() {
let mut limits = libc::rlimit {
rlim_cur: 0,
rlim_max: 0,
};

if unsafe { libc::getrlimit(libc::RLIMIT_NOFILE, &mut limits) } != 0 {
panic!(
"Failed to get the current file handle limits {}",
std::io::Error::last_os_error()
);
};

let limit_before = limits.rlim_cur;
limits.rlim_cur = limits.rlim_max;

if unsafe { libc::setrlimit(libc::RLIMIT_NOFILE, &limits) } != 0 {
panic!(
"Failed to set the file handle limits {}",
std::io::Error::last_os_error()
);
}

log::debug!(
"file descriptor adjusted to {} from {}",
limits.rlim_max,
limit_before
);
}

fn next(current: &mut Token) -> Token {
let next = current.0;
current.0 += 1;
Expand Down

0 comments on commit 72ddcb3

Please sign in to comment.