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

Add new flag for maximum file descriptors in rocksdb. #2386

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

AurelienFT
Copy link
Contributor

Linked Issues/PRs

Resolves: #2093

Description

Add a flag to define the maximum number of file descriptors that RocksDB can use. By default it's half of the OS limit.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

Copy link
Member

@MitchTurner MitchTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Left some thoughts.

bin/fuel-core/src/cli/run.rs Outdated Show resolved Hide resolved
crates/fuel-core/src/state/rocks_db.rs Outdated Show resolved Hide resolved
@@ -30,7 +30,7 @@ pub struct Command {
#[clap(
long = "rocksdb-max-fds",
env,
default_value = getrlimit(Resource::NOFILE).map(|(_, hard)| i32::try_from(hard.saturating_div(2)).unwrap_or(i32::MAX)).unwrap().to_string()
default_value = getrlimit(Resource::NOFILE).map(|(_, hard)| i32::try_from(hard.saturating_div(2)).unwrap_or(i32::MAX)).expect("Failed to get OS max file descriptors.").to_string()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Sorry. I mean specify why it shouldn't panic:

We recommend that expect messages are used to describe the reason you expect the Result should be Ok.

As suggested by the docs:
https://doc.rust-lang.org/std/result/enum.Result.html#method.expect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't correctly understood you first message and didn't know about this convention. Happy to learn :D Ty

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh didn't know this. I've definitely done a bunch of .expect("failed to blah blah") 😅 TIL

@AurelienFT AurelienFT requested review from MitchTurner and a team October 23, 2024 19:20
@AurelienFT AurelienFT self-assigned this Oct 24, 2024
netrome
netrome previously approved these changes Oct 24, 2024
Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me. I think this would be even better if we used an Option<u32> instead of an i32 where -1 has a special meaning.

Comment on lines +28 to +29
/// If defined as -1 no limit will be applied and will use the OS limits.
/// If not defined the system default divided by two is used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for using -1 to mean no limit as opposed to take an Option<u32>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the default value used by RocksDB for no limit that's why they are a i32.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we want to have different behaviour between :

  • No defined value which will be using OS divided by two
  • and max value of the system which is -1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, fair enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this limit should generally be Option<u32>, but this can only represent two states, not the three we need. Let's keep it like that for the sake of simplicity. But we should maybe sanitize this value and not allow -2, -3, etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RocksDB doesn't seems to consider these values as error : #2386 (comment)

But we can do. I don't think it's very useful because it doesn't creates any problem and the only reason to tryy a -2 is to tryy to make a problem.

#[clap(
long = "rocksdb-max-fds",
env,
default_value = getrlimit(Resource::NOFILE).map(|(_, hard)| i32::try_from(hard.saturating_div(2)).unwrap_or(i32::MAX)).expect("Our supported platforms should return max FD.").to_string()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite long to be in an attribute. How about breaking this out to a helper function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#[clap(
long = "rocksdb-max-fds",
env,
default_value = getrlimit(Resource::NOFILE).map(|(_, hard)| i32::try_from(hard.saturating_div(2)).unwrap_or(i32::MAX)).expect("Our supported platforms should return max FD.").to_string()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#[clap(
long = "rocksdb-max-fds",
env,
default_value = getrlimit(Resource::NOFILE).map(|(_, hard)| i32::try_from(hard.saturating_div(2)).unwrap_or(i32::MAX)).expect("Our supported platforms should return max FD.").to_string()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@MitchTurner
Copy link
Member

Ready to approve after those last changes are made.

@@ -75,6 +75,7 @@ impl BenchDb {
tmp_dir.path(),
None,
Default::default(),
-1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few places that we're still using -1. Is that okay?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have let in benches because benches didn't used the test value before and I don't want them to be slowed down by a new limit (maybe it don't change anything but there is no risk for benches I think)

@@ -19,11 +23,28 @@ pub struct Command {
)]
pub database_path: PathBuf,

/// Defines a specific number of file descriptors that RocksDB can use.
///
/// If defined as -1 no limit will be applied and will use the OS limits.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the behavior if they use -2 or any other negative value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't found anything about it in rocksdb source code in Rust or C, so I tried myself in a test and it seems to work without issues. Maybe this is the code : https://github.com/facebook/rocksdb/blob/8b38d4b4006ca9fd49432ccc16d9911919870dd2/db/db_impl/db_impl_open.cc#L57 I'm not sure that I fully understand this code but fore me if the value is -2 it will be clamped to 20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants