Skip to content

Commit

Permalink
blockstore: Make metrics reporting service more responsive to exit fl…
Browse files Browse the repository at this point in the history
…ag (solana-labs#3976)

The exit flag may get set when someone wishes to stop their validator.
This service does check if the exit flag has been set, but it only
checks every 10 seconds (the metrics reporting interval).

This change keeps the metrics reporting interval at 10s, but makes the
service check if the exit flag has been set every 1s
  • Loading branch information
steviez authored Dec 9, 2024
1 parent 889639b commit 6cafb1d
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions ledger/src/blockstore_metric_report_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use {
Arc,
},
thread::{self, Builder, JoinHandle},
time::Duration,
time::{Duration, Instant},
},
};

// Determines how often we report blockstore metrics under
// BlockstoreMetricReportService. Note that there are other blockstore
// metrics that are reported outside BlockstoreMetricReportService.
const BLOCKSTORE_METRICS_REPORT_PERIOD_MILLIS: u64 = 10000;
const BLOCKSTORE_METRICS_REPORT_INTERVAL: Duration = Duration::from_secs(10);

pub struct BlockstoreMetricReportService {
t_cf_metric: JoinHandle<()>,
Expand All @@ -26,15 +26,24 @@ impl BlockstoreMetricReportService {
pub fn new(blockstore: Arc<Blockstore>, exit: Arc<AtomicBool>) -> Self {
let t_cf_metric = Builder::new()
.name("solRocksCfMtrcs".to_string())
.spawn(move || loop {
if exit.load(Ordering::Relaxed) {
break;
.spawn(move || {
info!("BlockstoreMetricReportService has started");
let mut last_report_time = Instant::now();
loop {
if exit.load(Ordering::Relaxed) {
break;
}

if last_report_time.elapsed() > BLOCKSTORE_METRICS_REPORT_INTERVAL {
blockstore.submit_rocksdb_cf_metrics_for_all_cfs();
blockstore.report_rpc_api_metrics();

last_report_time = Instant::now();
}

thread::sleep(Duration::from_secs(1));
}
thread::sleep(Duration::from_millis(
BLOCKSTORE_METRICS_REPORT_PERIOD_MILLIS,
));
blockstore.submit_rocksdb_cf_metrics_for_all_cfs();
blockstore.report_rpc_api_metrics();
info!("BlockstoreMetricReportService has stopped");
})
.unwrap();
Self { t_cf_metric }
Expand Down

0 comments on commit 6cafb1d

Please sign in to comment.