Skip to content

Commit

Permalink
adding NativeVMWithBlockSTM executor
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Oct 28, 2024
1 parent 05826a1 commit 489ceea
Show file tree
Hide file tree
Showing 20 changed files with 1,127 additions and 397 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions aptos-move/aptos-vm/src/block_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct AptosTransactionOutput {
}

impl AptosTransactionOutput {
pub(crate) fn new(output: VMOutput) -> Self {
pub fn new(output: VMOutput) -> Self {
Self {
vm_output: Mutex::new(Some(output)),
committed_output: OnceCell::new(),
Expand All @@ -79,7 +79,7 @@ impl AptosTransactionOutput {
self.committed_output.get().unwrap()
}

fn take_output(mut self) -> TransactionOutput {
pub fn take_output(mut self) -> TransactionOutput {
match self.committed_output.take() {
Some(output) => output,
// TODO: revisit whether we should always get it via committed, or o.w. create a
Expand Down
4 changes: 4 additions & 0 deletions execution/executor-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ aptos-genesis = { workspace = true, features = ["testing"] }
aptos-jellyfish-merkle = { workspace = true }
aptos-logger = { workspace = true }
aptos-metrics-core = { workspace = true }
aptos-mvhashmap = { workspace = true }
aptos-node-resource-metrics = { workspace = true }
aptos-push-metrics = { workspace = true }
aptos-sdk = { workspace = true }
aptos-storage-interface = { workspace = true }
aptos-transaction-generator-lib = { workspace = true }
aptos-types = { workspace = true }
aptos-vm = { workspace = true }
aptos-vm-types = { workspace = true }
async-trait = { workspace = true }
bytes = { workspace = true }
bcs = { workspace = true }
chrono = { workspace = true }
clap = { workspace = true }
dashmap = { workspace = true }
derivative = { workspace = true }
indicatif = { workspace = true }
itertools = { workspace = true }
Expand Down
75 changes: 54 additions & 21 deletions execution/executor-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub mod db_generator;
mod db_reliable_submitter;
mod ledger_update_stage;
mod metrics;
pub mod native_transaction;
pub mod native_executor_task;
pub mod native_loose_block_executor;
pub mod pipeline;
pub mod transaction_committer;
Expand All @@ -25,8 +27,7 @@ use aptos_db::AptosDB;
use aptos_executor::{
block_executor::{BlockExecutor, TransactionBlockExecutor},
metrics::{
COMMIT_BLOCKS, EXECUTE_BLOCK, OTHER_TIMERS, PROCESSED_TXNS_OUTPUT_SIZE, UPDATE_LEDGER,
VM_EXECUTE_BLOCK,
BLOCK_EXECUTOR_EXECUTE_BLOCK, BLOCK_EXECUTOR_INNER_EXECUTE_BLOCK, COMMIT_BLOCKS, EXECUTE_BLOCK, OTHER_TIMERS, PROCESSED_TXNS_OUTPUT_SIZE, UPDATE_LEDGER
},
};
use aptos_jellyfish_merkle::metrics::{
Expand Down Expand Up @@ -542,7 +543,8 @@ struct ExecutionTimeMeasurement {
sig_verify_total_time: f64,
partitioning_total_time: f64,
execution_total_time: f64,
vm_total_time: f64,
block_executor_total_time: f64,
block_executor_inner_total_time: f64,
by_other: HashMap<&'static str, f64>,
ledger_update_total: f64,
commit_total_time: f64,
Expand All @@ -557,7 +559,8 @@ impl ExecutionTimeMeasurement {
let sig_verify_total = TIMER.with_label_values(&["sig_verify"]).get_sample_sum();
let partitioning_total = TIMER.with_label_values(&["partition"]).get_sample_sum();
let execution_total = EXECUTE_BLOCK.get_sample_sum();
let vm_total = VM_EXECUTE_BLOCK.get_sample_sum();
let block_executor_total = BLOCK_EXECUTOR_EXECUTE_BLOCK.get_sample_sum();
let block_executor_inner_total = BLOCK_EXECUTOR_INNER_EXECUTE_BLOCK.get_sample_sum();

let by_other = OTHER_LABELS
.iter()
Expand All @@ -578,7 +581,8 @@ impl ExecutionTimeMeasurement {
sig_verify_total_time: sig_verify_total,
partitioning_total_time: partitioning_total,
execution_total_time: execution_total,
vm_total_time: vm_total,
block_executor_total_time: block_executor_total,
block_executor_inner_total_time: block_executor_inner_total,
by_other,
ledger_update_total,
commit_total_time: commit_total,
Expand All @@ -593,7 +597,8 @@ impl ExecutionTimeMeasurement {
sig_verify_total_time: end.sig_verify_total_time - self.sig_verify_total_time,
partitioning_total_time: end.partitioning_total_time - self.partitioning_total_time,
execution_total_time: end.execution_total_time - self.execution_total_time,
vm_total_time: end.vm_total_time - self.vm_total_time,
block_executor_total_time: end.block_executor_total_time - self.block_executor_total_time,
block_executor_inner_total_time: end.block_executor_inner_total_time - self.block_executor_inner_total_time,
by_other: end
.by_other
.into_iter()
Expand Down Expand Up @@ -695,10 +700,16 @@ impl OverallMeasuring {
num_txns / delta_execution.execution_total_time
);
info!(
"{} fraction of execution {:.4} in VM (component TPS: {:.1})",
"{} fraction of execution {:.4} in block executor (component TPS: {:.1})",
prefix,
delta_execution.vm_total_time / delta_execution.execution_total_time,
num_txns / delta_execution.vm_total_time
delta_execution.block_executor_total_time / delta_execution.execution_total_time,
num_txns / delta_execution.block_executor_total_time
);
info!(
"{} fraction of execution {:.4} in inner block executor (component TPS: {:.1})",
prefix,
delta_execution.block_executor_inner_total_time / delta_execution.execution_total_time,
num_txns / delta_execution.block_executor_inner_total_time
);
for (prefix, top_level, other_label) in OTHER_LABELS {
let time_in_label = delta_execution.by_other.get(other_label).unwrap();
Expand Down Expand Up @@ -740,10 +751,10 @@ fn log_total_supply(db_reader: &Arc<dyn DbReader>) {
mod tests {
use std::fs;

use crate::{db_generator::bootstrap_with_genesis, init_db_and_executor, native_loose_block_executor::NativeLooseBlockExecutor, pipeline::PipelineConfig, transaction_executor::BENCHMARKS_BLOCK_EXECUTOR_ONCHAIN_CONFIG, transaction_generator::TransactionGenerator, BenchmarkWorkload};
use crate::{db_generator::bootstrap_with_genesis, init_db_and_executor, native_executor_task::NativeVMBlockExecutor, native_loose_block_executor::{NativeNoStorageLooseSpeculativeBlockExecutor, NativeLooseSpeculativeBlockExecutor}, native_transaction::NativeConfig, pipeline::PipelineConfig, transaction_executor::BENCHMARKS_BLOCK_EXECUTOR_ONCHAIN_CONFIG, transaction_generator::TransactionGenerator, BenchmarkWorkload};
use aptos_config::config::NO_OP_STORAGE_PRUNER_CONFIG;
use aptos_crypto::HashValue;
use aptos_executor::block_executor::TransactionBlockExecutor;
use aptos_executor::block_executor::{AptosVMBlockExecutor, TransactionBlockExecutor};
use aptos_sdk::{transaction_builder::{aptos_stdlib, TransactionFactory}, types::LocalAccount};
use aptos_temppath::TempPath;
use aptos_transaction_generator_lib::{args::TransactionTypeArg, WorkflowProgress};
Expand Down Expand Up @@ -773,7 +784,7 @@ mod tests {
config.storage.rocksdb_configs.enable_storage_sharding = false;

let (txn, vm_result) = {
let (vm_db, vm_executor) = init_db_and_executor::<AptosVM>(&config);
let (vm_db, vm_executor) = init_db_and_executor::<AptosVMBlockExecutor>(&config);
let root_account = TransactionGenerator::read_root_account(genesis_key, &vm_db);
let dst = LocalAccount::generate(&mut thread_rng());
let num_coins = 1000;
Expand All @@ -793,7 +804,7 @@ mod tests {
(txn, vm_result)
};

let (native_db, native_executor) = init_db_and_executor::<NativeLooseBlockExecutor>(&config);
let (native_db, native_executor) = init_db_and_executor::<NativeLooseSpeculativeBlockExecutor>(&config);
let native_result = native_executor
.execute_and_state_checkpoint(
(HashValue::zero(), vec![txn]).into(),
Expand Down Expand Up @@ -851,6 +862,10 @@ mod tests {

println!("db_generator::create_db_with_accounts");

let mut features = Features::default();
features.enable(FeatureFlag::NEW_ACCOUNTS_DEFAULT_TO_FA_APT_STORE);
features.enable(FeatureFlag::OPERATIONS_DEFAULT_TO_FA_APT_STORE);

crate::db_generator::create_db_with_accounts::<E>(
100, /* num_accounts */
// TODO(Gas): double check if this is correct
Expand All @@ -861,7 +876,7 @@ mod tests {
verify_sequence_numbers,
false,
PipelineConfig::default(),
Features::default(),
features.clone(),
);

println!("run_benchmark");
Expand All @@ -882,30 +897,48 @@ mod tests {
NO_OP_STORAGE_PRUNER_CONFIG,
false,
PipelineConfig::default(),
Features::default(),
features,
);
}

#[test]
fn test_benchmark_default() {
test_generic_benchmark::<AptosVM>(None, true);
test_generic_benchmark::<AptosVMBlockExecutor>(None, true);
}

#[test]
fn test_benchmark_transaction() {
AptosVM::set_num_shards_once(1);
AptosVM::set_concurrency_level_once(4);
AptosVM::set_concurrency_level_once(1);
AptosVM::set_processed_transactions_detailed_counters();
NativeLooseBlockExecutor::set_concurrency_level_once(4);
test_generic_benchmark::<AptosVM>(
NativeConfig::set_concurrency_level_once(1);
test_generic_benchmark::<AptosVMBlockExecutor>(
Some(TransactionTypeArg::ModifyGlobalMilestoneAggV2),
true,
);
}

#[test]
fn test_native_benchmark() {
fn test_native_vm_benchmark_transaction() {
AptosVM::set_num_shards_once(1);
AptosVM::set_concurrency_level_once(1);
AptosVM::set_processed_transactions_detailed_counters();
NativeConfig::set_concurrency_level_once(1);
test_generic_benchmark::<NativeVMBlockExecutor>(
Some(TransactionTypeArg::NoOp),
true,
);
}

#[test]
fn test_native_loose_block_executor_benchmark() {
// correct execution not yet implemented, so cannot be checked for validity
test_generic_benchmark::<NativeLooseSpeculativeBlockExecutor>(Some(TransactionTypeArg::AptFaTransfer), false);
}

#[test]
fn test_native_direct_raw_loose_block_executor_benchmark() {
// correct execution not yet implemented, so cannot be checked for validity
test_generic_benchmark::<NativeLooseBlockExecutor>(Some(TransactionTypeArg::AptFaTransfer), false);
test_generic_benchmark::<NativeNoStorageLooseSpeculativeBlockExecutor>(Some(TransactionTypeArg::AptFaTransfer), false);
}
}
61 changes: 36 additions & 25 deletions execution/executor-benchmark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use aptos_block_partitioner::{
use aptos_config::config::{
EpochSnapshotPrunerConfig, LedgerPrunerConfig, PrunerConfig, StateMerklePrunerConfig,
};
use aptos_executor::block_executor::TransactionBlockExecutor;
use aptos_executor_benchmark::{native_loose_block_executor::NativeLooseBlockExecutor, pipeline::PipelineConfig, BenchmarkWorkload};
use aptos_executor::block_executor::{AptosVMBlockExecutor, TransactionBlockExecutor};
use aptos_executor_benchmark::{native_executor_task::NativeVMBlockExecutor, native_loose_block_executor::{NativeNoStorageLooseSpeculativeBlockExecutor, NativeLooseSpeculativeBlockExecutor}, native_transaction::NativeConfig, pipeline::PipelineConfig, BenchmarkWorkload};
use aptos_executor_service::remote_executor_client;
use aptos_experimental_ptx_executor::PtxBlockExecutor;
#[cfg(target_os = "linux")]
Expand All @@ -28,7 +28,7 @@ use aptos_types::{
vm::configs::set_paranoid_type_checks,
};
use aptos_vm::AptosVM;
use clap::{ArgGroup, Parser, Subcommand};
use clap::{ArgGroup, Parser, Subcommand, ValueEnum};
use once_cell::sync::Lazy;
use std::{
net::SocketAddr,
Expand Down Expand Up @@ -206,17 +206,14 @@ struct ProfilerOpt {
memory_profiling: bool,
}

#[derive(Parser, Debug)]
#[clap(group(
ArgGroup::new("vm_selection")
.args(&["use_native_loose_block_executor", "use_ptx_executor"]),
))]
pub struct VmSelectionOpt {
#[clap(long)]
use_native_loose_block_executor: bool,

#[clap(long)]
use_ptx_executor: bool,
#[derive(Parser, Debug, ValueEnum, Clone, Default)]
enum BlockExecutorTypeOpt {
#[default]
AptosVMWithBlockSTM,
NativeVMWithBlockSTM,
NativeLooseSpeculative,
NativeNoStorageLooseSpeculative,
PtxExecutor,
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -260,8 +257,12 @@ struct Opt {
#[clap(long)]
verify_sequence_numbers: bool,

#[clap(flatten)]
vm_selection_opt: VmSelectionOpt,
#[clap(
long,
value_enum,
ignore_case = true,
)]
block_executor_type: BlockExecutorTypeOpt,

#[clap(flatten)]
profiler_opt: ProfilerOpt,
Expand Down Expand Up @@ -564,7 +565,7 @@ fn main() {
}
AptosVM::set_num_shards_once(execution_shards);
AptosVM::set_concurrency_level_once(execution_threads_per_shard);
NativeLooseBlockExecutor::set_concurrency_level_once(execution_threads_per_shard);
NativeConfig::set_concurrency_level_once(execution_threads_per_shard);
AptosVM::set_processed_transactions_detailed_counters();

let config = ProfilerConfig::new_with_defaults();
Expand All @@ -583,14 +584,24 @@ fn main() {
let _mem_start = memory_profiler.start_profiling();
}

if opt.vm_selection_opt.use_native_loose_block_executor {
run::<NativeLooseBlockExecutor>(opt);
} else if opt.vm_selection_opt.use_ptx_executor {
#[cfg(target_os = "linux")]
ThreadManagerBuilder::set_thread_config_strategy(ThreadConfigStrategy::ThreadsPriority(48));
run::<PtxBlockExecutor>(opt);
} else {
run::<AptosVM>(opt);
match opt.block_executor_type {
BlockExecutorTypeOpt::AptosVMWithBlockSTM => {
run::<AptosVMBlockExecutor>(opt);
},
BlockExecutorTypeOpt::NativeVMWithBlockSTM => {
run::<NativeVMBlockExecutor>(opt);
},
BlockExecutorTypeOpt::NativeLooseSpeculative => {
run::<NativeLooseSpeculativeBlockExecutor>(opt);
},
BlockExecutorTypeOpt::NativeNoStorageLooseSpeculative => {
run::<NativeNoStorageLooseSpeculativeBlockExecutor>(opt);
},
BlockExecutorTypeOpt::PtxExecutor => {
#[cfg(target_os = "linux")]
ThreadManagerBuilder::set_thread_config_strategy(ThreadConfigStrategy::ThreadsPriority(48));
run::<PtxBlockExecutor>(opt);
},
}

if cpu_profiling {
Expand Down
Loading

0 comments on commit 489ceea

Please sign in to comment.