Skip to content

Commit

Permalink
[exec_bench] unify diemdb_bench and exec_bench with same txn gen
Browse files Browse the repository at this point in the history
  • Loading branch information
lightmark authored and bors-libra committed Oct 1, 2021
1 parent 6d265b6 commit d8ed3ce
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 182 deletions.
28 changes: 6 additions & 22 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ members = [
"storage/backup/backup-cli",
"storage/backup/backup-service",
"storage/diemdb",
"storage/diemdb-benchmark",
"storage/diemsum",
"storage/inspector",
"storage/jellyfish-merkle",
Expand Down
10 changes: 9 additions & 1 deletion execution/executor-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ publish = false
edition = "2018"

[dependencies]
bcs = "0.1.2"
criterion = "0.3.4"
indicatif = "0.15.0"
itertools = { version = "0.10.0", default-features = false }
rand = "0.8.3"
rayon = "1.5.0"
serde = "1.0.124"
structopt = "0.3.21"
criterion = "0.3.4"

executor = { path = "../executor" }
executor-types = { path = "../executor-types" }
Expand All @@ -23,15 +26,20 @@ diem-config = { path = "../../config" }
diem-crypto = { path = "../../crypto/crypto" }
diem-genesis-tool = {path = "../../config/management/genesis", features = ["testing"] }
diem-infallible = { path = "../../common/infallible" }
diem-jellyfish-merkle = { path = "../../storage/jellyfish-merkle" }
diem-logger = { path = "../../common/logger" }
diem-types = { path = "../../types" }
diem-vm= { path = "../../language/diem-vm" }
diem-workspace-hack = { path = "../../common/workspace-hack" }
schemadb = { path = "../../storage/schemadb" }
storage-client = { path = "../../storage/storage-client" }
storage-interface = { path = "../../storage/storage-interface" }
storage-service = { path = "../../storage/storage-service" }
diem-transaction-builder = { path = "../../sdk/transaction-builder" }

[dev-dependencies]
diem-temppath = { path = "../../common/temppath" }

[features]
default = []
fuzzing = ["diem-config/fuzzing", "diem-crypto/fuzzing", "diem-types/fuzzing"]
Expand Down
2 changes: 1 addition & 1 deletion execution/executor-benchmark/benches/executor_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn executor_benchmark<M: Measurement + 'static>(c: &mut Criterion<M>) {
let mut generator = TransactionGenerator::new(genesis_key, NUM_ACCOUNTS);
let (commit_tx, _commit_rx) = std::sync::mpsc::channel();

let mut executor = TransactionExecutor::new(executor, parent_block_id, Some(commit_tx));
let mut executor = TransactionExecutor::new(executor, parent_block_id, 0, Some(commit_tx));
let txns = generator.gen_account_creations(SMALL_BLOCK_SIZE);
for txn_block in txns {
executor.execute_block(txn_block);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::{
transaction_executor::TransactionExecutor, transaction_generator::TransactionGenerator,
};
use diem_config::{config::RocksdbConfig, utils::get_genesis_txn};
use diem_jellyfish_merkle::metrics::{
DIEM_JELLYFISH_INTERNAL_ENCODED_BYTES, DIEM_JELLYFISH_LEAF_ENCODED_BYTES,
DIEM_JELLYFISH_STORAGE_READS,
};
use diem_logger::prelude::*;
use diem_vm::DiemVM;
use diemdb::{
metrics::DIEM_STORAGE_ROCKSDB_PROPERTIES, schema::JELLYFISH_MERKLE_NODE_CF_NAME, DiemDB,
Expand All @@ -14,29 +18,25 @@ use executor::{
db_bootstrapper::{generate_waypoint, maybe_bootstrap},
Executor,
};
use executor_benchmark::{
transaction_executor::TransactionExecutor, transaction_generator::TransactionGenerator,
};
use indicatif::{ProgressBar, ProgressStyle};
use std::{
fs,
path::PathBuf,
path::Path,
sync::{mpsc, Arc},
};
use storage_interface::DbReaderWriter;

pub fn run_benchmark(
pub fn run(
num_accounts: usize,
init_account_balance: u64,
block_size: usize,
db_dir: PathBuf,
db_dir: impl AsRef<Path>,
prune_window: Option<u64>,
) {
if db_dir.exists() {
fs::remove_dir_all(db_dir.join("diemdb")).unwrap();
if db_dir.as_ref().exists() {
fs::remove_dir_all(db_dir.as_ref().join("diemdb")).unwrap_or(());
}
// create if not exists
fs::create_dir_all(db_dir.clone()).unwrap();
fs::create_dir_all(db_dir.as_ref()).unwrap();

let (config, genesis_key) = diem_genesis_tool::test_config();
// Create executor.
Expand All @@ -49,42 +49,36 @@ pub fn run_benchmark(
)
.expect("DB should open."),
);

// Bootstrap db with genesis
let waypoint = generate_waypoint::<DiemVM>(&db_rw, get_genesis_txn(&config).unwrap()).unwrap();
maybe_bootstrap::<DiemVM>(&db_rw, get_genesis_txn(&config).unwrap(), waypoint).unwrap();

let executor = Arc::new(Executor::new(db_rw));
let genesis_block_id = executor.committed_block_id();

let (block_sender, block_receiver) = mpsc::sync_channel(50 /* bound */);

// Set a progressing bar
let bar = Arc::new(ProgressBar::new(0));
bar.set_style(
ProgressStyle::default_bar()
.template("[{elapsed}] {bar:100.cyan/blue} {pos:>7}/{len:7} {msg}"),
);
let gen_thread_bar = Arc::clone(&bar);
let exe_thread_bar = Arc::clone(&bar);

// Spawn two threads to run transaction generator and executor separately.
let gen_thread = std::thread::Builder::new()
.name("txn_generator".to_string())
.spawn(move || {
println!("Generating transactions...");
let mut generator =
TransactionGenerator::new_with_sender(genesis_key, num_accounts, block_sender);
generator.run_mint(init_account_balance, block_size);
gen_thread_bar.set_length(generator.version());
generator
})
.expect("Failed to spawn transaction generator thread.");
let exe_thread = std::thread::Builder::new()
.name("txn_executor".to_string())
.spawn(move || {
let mut exe = TransactionExecutor::new(executor, genesis_block_id, None);
let mut exe = TransactionExecutor::new(
executor,
genesis_block_id,
0, /* start_verison */
None,
);
while let Ok(transactions) = block_receiver.recv() {
let version_bump = transactions.len() as u64;
exe.execute_block(transactions);
exe_thread_bar.inc(version_bump);
}
})
.expect("Failed to spawn transaction executor thread.");
Expand All @@ -96,7 +90,10 @@ pub fn run_benchmark(
exe_thread.join().unwrap();
// Do a sanity check on the sequence number to make sure all transactions are committed.
generator.verify_sequence_number(db.as_ref());
bar.finish();

let final_version = generator.version();
// Write metadata
generator.write_meta(&db_dir);

db.update_rocksdb_properties().unwrap();
let db_size = DIEM_STORAGE_ROCKSDB_PROPERTIES
Expand All @@ -111,18 +108,18 @@ pub fn run_benchmark(
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 exist.",
bar.length(),
num_accounts,
info!("=============FINISHED DB CREATION =============");
info!(
"created a DiemDB til version {} with {} accounts.",
final_version, num_accounts,
);
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!(
info!("DB dir: {}", db_dir.as_ref().display());
info!("Jellyfish Merkle physical size: {}", db_size);
info!("Jellyfish Merkle logical size: {}", data_size);
info!("Total reads from storage: {}", reads);
info!(
"Total written internal nodes value size: {} bytes",
internal_bytes
);
println!("Total written leaf nodes value size: {} bytes", leaf_bytes);
info!("Total written leaf nodes value size: {} bytes", leaf_bytes);
}
Loading

0 comments on commit d8ed3ce

Please sign in to comment.