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

service: storage monitor added #13082

Merged
merged 27 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
34577eb
service: storage monitor added
michalkucharczyk Jan 5, 2023
b5f970b
Merge remote-tracking branch 'origin/master' into mku-storage-monitor
michalkucharczyk Jan 6, 2023
37bbba4
Cargo.lock updated
michalkucharczyk Jan 6, 2023
ba0f28f
misspell
michalkucharczyk Jan 9, 2023
e360685
fs events throttling added
michalkucharczyk Jan 9, 2023
fd5679f
minor updates
michalkucharczyk Jan 9, 2023
217234f
filter out non mutating events
michalkucharczyk Jan 9, 2023
8b3310b
misspell
michalkucharczyk Jan 9, 2023
931339c
".git/.scripts/commands/fmt/fmt.sh"
Jan 10, 2023
c200159
Update client/service/src/storage_monitor.rs
michalkucharczyk Jan 12, 2023
f5501f2
storage-monitor crate added
michalkucharczyk Jan 13, 2023
45171dc
cleanup: configuration + service builder
michalkucharczyk Jan 13, 2023
f346394
storage_monitor in custom service (wip)
michalkucharczyk Jan 13, 2023
eb49400
copy-paste bad desc fixed
michalkucharczyk Jan 13, 2023
8619766
notify removed
michalkucharczyk Jan 16, 2023
a0cd44d
storage_monitor added to node
michalkucharczyk Jan 16, 2023
d3f143c
Merge remote-tracking branch 'origin/master' into mku-storage-monitor
Jan 16, 2023
a79af9a
fix for clippy
michalkucharczyk Jan 16, 2023
00e7264
publish = false
michalkucharczyk Jan 16, 2023
6c3eb1c
Update bin/node/cli/src/command.rs
michalkucharczyk Jan 17, 2023
58dcf55
Apply suggestions from code review
michalkucharczyk Jan 23, 2023
95b576b
crate name: storage-monitor -> sc-storage-monitor
michalkucharczyk Jan 23, 2023
0b8697e
error handling improved
michalkucharczyk Jan 23, 2023
c0fc2ca
Merge remote-tracking branch 'origin/master' into mku-storage-monitor
michalkucharczyk Jan 23, 2023
de35dda
Apply suggestions from code review
michalkucharczyk Jan 23, 2023
4e32f3d
publish=false removed
michalkucharczyk Jan 24, 2023
0578588
Merge remote-tracking branch 'origin/master' into mku-storage-monitor
Jan 24, 2023
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
83 changes: 83 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 bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
base_path: Some(base_path),
informant_output_format: Default::default(),
wasm_runtime_overrides: None,
available_storage_threshold: 1000,
};

node_cli::service::new_full_base(config, false, |_, _| ())
Expand Down
1 change: 1 addition & 0 deletions bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
base_path: Some(base_path),
informant_output_format: Default::default(),
wasm_runtime_overrides: None,
available_storage_threshold: 1000,
};

node_cli::service::new_full_base(config, false, |_, _| ()).expect("Creates node")
Expand Down
11 changes: 11 additions & 0 deletions client/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
.unwrap_or_else(|| Ok((None, KeystoreConfig::InMemory)))
}

/// Get the database available storage space threshold.
///
/// By default this is retrieved from `DatabaseParams` if it is available.
fn database_storage_threshold(&self) -> Result<u64> {
Ok(self
.database_params()
.map(|x| x.database_storage_threshold())
.unwrap_or_default())
}

/// Get the database cache size.
///
/// By default this is retrieved from `DatabaseParams` if it is available. Otherwise its `None`.
Expand Down Expand Up @@ -562,6 +572,7 @@ pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized {
base_path: Some(base_path),
informant_output_format: Default::default(),
runtime_cache_size,
available_storage_threshold: self.database_storage_threshold()?,
})
}

Expand Down
15 changes: 13 additions & 2 deletions client/cli/src/params/database_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::arg_enums::Database;
use clap::Args;

/// Parameters for block import.
/// Parameters for database
#[derive(Debug, Clone, PartialEq, Args)]
pub struct DatabaseParams {
/// Select database backend to use.
Expand All @@ -29,10 +29,16 @@ pub struct DatabaseParams {
/// Limit the memory the database cache can use.
#[arg(long = "db-cache", value_name = "MiB")]
pub database_cache_size: Option<usize>,

/// Required available space on database storage. If available space for DB storage drops below
/// the given threshold, node will be gracefully terminated. If `0` is given monitoring will be
/// disabled.
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
#[arg(long = "db-storage-threshold", value_name = "MB", default_value_t = 1000)]
pub database_storage_threshold: u64,
}

impl DatabaseParams {
/// Limit the memory the database cache can use.
/// Database backend
pub fn database(&self) -> Option<Database> {
self.database
}
Expand All @@ -41,4 +47,9 @@ impl DatabaseParams {
pub fn database_cache_size(&self) -> Option<usize> {
self.database_cache_size
}

/// Available storage space threshold
pub fn database_storage_threshold(&self) -> u64 {
self.database_storage_threshold
}
}
1 change: 1 addition & 0 deletions client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ mod tests {
base_path: None,
informant_output_format: Default::default(),
runtime_cache_size: 2,
available_storage_threshold: 1000,
},
runtime,
)
Expand Down
2 changes: 2 additions & 0 deletions client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ tokio = { version = "1.22.0", features = ["time", "rt-multi-thread", "parking_lo
tempfile = "3.1.0"
directories = "4.0.1"
static_init = "1.0.3"
nix = { version = "0.26.1", features = ["fs"] }
notify = "5.0.0"

[dev-dependencies]
substrate-test-runtime-client = { version = "2.0.0", path = "../../test-utils/runtime/client" }
Expand Down
14 changes: 12 additions & 2 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ use crate::{
config::{Configuration, KeystoreConfig, PrometheusConfig},
error::Error,
metrics::MetricsService,
start_rpc_servers, BuildGenesisBlock, GenesisBlockBuilder, RpcHandlers, SpawnTaskHandle,
TaskManager, TransactionPoolAdapter,
start_rpc_servers,
storage_monitor::StorageMonitorService,
BuildGenesisBlock, GenesisBlockBuilder, RpcHandlers, SpawnTaskHandle, TaskManager,
TransactionPoolAdapter,
};
use futures::{channel::oneshot, future::ready, FutureExt, StreamExt};
use jsonrpsee::RpcModule;
Expand Down Expand Up @@ -534,6 +536,14 @@ where
metrics_service.run(client.clone(), transaction_pool.clone(), network.clone()),
);

if let Some(storage_monitor_service) = StorageMonitorService::new_for_config(&config)? {
task_manager.spawn_essential_handle().spawn(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is statvfs syscall called inside, so maybe this should be spawn_blocking?

Copy link
Member

Choose a reason for hiding this comment

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

Any idea how long this takes?

Copy link
Contributor Author

@michalkucharczyk michalkucharczyk Jan 16, 2023

Choose a reason for hiding this comment

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

on my pc test running for few minutes: typically few µs, sometimes several dozes µs, rarely hundreds.

Histogram (in nanoseconds):

# Min = 870
# Max = 124399
#
# Mean = 972.8840301798245
# Standard deviation = 243.63354324050133
# Variance = 59357.30339192123
#
# Each ∎ is a count of 2946629
#
   870 ..  13223 [ 147331481 ]: ∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
 13223 ..  25576 [      1237 ]: 
 25576 ..  37929 [        48 ]: 
 37929 ..  50282 [        18 ]: 
 50282 ..  62635 [        15 ]: 
 62635 ..  74988 [         7 ]: 
 74988 ..  87341 [         3 ]: 
 87341 ..  99694 [         2 ]: 
 99694 .. 112047 [         1 ]: 
112047 .. 124400 [         3 ]: 

Still, even it is low on average, sometimes it can block for a little bit longer (0.12ms). Probably non-blocking spawn would be fine here. Let's give it a try.

"storage-monitor",
None,
storage_monitor_service.run(),
)
}

let rpc_id_provider = config.rpc_id_provider.take();

// jsonrpsee RPC
Expand Down
3 changes: 3 additions & 0 deletions client/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ pub struct Configuration {
pub informant_output_format: sc_informant::OutputFormat,
/// Maximum number of different runtime versions that can be cached.
pub runtime_cache_size: u8,
/// Threshold (in megabytes) for available storage space associated with `base_path`. `0` means
/// no storage monitoring.
pub available_storage_threshold: u64,
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
}

/// Type for tasks spawned by the executor.
Expand Down
1 change: 1 addition & 0 deletions client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub mod client;
#[cfg(not(feature = "test-helpers"))]
mod client;
mod metrics;
mod storage_monitor;
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
mod task_manager;

use std::{collections::HashMap, net::SocketAddr};
Expand Down
Loading