Skip to content

Commit

Permalink
[Metric] export transaction sizes by transaction kinds (MystenLabs#17554
Browse files Browse the repository at this point in the history
)

## Description 

This helps us understand the size of transactions sent through
consensus.

## Test plan 

CI

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
mwtian authored May 7, 2024
1 parent aeb37cd commit b1540cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
28 changes: 18 additions & 10 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use parking_lot::Mutex;
use prometheus::{
register_histogram_vec_with_registry, register_histogram_with_registry,
register_int_counter_vec_with_registry, register_int_counter_with_registry,
register_int_gauge_vec_with_registry, register_int_gauge_with_registry, Histogram, IntCounter,
IntCounterVec, IntGauge, IntGaugeVec, Registry,
register_int_gauge_vec_with_registry, register_int_gauge_with_registry, Histogram,
HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec, Registry,
};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -264,8 +264,8 @@ pub struct AuthorityMetrics {
post_processing_total_failures: IntCounter,

/// Consensus handler metrics
pub consensus_handler_processed_bytes: IntCounter,
pub consensus_handler_processed: IntCounterVec,
pub consensus_handler_transaction_sizes: HistogramVec,
pub consensus_handler_num_low_scoring_authorities: IntGauge,
pub consensus_handler_scores: IntGaugeVec,
pub consensus_handler_deferred_transactions: IntCounter,
Expand Down Expand Up @@ -305,9 +305,11 @@ pub struct AuthorityMetrics {
pub execution_rate_tracker: Arc<Mutex<RateTracker>>,
}

// Override default Prom buckets for positive numbers in 0-50k range
// Override default Prom buckets for positive numbers in 0-10M range
const POSITIVE_INT_BUCKETS: &[f64] = &[
1., 2., 5., 10., 20., 50., 100., 200., 500., 1000., 2000., 5000., 10000., 20000., 50000.,
1., 2., 5., 7., 10., 20., 50., 70., 100., 200., 500., 700., 1000., 2000., 5000., 7000., 10000.,
20000., 50000., 70000., 100000., 200000., 500000., 700000., 1000000., 2000000., 5000000.,
7000000., 10000000.,
];

const LATENCY_SEC_BUCKETS: &[f64] = &[
Expand Down Expand Up @@ -627,13 +629,19 @@ impl AuthorityMetrics {
registry,
)
.unwrap(),
consensus_handler_processed_bytes: register_int_counter_with_registry!(
"consensus_handler_processed_bytes",
"Number of bytes processed by consensus_handler",
consensus_handler_processed: register_int_counter_vec_with_registry!(
"consensus_handler_processed",
"Number of transactions processed by consensus handler",
&["class"],
registry
).unwrap(),
consensus_handler_transaction_sizes: register_histogram_vec_with_registry!(
"consensus_handler_transaction_sizes",
"Sizes of each type of transactions processed by consensus handler",
&["class"],
POSITIVE_INT_BUCKETS.to_vec(),
registry
).unwrap(),
consensus_handler_processed: register_int_counter_vec_with_registry!("consensus_handler_processed", "Number of transactions processed by consensus handler", &["class"], registry)
.unwrap(),
consensus_handler_num_low_scoring_authorities: register_int_gauge_with_registry!(
"consensus_handler_num_low_scoring_authorities",
"Number of low scoring authorities based on reputation scores from consensus",
Expand Down
12 changes: 6 additions & 6 deletions crates/sui-core/src/consensus_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ impl<C: CheckpointServiceNotify + Send + Sync> ConsensusHandler<C> {
.with_label_values(&[&leader_author.to_string()])
.inc();

let mut bytes = 0usize;
{
let span = trace_span!("process_consensus_certs");
let _guard = span.enter();
Expand All @@ -343,11 +342,15 @@ impl<C: CheckpointServiceNotify + Send + Sync> ConsensusHandler<C> {
.stats
.inc_num_messages(authority_index as usize);
for (serialized_transaction, transaction) in authority_transactions {
bytes += serialized_transaction.len();
let kind = classify(&transaction);
self.metrics
.consensus_handler_processed
.with_label_values(&[classify(&transaction)])
.with_label_values(&[kind])
.inc();
self.metrics
.consensus_handler_transaction_sizes
.with_label_values(&[kind])
.observe(serialized_transaction.len() as f64);
if matches!(
&transaction.kind,
ConsensusTransactionKind::UserTransaction(_)
Expand Down Expand Up @@ -383,9 +386,6 @@ impl<C: CheckpointServiceNotify + Send + Sync> ConsensusHandler<C> {
.with_label_values(&[hostname])
.set(self.last_consensus_stats.stats.get_num_user_transactions(i) as i64);
}
self.metrics
.consensus_handler_processed_bytes
.inc_by(bytes as u64);

let mut all_transactions = Vec::new();
{
Expand Down

0 comments on commit b1540cd

Please sign in to comment.