Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
client/cli/src/config: Warn on low file descriptor limit (#6956)
Browse files Browse the repository at this point in the history
* client/cli/src/config: Warn on low file descriptor limit

Substrate sets the soft file descriptor limit to the hard limit at
startup. In the case of the latter being low already (< 10_000) a
Substrate node under high demand might run into issues e.g. when opening
up new TCP connections or persisting data to the database.

With this commit a warn message is printed to stderr.

* client/cli/Cargo.toml: Update to fdlimit 0.2.0
  • Loading branch information
mxinden authored and bkchr committed Sep 18, 2020
1 parent 7d53c94 commit 539f4d2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ansi_term = "0.12.1"
lazy_static = "1.4.0"
tokio = { version = "0.2.21", features = [ "signal", "rt-core", "rt-threaded", "blocking" ] }
futures = "0.3.4"
fdlimit = "0.1.4"
fdlimit = "0.2.0"
libp2p = "0.24.0"
parity-scale-codec = "1.3.0"
hex = "0.4.2"
Expand Down
23 changes: 18 additions & 5 deletions client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
init_logger, DatabaseParams, ImportParams, KeystoreParams, NetworkParams, NodeKeyParams,
OffchainWorkerParams, PruningParams, SharedParams, SubstrateCli,
};
use log::warn;
use names::{Generator, Name};
use sc_client_api::execution_extensions::ExecutionStrategies;
use sc_service::config::{
Expand All @@ -38,9 +39,12 @@ use std::path::PathBuf;
/// The maximum number of characters for a node name.
pub(crate) const NODE_NAME_MAX_LENGTH: usize = 64;

/// default sub directory to store network config
/// Default sub directory to store network config.
pub(crate) const DEFAULT_NETWORK_CONFIG_PATH: &'static str = "network";

/// The recommended open file descriptor limit to be configured for the process.
const RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT: u64 = 10_000;

/// Default configuration values used by Substrate
///
/// These values will be used by [`CliConfiguritation`] to set
Expand Down Expand Up @@ -531,17 +535,26 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
///
/// This method:
///
/// 1. Set the panic handler
/// 2. Raise the FD limit
/// 3. Initialize the logger
/// 1. Sets the panic handler
/// 2. Initializes the logger
/// 3. Raises the FD limit
fn init<C: SubstrateCli>(&self) -> Result<()> {
let logger_pattern = self.log_filters()?;

sp_panic_handler::set(&C::support_url(), &C::impl_version());

fdlimit::raise_fd_limit();
init_logger(&logger_pattern);

if let Some(new_limit) = fdlimit::raise_fd_limit() {
if new_limit < RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT {
warn!(
"Low open file descriptor limit configured for the process. \
Current value: {:?}, recommended value: {:?}.",
new_limit, RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT,
);
}
}

Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/service/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tokio = "0.1.22"
futures01 = { package = "futures", version = "0.1.29" }
log = "0.4.8"
env_logger = "0.7.0"
fdlimit = "0.1.4"
fdlimit = "0.2.0"
parking_lot = "0.10.0"
sc-light = { version = "2.0.0-rc6", path = "../../light" }
sp-blockchain = { version = "2.0.0-rc6", path = "../../../primitives/blockchain" }
Expand Down

0 comments on commit 539f4d2

Please sign in to comment.