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

feat: try increasing file descriptor soft limit for service at start #24

Merged
merged 1 commit into from
Apr 11, 2024
Merged
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
11 changes: 11 additions & 0 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ zeroize = { version = "1.7", features = ["derive"] }
url = "2.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
fdlimit = "0.3"

reqwest = { version = "0.11", default-features = false, features = ["json", "blocking"] }
jsonrpc-core = "18.0"
Expand Down
3 changes: 3 additions & 0 deletions src/cli/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::{
},
prelude::*,
result::{Error, Result},
utilities::try_raise_fd_limit,
};

#[derive(Parser)]
Expand Down Expand Up @@ -83,6 +84,8 @@ impl Args {
pub fn execute(&self) -> Result<()> {
log::info!("Starting the Bitcoin SPV service");

try_raise_fd_limit();

let storage = Storage::new(&self.data_dir)?;
if !storage.is_initialized()? {
let msg = format!(
Expand Down
3 changes: 3 additions & 0 deletions src/cli/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
components::{ApiServiceConfig, SpvService, Storage},
prelude::*,
result::{Error, Result},
utilities::try_raise_fd_limit,
};

#[derive(Parser)]
Expand Down Expand Up @@ -45,6 +46,8 @@ impl Args {
pub fn execute(&self) -> Result<()> {
log::info!("Starting the Bitcoin SPV service (readonly)");

try_raise_fd_limit();

let storage = Storage::new(&self.data_dir)?;
if !storage.is_initialized()? {
let msg = format!(
Expand Down
1 change: 0 additions & 1 deletion src/components/api_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ impl SpvRpc for SpvRpcImpl {
})?;
log::trace!(">>> tip height in local storage is {stg_tip_height}");

// TODO Define server errors with enum.
if stg_tip_height < target_height {
let desc = format!(
"target transaction is in header#{target_height}, \
Expand Down
2 changes: 2 additions & 0 deletions src/utilities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Utilities.

mod key;
mod platform;
mod type_id;
pub(crate) mod value_parsers;

pub(crate) use key::Key256Bits;
pub(crate) use platform::try_raise_fd_limit;
pub(crate) use type_id::calculate_type_id;
17 changes: 17 additions & 0 deletions src/utilities/platform.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Enhance the platform environment for continuously running services.

use fdlimit::{raise_fd_limit, Outcome};

pub fn try_raise_fd_limit() {
match raise_fd_limit() {
Ok(Outcome::LimitRaised { from, to }) => {
log::info!("raise file descriptor resource limit from {from} to {to}");
}
Ok(Outcome::Unsupported) => {
log::warn!("raising limit is not supported on this platform");
}
Err(err) => {
log::error!("failed to raise file descriptor resource limit, since {err}");
}
}
}