Skip to content

Commit

Permalink
Merge pull request #4328 from chenyukang/yukang-add-process-block-int…
Browse files Browse the repository at this point in the history
…erval

Add ckb_block_process_duration in metric for monitoring and testing
  • Loading branch information
chenyukang authored Jan 26, 2024
2 parents 952153b + 10950bb commit 8e81649
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use ckb_verification_contextual::{ContextualBlockVerifier, VerifyContext};
use ckb_verification_traits::{Switch, Verifier};
use std::collections::{HashSet, VecDeque};
use std::sync::Arc;
use std::time::Instant;
use std::{cmp, thread};

type ProcessBlockRequest = Request<(Arc<BlockView>, Switch), Result<bool, Error>>;
Expand Down Expand Up @@ -236,9 +237,17 @@ impl ChainService {
select! {
recv(process_block_receiver) -> msg => match msg {
Ok(Request { responder, arguments: (block, verify) }) => {
let instant = Instant::now();

let _ = tx_control.suspend_chunk_process();
let _ = responder.send(self.process_block(block, verify));
let _ = tx_control.continue_chunk_process();

if let Some(metrics) = ckb_metrics::handle() {
metrics
.ckb_block_process_duration
.observe(instant.elapsed().as_secs_f64());
}
},
_ => {
error!("process_block_receiver closed");
Expand Down
7 changes: 7 additions & 0 deletions util/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub struct Metrics {
pub ckb_relay_transaction_short_id_collide: IntCounter,
/// Histogram for relay compact block verify duration
pub ckb_relay_cb_verify_duration: Histogram,
/// Histogram for block process duration
pub ckb_block_process_duration: Histogram,
/// Counter for relay compact block transaction count
pub ckb_relay_cb_transaction_count: IntCounter,
/// Counter for relay compact block reconstruct ok
Expand Down Expand Up @@ -97,6 +99,11 @@ static METRICS: once_cell::sync::Lazy<Metrics> = once_cell::sync::Lazy::new(|| M
"The CKB relay compact block verify duration"
)
.unwrap(),
ckb_block_process_duration: register_histogram!(
"ckb_block_process_duration",
"The CKB block process duration"
)
.unwrap(),
ckb_relay_cb_transaction_count: register_int_counter!(
"ckb_relay_cb_transaction_count",
"The CKB relay compact block transaction count"
Expand Down

0 comments on commit 8e81649

Please sign in to comment.