Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust file descriptor limits #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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