forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
185 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "scratchpad-benchmark" | ||
version = "0.1.0" | ||
authors = ["Diem Association <[email protected]>"] | ||
description = "Diem executor benchmark" | ||
repository = "https://github.com/diem/diem" | ||
homepage = "https://diem.com" | ||
license = "Apache-2.0" | ||
publish = false | ||
edition = "2018" | ||
|
||
[dependencies] | ||
anyhow = "1.0.38" | ||
itertools = { version = "0.10.0", default-features = false } | ||
rand = "0.8.3" | ||
rayon = "1.5.0" | ||
structopt = "0.3.21" | ||
|
||
diemdb = { path = "../diemdb" } | ||
diemdb-benchmark = { path = "../diemdb-benchmark" } | ||
diem-config = { path = "../../config" } | ||
diem-crypto = { path = "../../crypto/crypto" } | ||
diem-genesis-tool = {path = "../../config/management/genesis", features = ["testing"] } | ||
diem-infallible = { path = "../../common/infallible" } | ||
diem-logger = { path = "../../common/logger" } | ||
diem-types = { path = "../../types" } | ||
diem-workspace-hack = { path = "../../common/workspace-hack" } | ||
executor-types = { path = "../../execution/executor-types" } | ||
scratchpad = { path = "..//scratchpad" } | ||
storage-interface = { path = "../storage-interface" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) The Diem Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use anyhow::Result; | ||
use diem_config::config::RocksdbConfig; | ||
use diem_types::{account_address::HashAccountAddress, account_state_blob::AccountStateBlob}; | ||
use diemdb::DiemDB; | ||
use diemdb_benchmark::{gen_account_from_index, gen_random_blob}; | ||
use executor_types::ProofReader; | ||
use rand::Rng; | ||
use std::{collections::HashMap, path::PathBuf}; | ||
use storage_interface::DbReader; | ||
|
||
type SparseMerkleTree = scratchpad::SparseMerkleTree<AccountStateBlob>; | ||
|
||
pub fn run_benchmark(num_updates: usize, max_accounts: u64, blob_size: usize, db_dir: PathBuf) { | ||
let db = DiemDB::open( | ||
&db_dir, | ||
false, /* readonly */ | ||
None, /* pruner */ | ||
RocksdbConfig::default(), | ||
) | ||
.expect("DB should open."); | ||
|
||
let mut rng = ::rand::thread_rng(); | ||
|
||
let updates = (0..num_updates) | ||
.into_iter() | ||
.map(|_| { | ||
( | ||
gen_account_from_index(rng.gen_range(0..max_accounts)), | ||
gen_random_blob(blob_size, &mut rng), | ||
) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
let version = db.get_latest_version().unwrap(); | ||
let account_state_proofs = updates | ||
.iter() | ||
.map(|(k, _)| { | ||
db.get_account_state_with_proof(*k, version, version) | ||
.map(|p| p.proof.transaction_info_to_account_proof().clone()) | ||
}) | ||
.collect::<Result<Vec<_>>>() | ||
.unwrap(); | ||
|
||
let proof_reader = ProofReader::new( | ||
itertools::zip_eq( | ||
updates.iter().map(|(k, _)| k.hash()), | ||
account_state_proofs.into_iter(), | ||
) | ||
.collect::<HashMap<_, _>>(), | ||
); | ||
let root = db.get_latest_state_root().unwrap().1; | ||
let smt = SparseMerkleTree::new(root); | ||
let start = std::time::Instant::now(); | ||
smt.batch_update( | ||
updates | ||
.iter() | ||
.map(|(k, v)| (k.hash(), v)) | ||
.collect::<Vec<_>>(), | ||
&proof_reader, | ||
) | ||
.unwrap(); | ||
println!( | ||
"Sparse Merkle Tree batch update {} updates: {}ms", | ||
num_updates, | ||
start.elapsed().as_millis() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) The Diem Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::path::PathBuf; | ||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, StructOpt)] | ||
struct Opt { | ||
#[structopt(long, default_value = "2000")] | ||
num_updates: usize, | ||
|
||
#[structopt(long)] | ||
num_accounts: u64, | ||
|
||
#[structopt(short, default_value = "40")] | ||
blob_size: usize, | ||
|
||
#[structopt(long, parse(from_os_str))] | ||
db_dir: PathBuf, | ||
} | ||
|
||
fn main() { | ||
let opt = Opt::from_args(); | ||
scratchpad_benchmark::run_benchmark( | ||
opt.num_updates, | ||
opt.num_accounts, | ||
opt.blob_size, | ||
opt.db_dir, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters