Skip to content

Commit

Permalink
[diemdb-bench] add reads/bytes_written
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmark authored and bors-libra committed Mar 11, 2021
1 parent d591f3b commit 454f470
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions storage/diemdb-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rand = "0.8.3"
structopt = "0.3.21"

diemdb = { path = "../diemdb" }
diem-jellyfish-merkle = { path = "../jellyfish-merkle" }
diem-config = { path = "../../config" }
diem-types = { path = "../../types" }
diem-workspace-hack = { path = "../../common/workspace-hack" }
Expand Down
13 changes: 13 additions & 0 deletions storage/diemdb-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

use byteorder::{BigEndian, WriteBytesExt};
use diem_config::config::RocksdbConfig;
use diem_jellyfish_merkle::metrics::{
DIEM_JELLYFISH_INTERNAL_ENCODED_BYTES, DIEM_JELLYFISH_LEAF_ENCODED_BYTES,
DIEM_JELLYFISH_STORAGE_READS,
};
use diem_types::{
account_address::AccountAddress,
account_state_blob::AccountStateBlob,
Expand Down Expand Up @@ -118,11 +122,20 @@ pub fn run_benchmark(
let data_size = DIEM_STORAGE_ROCKSDB_PROPERTIES
.with_label_values(&[JELLYFISH_MERKLE_NODE_CF_NAME, "diem_rocksdb_cf_size_bytes"])
.get();
let reads = DIEM_JELLYFISH_STORAGE_READS.get();
let leaf_bytes = DIEM_JELLYFISH_LEAF_ENCODED_BYTES.get();
let internal_bytes = DIEM_JELLYFISH_INTERNAL_ENCODED_BYTES.get();
println!(
"created a DiemDB til version {}, where {} accounts with avg blob size {} bytes exist.",
total_version, num_accounts, blob_size
);
println!("DB dir: {}", db_dir.as_path().display());
println!("Jellyfish Merkle physical size: {}", db_size);
println!("Jellyfish Merkle logical size: {}", data_size);
println!("Total reads from storage: {}", reads);
println!(
"Total written internal nodes value size: {} bytes",
internal_bytes
);
println!("Total written leaf nodes value size: {} bytes", leaf_bytes);
}
2 changes: 2 additions & 0 deletions storage/jellyfish-merkle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ byteorder = "1.4.3"
mirai-annotations = "1.10.1"
num-derive = "0.3.3"
num-traits = "0.2.14"
once_cell = "1.7.2"
proptest = { version = "1.0.0", optional = true }
proptest-derive = { version = "0.3.0", optional = true }
rand = { version = "0.8.3", optional = true }
Expand All @@ -25,6 +26,7 @@ bcs = "0.1.2"
diem-crypto = { path = "../../crypto/crypto" }
diem-crypto-derive = { path = "../../crypto/crypto-derive" }
diem-infallible = { path = "../../common/infallible" }
diem-metrics = { path = "../../common/metrics" }
diem-nibble = { path = "../../common/nibble" }
diem-types = { path = "../../types" }
diem-workspace-hack = { path = "../../common/workspace-hack" }
Expand Down
1 change: 1 addition & 0 deletions storage/jellyfish-merkle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
pub mod iterator;
#[cfg(test)]
mod jellyfish_merkle_test;
pub mod metrics;
#[cfg(any(test, feature = "fuzzing"))]
mod mock_tree_store;
mod nibble_path;
Expand Down
29 changes: 29 additions & 0 deletions storage/jellyfish-merkle/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use diem_metrics::{register_int_counter, IntCounter};
use once_cell::sync::Lazy;

pub static DIEM_JELLYFISH_LEAF_ENCODED_BYTES: Lazy<IntCounter> = Lazy::new(|| {
register_int_counter!(
"diem_jellyfish_leaf_encoded_bytes",
"Diem jellyfish leaf encoded bytes in total"
)
.unwrap()
});

pub static DIEM_JELLYFISH_INTERNAL_ENCODED_BYTES: Lazy<IntCounter> = Lazy::new(|| {
register_int_counter!(
"diem_jellyfish_internal_encoded_bytes",
"Diem jellyfish total internal nodes encoded in bytes"
)
.unwrap()
});

pub static DIEM_JELLYFISH_STORAGE_READS: Lazy<IntCounter> = Lazy::new(|| {
register_int_counter!(
"diem_jellyfish_storage_reads",
"Diem jellyfish reads from storage"
)
.unwrap()
});
10 changes: 8 additions & 2 deletions storage/jellyfish-merkle/src/node_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#[cfg(test)]
mod node_type_test;

use crate::{nibble_path::NibblePath, ROOT_NIBBLE_HEIGHT};
use crate::{
metrics::{DIEM_JELLYFISH_INTERNAL_ENCODED_BYTES, DIEM_JELLYFISH_LEAF_ENCODED_BYTES},
nibble_path::NibblePath,
ROOT_NIBBLE_HEIGHT,
};
use anyhow::{ensure, Context, Result};
use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt};
use diem_crypto::{
Expand Down Expand Up @@ -608,11 +612,13 @@ where
}
Node::Internal(internal_node) => {
out.push(NodeTag::Internal as u8);
internal_node.serialize(&mut out)?
internal_node.serialize(&mut out)?;
DIEM_JELLYFISH_INTERNAL_ENCODED_BYTES.inc_by(out.len() as u64);
}
Node::Leaf(leaf_node) => {
out.push(NodeTag::Leaf as u8);
out.extend(bcs::to_bytes(&leaf_node)?);
DIEM_JELLYFISH_LEAF_ENCODED_BYTES.inc_by(out.len() as u64);
}
}
Ok(out)
Expand Down
2 changes: 2 additions & 0 deletions storage/jellyfish-merkle/src/tree_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
mod tree_cache_test;

use crate::{
metrics::DIEM_JELLYFISH_STORAGE_READS,
node_type::{Node, NodeKey},
NodeStats, StaleNodeIndex, TreeReader, TreeUpdateBatch,
};
Expand Down Expand Up @@ -186,6 +187,7 @@ where
} else if let Some(node) = self.frozen_cache.node_cache.get(node_key) {
node.clone()
} else {
DIEM_JELLYFISH_STORAGE_READS.inc();
self.reader.get_node(node_key)?
})
}
Expand Down

0 comments on commit 454f470

Please sign in to comment.