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

Commit 539f4d2

Browse files
mxindenbkchr
authored andcommitted
client/cli/src/config: Warn on low file descriptor limit (#6956)
* 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
1 parent 7d53c94 commit 539f4d2

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ansi_term = "0.12.1"
2222
lazy_static = "1.4.0"
2323
tokio = { version = "0.2.21", features = [ "signal", "rt-core", "rt-threaded", "blocking" ] }
2424
futures = "0.3.4"
25-
fdlimit = "0.1.4"
25+
fdlimit = "0.2.0"
2626
libp2p = "0.24.0"
2727
parity-scale-codec = "1.3.0"
2828
hex = "0.4.2"

client/cli/src/config.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::{
2424
init_logger, DatabaseParams, ImportParams, KeystoreParams, NetworkParams, NodeKeyParams,
2525
OffchainWorkerParams, PruningParams, SharedParams, SubstrateCli,
2626
};
27+
use log::warn;
2728
use names::{Generator, Name};
2829
use sc_client_api::execution_extensions::ExecutionStrategies;
2930
use sc_service::config::{
@@ -38,9 +39,12 @@ use std::path::PathBuf;
3839
/// The maximum number of characters for a node name.
3940
pub(crate) const NODE_NAME_MAX_LENGTH: usize = 64;
4041

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

45+
/// The recommended open file descriptor limit to be configured for the process.
46+
const RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT: u64 = 10_000;
47+
4448
/// Default configuration values used by Substrate
4549
///
4650
/// These values will be used by [`CliConfiguritation`] to set
@@ -531,17 +535,26 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
531535
///
532536
/// This method:
533537
///
534-
/// 1. Set the panic handler
535-
/// 2. Raise the FD limit
536-
/// 3. Initialize the logger
538+
/// 1. Sets the panic handler
539+
/// 2. Initializes the logger
540+
/// 3. Raises the FD limit
537541
fn init<C: SubstrateCli>(&self) -> Result<()> {
538542
let logger_pattern = self.log_filters()?;
539543

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

542-
fdlimit::raise_fd_limit();
543546
init_logger(&logger_pattern);
544547

548+
if let Some(new_limit) = fdlimit::raise_fd_limit() {
549+
if new_limit < RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT {
550+
warn!(
551+
"Low open file descriptor limit configured for the process. \
552+
Current value: {:?}, recommended value: {:?}.",
553+
new_limit, RECOMMENDED_OPEN_FILE_DESCRIPTOR_LIMIT,
554+
);
555+
}
556+
}
557+
545558
Ok(())
546559
}
547560
}

client/service/test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tokio = "0.1.22"
1818
futures01 = { package = "futures", version = "0.1.29" }
1919
log = "0.4.8"
2020
env_logger = "0.7.0"
21-
fdlimit = "0.1.4"
21+
fdlimit = "0.2.0"
2222
parking_lot = "0.10.0"
2323
sc-light = { version = "2.0.0-rc6", path = "../../light" }
2424
sp-blockchain = { version = "2.0.0-rc6", path = "../../../primitives/blockchain" }

0 commit comments

Comments
 (0)