Skip to content

Commit

Permalink
[storage] more metrics
Browse files Browse the repository at this point in the history
Closes: #10096
  • Loading branch information
msmouse authored and bors-libra committed Dec 23, 2021
1 parent 6f5de36 commit 0b180cb
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 53 deletions.
112 changes: 63 additions & 49 deletions storage/diemdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,60 +569,74 @@ impl DiemDB {
let last_version = first_version + txns_to_commit.len() as u64 - 1;

// Account state updates. Gather account state root hashes
let account_state_sets = txns_to_commit
.iter()
.map(|txn_to_commit| txn_to_commit.account_states().clone())
.collect::<Vec<_>>();

let node_hashes = txns_to_commit
.iter()
.map(|txn_to_commit| txn_to_commit.jf_node_hashes())
.collect::<Option<Vec<_>>>();
let state_root_hashes = self.state_store.put_account_state_sets(
account_state_sets,
node_hashes,
first_version,
&mut cs,
)?;
let state_root_hashes = {
let _timer = DIEM_STORAGE_OTHER_TIMERS_SECONDS
.with_label_values(&["save_transactions_state"])
.start_timer();

let account_state_sets = txns_to_commit
.iter()
.map(|txn_to_commit| txn_to_commit.account_states().clone())
.collect::<Vec<_>>();

let node_hashes = txns_to_commit
.iter()
.map(|txn_to_commit| txn_to_commit.jf_node_hashes())
.collect::<Option<Vec<_>>>();
self.state_store.put_account_state_sets(
account_state_sets,
node_hashes,
first_version,
&mut cs,
)?
};

// Event updates. Gather event accumulator root hashes.
let event_root_hashes = zip_eq(first_version..=last_version, txns_to_commit)
.map(|(ver, txn_to_commit)| {
self.event_store
.put_events(ver, txn_to_commit.events(), &mut cs)
})
.collect::<Result<Vec<_>>>()?;

zip_eq(first_version..=last_version, txns_to_commit).try_for_each(
|(ver, txn_to_commit)| {
// Transaction updates. Gather transaction hashes.
self.transaction_store.put_transaction(
ver,
txn_to_commit.transaction(),
&mut cs,
)?;
self.transaction_store
.put_write_set(ver, txn_to_commit.write_set(), &mut cs)
},
)?;
let event_root_hashes = {
let _timer = DIEM_STORAGE_OTHER_TIMERS_SECONDS
.with_label_values(&["save_transactions_events"])
.start_timer();
zip_eq(first_version..=last_version, txns_to_commit)
.map(|(ver, txn_to_commit)| {
self.event_store
.put_events(ver, txn_to_commit.events(), &mut cs)
})
.collect::<Result<Vec<_>>>()?
};

// Transaction accumulator updates. Get result root hash.
let txn_infos = izip!(txns_to_commit, state_root_hashes, event_root_hashes)
.map(|(t, s, e)| {
Ok(TransactionInfo::new(
t.transaction().hash(),
s,
e,
t.gas_used(),
t.status().clone(),
))
})
.collect::<Result<Vec<_>>>()?;
assert_eq!(txn_infos.len(), txns_to_commit.len());
let new_root_hash = {
let _timer = DIEM_STORAGE_OTHER_TIMERS_SECONDS
.with_label_values(&["save_transactions_txn_infos"])
.start_timer();
zip_eq(first_version..=last_version, txns_to_commit).try_for_each(
|(ver, txn_to_commit)| {
// Transaction updates. Gather transaction hashes.
self.transaction_store.put_transaction(
ver,
txn_to_commit.transaction(),
&mut cs,
)?;
self.transaction_store
.put_write_set(ver, txn_to_commit.write_set(), &mut cs)
},
)?;
// Transaction accumulator updates. Get result root hash.
let txn_infos = izip!(txns_to_commit, state_root_hashes, event_root_hashes)
.map(|(t, s, e)| {
Ok(TransactionInfo::new(
t.transaction().hash(),
s,
e,
t.gas_used(),
t.status().clone(),
))
})
.collect::<Result<Vec<_>>>()?;
assert_eq!(txn_infos.len(), txns_to_commit.len());

let new_root_hash =
self.ledger_store
.put_transaction_infos(first_version, &txn_infos, &mut cs)?;
.put_transaction_infos(first_version, &txn_infos, &mut cs)?
};

Ok(new_root_hash)
}
Expand Down
8 changes: 6 additions & 2 deletions storage/schemadb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ pub mod schema;
use crate::{
metrics::{
DIEM_SCHEMADB_BATCH_COMMIT_BYTES, DIEM_SCHEMADB_BATCH_COMMIT_LATENCY_SECONDS,
DIEM_SCHEMADB_DELETES, DIEM_SCHEMADB_GET_BYTES, DIEM_SCHEMADB_GET_LATENCY_SECONDS,
DIEM_SCHEMADB_ITER_BYTES, DIEM_SCHEMADB_ITER_LATENCY_SECONDS, DIEM_SCHEMADB_PUT_BYTES,
DIEM_SCHEMADB_BATCH_PUT_LATENCY_SECONDS, DIEM_SCHEMADB_DELETES, DIEM_SCHEMADB_GET_BYTES,
DIEM_SCHEMADB_GET_LATENCY_SECONDS, DIEM_SCHEMADB_ITER_BYTES,
DIEM_SCHEMADB_ITER_LATENCY_SECONDS, DIEM_SCHEMADB_PUT_BYTES,
},
schema::{KeyCodec, Schema, SeekKeyCodec, ValueCodec},
};
Expand Down Expand Up @@ -68,6 +69,9 @@ impl SchemaBatch {

/// Adds an insert/update operation to the batch.
pub fn put<S: Schema>(&mut self, key: &S::Key, value: &S::Value) -> Result<()> {
let _timer = DIEM_SCHEMADB_BATCH_PUT_LATENCY_SECONDS
.with_label_values(&["unknown"])
.start_timer();
let key = <S::Key as KeyCodec<S>>::encode_key(key)?;
let value = <S::Value as ValueCodec<S>>::encode_value(value)?;
self.rows
Expand Down
12 changes: 12 additions & 0 deletions storage/schemadb/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,15 @@ pub static DIEM_SCHEMADB_DELETES: Lazy<IntCounterVec> = Lazy::new(|| {
)
.unwrap()
});

pub static DIEM_SCHEMADB_BATCH_PUT_LATENCY_SECONDS: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!(
// metric name
"diem_schemadb_batch_put_latency_seconds",
// metric description
"Diem schemadb schema batch put latency in seconds",
// metric labels (dimensions)
&["db_name"]
)
.unwrap()
});
11 changes: 10 additions & 1 deletion storage/scratchpad/src/sparse_merkle/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![forbid(unsafe_code)]

use diem_metrics::{register_int_gauge, IntGauge};
use diem_metrics::{register_histogram_vec, register_int_gauge, HistogramVec, IntGauge};
use once_cell::sync::Lazy;

pub static OLDEST_GENERATION: Lazy<IntGauge> = Lazy::new(|| {
Expand All @@ -21,3 +21,12 @@ pub static LATEST_GENERATION: Lazy<IntGauge> = Lazy::new(|| {
)
.unwrap()
});

pub static TIMER: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!(
"diem_scratchpad_smt_timer_seconds",
"Various timers for performance analysis.",
&["name"]
)
.unwrap()
});
5 changes: 4 additions & 1 deletion storage/scratchpad/src/sparse_merkle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mod sparse_merkle_test;
pub mod test_utils;

use crate::sparse_merkle::{
metrics::{LATEST_GENERATION, OLDEST_GENERATION},
metrics::{LATEST_GENERATION, OLDEST_GENERATION, TIMER},
node::{NodeInner, SubTree},
updater::SubTreeUpdater,
utils::partition,
Expand Down Expand Up @@ -477,6 +477,9 @@ where
// must be sorted
touched_accounts: Vec<HashValue>,
) -> HashMap<NibblePath, HashValue> {
let _timer = TIMER
.with_label_values(&["generate_node_hashes"])
.start_timer();
let mut node_hashes = HashMap::new();
let mut nibble_path = NibblePath::new(vec![]);
self.collect_new_hashes(
Expand Down

0 comments on commit 0b180cb

Please sign in to comment.