Skip to content

Commit

Permalink
Add 1ms sleep to metrics to provide breathing room during metrics col…
Browse files Browse the repository at this point in the history
…lection.
  • Loading branch information
cryptoquick committed Nov 24, 2023
1 parent af40bc0 commit 9faa9cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/bin/bitmaskd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ async fn periodic_metrics() -> Result<()> {
let dir = std::path::Path::new(&path);
fs::create_dir_all(dir).await?;

let metrics = metrics(dir)?;
let metrics = metrics(dir).await?;
let metrics_json = serde_json::to_string_pretty(&metrics)?;
let metrics_csv = metrics_csv(metrics);

Expand Down
11 changes: 9 additions & 2 deletions src/carbonado/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
use std::{collections::BTreeMap, path::Path, time::SystemTime};
use std::{
collections::BTreeMap,
path::Path,
time::{Duration as StdDuration, SystemTime},
};

use anyhow::Result;
use chrono::{DateTime, Duration, NaiveDate, Utc};
use serde::{Deserialize, Serialize};
use tokio::time::sleep;
use walkdir::WalkDir;

#[derive(Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -37,7 +42,7 @@ const NETWORK_TOTAL: &str = "total";
const NETWORK_RGB_STOCKS: &str = "rgb_stocks";
const NETWORK_RGB_TRANSFER_FILES: &str = "rgb_transfer_files";

pub fn metrics(dir: &Path) -> Result<MetricsResponse> {
pub async fn metrics(dir: &Path) -> Result<MetricsResponse> {
let mut response = MetricsResponse::default();

response
Expand Down Expand Up @@ -136,6 +141,8 @@ pub fn metrics(dir: &Path) -> Result<MetricsResponse> {
rgb_transfer_files += 1;
}
}

sleep(StdDuration::from_millis(1)).await;
}

*response
Expand Down

0 comments on commit 9faa9cc

Please sign in to comment.