Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[benchmarks] Module loading benches (simple) #15255

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
97188b4
[refactoring] Move explicit sync wrapper to aptos-types
georgemitenkov Nov 5, 2024
d958da3
[refactoring] Move & rename immutabke module cache to aptos-types
georgemitenkov Nov 5, 2024
9f0f976
[global cache] Draft e2e implementation
georgemitenkov Nov 5, 2024
32ebdd3
[testing] Added different test cases for global caches
georgemitenkov Nov 6, 2024
2a65957
[perf] Framework prefetch
georgemitenkov Nov 6, 2024
0fda569
[exp] Avoid repeated arcswap load
georgemitenkov Nov 6, 2024
60ceafb
[cleanup] Add errors, documentation, reset state on panics
georgemitenkov Nov 6, 2024
583ccfa
[refactoring] Remove versions from module code
georgemitenkov Nov 7, 2024
8bee4e8
[comments] Addressing Rati's comments + adding size in bytes to modul…
georgemitenkov Nov 7, 2024
6c40603
[draft] Better states and encapsulation
georgemitenkov Nov 8, 2024
7c2dbf7
prior to addressing comments:
georgemitenkov Nov 9, 2024
03a1ea2
[comments] Address Rati's and Zekun's comments
georgemitenkov Nov 11, 2024
28116bc
[fix] Add done --> ready transition for unit tests
georgemitenkov Nov 11, 2024
d45df1f
Move ready checks to cache manager, better encapsulation by passing h…
georgemitenkov Nov 12, 2024
f317dcf
[cleanup] Set execute_no_limit to always use Nones for block IDs
georgemitenkov Nov 12, 2024
03bb4df
Feature gating
georgemitenkov Nov 12, 2024
715f3a9
[comments] Addressing Igor's comments
georgemitenkov Nov 13, 2024
81e44f8
[congigs] Use 1 GB max size
georgemitenkov Nov 13, 2024
2f3708e
format fix
georgemitenkov Nov 13, 2024
003ecea
[comments] Added a comment about num_modules > 0
georgemitenkov Nov 13, 2024
12292a2
[comments] Use rw lock for module cache, but aquire before block exec…
georgemitenkov Nov 13, 2024
878792e
[benchmarks] Module loading benches (simple)
georgemitenkov Nov 12, 2024
fb126de
[fixes] Fix raw module data & add env vars
georgemitenkov Nov 12, 2024
e36de2d
[fix] Fix & improve script benchmark
georgemitenkov Nov 12, 2024
9fad83d
[hack] Cross-block debugger
georgemitenkov Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

78 changes: 38 additions & 40 deletions aptos-move/aptos-debugger/src/aptos_debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

use anyhow::{bail, format_err, Result};
use aptos_block_executor::txn_commit_hook::NoOpTransactionCommitHook;
use aptos_crypto::HashValue;
use aptos_gas_profiling::{GasProfiler, TransactionGasLog};
use aptos_rest_client::Client;
use aptos_types::{
account_address::AccountAddress,
block_executor::config::{
BlockExecutorConfig, BlockExecutorConfigFromOnchain, BlockExecutorLocalConfig,
},
block_executor::config::BlockExecutorConfigFromOnchain,
contract_event::ContractEvent,
state_store::TStateView,
transaction::{
Expand All @@ -23,9 +21,7 @@ use aptos_validator_interface::{
AptosValidatorInterface, DBDebuggerInterface, DebuggerStateView, RestDebuggerInterface,
};
use aptos_vm::{
block_executor::{AptosTransactionOutput, BlockAptosVM},
data_cache::AsMoveResolver,
AptosVM,
aptos_vm::AptosVMBlockExecutor, data_cache::AsMoveResolver, AptosVM, VMBlockExecutor,
};
use aptos_vm_environment::environment::AptosEnvironment;
use aptos_vm_logging::log_schema::AdapterLogSchema;
Expand Down Expand Up @@ -54,10 +50,13 @@ impl AptosDebugger {

pub fn execute_transactions_at_version(
&self,
executor: &AptosVMBlockExecutor,
version: Version,
txns: Vec<Transaction>,
repeat_execution_times: u64,
concurrency_levels: &[usize],
parent: Option<&HashValue>,
current: Option<HashValue>,
) -> Result<Vec<TransactionOutput>> {
let sig_verified_txns: Vec<SignatureVerifiedTransaction> =
txns.into_iter().map(|x| x.into()).collect::<Vec<_>>();
Expand All @@ -70,9 +69,16 @@ impl AptosDebugger {
for concurrency_level in concurrency_levels {
for i in 0..repeat_execution_times {
let start_time = Instant::now();
let cur_result =
execute_block_no_limit(&sig_verified_txns, &state_view, *concurrency_level)
.map_err(|err| format_err!("Unexpected VM Error: {:?}", err))?;
let cur_result = executor
.execute_block(
&sig_verified_txns,
&state_view,
BlockExecutorConfigFromOnchain::new_no_block_limit(),
parent,
current,
)
.map(BlockOutput::into_transaction_outputs_forced)
.map_err(|err| format_err!("Unexpected VM Error: {:?}", err))?;

println!(
"[{} txns from {}] Finished execution round {}/{} with concurrency_level={} in {}ms",
Expand Down Expand Up @@ -169,14 +175,12 @@ impl AptosDebugger {
if use_same_block_boundaries {
// when going block by block, no need to worry about epoch boundaries
// as new epoch is always a new block.
Ok(self
.execute_transactions_by_block(
begin,
txns.clone(),
repeat_execution_times,
concurrency_levels,
)
.await?)
Ok(self.execute_transactions_by_block(
begin,
txns.clone(),
repeat_execution_times,
concurrency_levels,
)?)
} else {
self.execute_transactions_by_epoch(
limit,
Expand Down Expand Up @@ -228,16 +232,20 @@ impl AptosDebugger {

async fn execute_transactions_until_epoch_end(
&self,
executor: &AptosVMBlockExecutor,
begin: Version,
txns: Vec<Transaction>,
repeat_execution_times: u64,
concurrency_levels: &[usize],
) -> Result<Vec<TransactionOutput>> {
let results = self.execute_transactions_at_version(
executor,
begin,
txns,
repeat_execution_times,
concurrency_levels,
None,
None,
)?;
let mut ret = vec![];
let mut is_reconfig = false;
Expand Down Expand Up @@ -270,8 +278,10 @@ impl AptosDebugger {
begin, limit
);

let executor = AptosVMBlockExecutor::new();
let mut epoch_result = self
.execute_transactions_until_epoch_end(
&executor,
begin,
txns.clone(),
repeat_execution_times,
Expand All @@ -289,7 +299,7 @@ impl AptosDebugger {
Ok(ret)
}

async fn execute_transactions_by_block(
fn execute_transactions_by_block(
&self,
begin: Version,
txns: Vec<Transaction>,
Expand All @@ -299,14 +309,20 @@ impl AptosDebugger {
let mut ret = vec![];
let mut cur = vec![];
let mut cur_version = begin;

let hash = HashValue::zero();
let executor = AptosVMBlockExecutor::new();
for txn in txns {
if txn.is_block_start() && !cur.is_empty() {
let to_execute = std::mem::take(&mut cur);
let results = self.execute_transactions_at_version(
&executor,
cur_version,
to_execute,
repeat_execution_times,
concurrency_levels,
Some(&hash),
Some(hash),
)?;
cur_version += results.len() as u64;
ret.extend(results);
Expand All @@ -315,10 +331,13 @@ impl AptosDebugger {
}
if !cur.is_empty() {
let results = self.execute_transactions_at_version(
&executor,
cur_version,
cur,
repeat_execution_times,
concurrency_levels,
Some(&hash),
Some(hash),
)?;
ret.extend(results);
}
Expand Down Expand Up @@ -422,24 +441,3 @@ fn is_reconfiguration(vm_output: &TransactionOutput) -> bool {
.iter()
.any(ContractEvent::is_new_epoch_event)
}

fn execute_block_no_limit(
sig_verified_txns: &[SignatureVerifiedTransaction],
state_view: &DebuggerStateView,
concurrency_level: usize,
) -> Result<Vec<TransactionOutput>, VMStatus> {
BlockAptosVM::execute_block::<_, NoOpTransactionCommitHook<AptosTransactionOutput, VMStatus>>(
sig_verified_txns,
state_view,
BlockExecutorConfig {
local: BlockExecutorLocalConfig {
concurrency_level,
allow_fallback: true,
discard_failed_blocks: false,
},
onchain: BlockExecutorConfigFromOnchain::new_no_block_limit(),
},
None,
)
.map(BlockOutput::into_transaction_outputs_forced)
}
5 changes: 5 additions & 0 deletions aptos-move/aptos-debugger/src/execute_pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::Result;
use aptos_crypto::HashValue;
use aptos_logger::info;
use aptos_rest_client::Client;
use aptos_vm::{aptos_vm::AptosVMBlockExecutor, VMBlockExecutor};
use clap::Parser;
use std::path::PathBuf;
use url::Url;
Expand Down Expand Up @@ -84,11 +85,15 @@ impl Command {
user_txns
};

let executor = AptosVMBlockExecutor::new();
let txn_outputs = debugger.execute_transactions_at_version(
&executor,
self.begin_version,
block,
self.repeat_execution_times.unwrap_or(1),
&self.opts.concurrency_level,
None,
None,
)?;
println!("{txn_outputs:#?}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

use crate::transactions;
use aptos_bitvec::BitVec;
use aptos_block_executor::txn_commit_hook::NoOpTransactionCommitHook;
use aptos_block_executor::{
code_cache_global_manager::ModuleCacheManager, txn_commit_hook::NoOpTransactionCommitHook,
};
use aptos_block_partitioner::{
v2::config::PartitionerV2Config, BlockPartitioner, PartitionerConfig,
};
Expand Down Expand Up @@ -218,8 +220,11 @@ where
>(
transactions,
self.state_view.as_ref(),
&ModuleCacheManager::new(),
BlockExecutorConfig::new_maybe_block_limit(1, maybe_block_gas_limit),
None,
None,
None,
)
.expect("VM should not fail to start")
.into_transaction_outputs_forced();
Expand Down Expand Up @@ -266,11 +271,14 @@ where
>(
transactions,
self.state_view.as_ref(),
&ModuleCacheManager::new(),
BlockExecutorConfig::new_maybe_block_limit(
concurrency_level_per_shard,
maybe_block_gas_limit,
),
None,
None,
None,
)
.expect("VM should not fail to start")
.into_transaction_outputs_forced();
Expand All @@ -285,21 +293,21 @@ where
partitioned_txns: Option<PartitionedTransactions>,
run_par: bool,
run_seq: bool,
conurrency_level_per_shard: usize,
concurrency_level_per_shard: usize,
maybe_block_gas_limit: Option<u64>,
) -> (usize, usize) {
let (output, par_tps) = if run_par {
println!("Parallel execution starts...");
let (output, tps) = if self.is_shareded() {
self.execute_benchmark_sharded(
partitioned_txns.unwrap(),
conurrency_level_per_shard,
concurrency_level_per_shard,
maybe_block_gas_limit,
)
} else {
self.execute_benchmark_parallel(
&transactions,
conurrency_level_per_shard,
concurrency_level_per_shard,
maybe_block_gas_limit,
)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ use aptos_language_e2e_tests::data_store::{FakeDataStore, GENESIS_CHANGE_SET_HEA
use aptos_resource_viewer::{AnnotatedMoveValue, AptosValueAnnotator};
use aptos_types::{
account_config::{aptos_test_root_address, AccountResource, CoinStoreResource},
block_executor::config::BlockExecutorConfigFromOnchain,
block_metadata::BlockMetadata,
chain_id::ChainId,
contract_event::ContractEvent,
on_chain_config::BlockGasLimitType,
state_store::{state_key::StateKey, table::TableHandle, TStateView},
transaction::{
signature_verified_transaction::into_signature_verified_block,
Expand Down Expand Up @@ -517,14 +515,8 @@ impl<'a> AptosTestAdapter<'a> {
fn run_transaction(&mut self, txn: Transaction) -> Result<TransactionOutput> {
let txn_block = vec![txn];
let sig_verified_block = into_signature_verified_block(txn_block);
let onchain_config = BlockExecutorConfigFromOnchain {
// TODO fetch values from state?
// Or should we just use execute_block_no_limit ?
block_gas_limit_type: BlockGasLimitType::Limit(30000),
};
let (mut outputs, _) = AptosVMBlockExecutor::new()
.execute_block(&sig_verified_block, &self.storage.clone(), onchain_config)?
.into_inner();
let mut outputs = AptosVMBlockExecutor::new()
.execute_block_no_limit(&sig_verified_block, &self.storage.clone())?;

assert_eq!(outputs.len(), 1);

Expand Down
10 changes: 8 additions & 2 deletions aptos-move/aptos-vm-environment/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use aptos_native_interface::SafeNativeBuilder;
use aptos_types::{
chain_id::ChainId,
on_chain_config::{
ConfigurationResource, Features, OnChainConfig, TimedFeatures, TimedFeaturesBuilder,
ConfigurationResource, FeatureFlag, Features, OnChainConfig, TimedFeatures,
TimedFeaturesBuilder,
},
state_store::StateView,
};
Expand Down Expand Up @@ -175,8 +176,13 @@ impl Environment {
) -> Self {
// We compute and store a hash of configs in order to distinguish different environments.
let mut sha3_256 = Sha3_256::new();
let features =
let mut features =
fetch_config_and_update_hash::<Features>(&mut sha3_256, state_view).unwrap_or_default();
if std::env::var("USE_LOADER_V2").is_ok() {
features.enable(FeatureFlag::ENABLE_LOADER_V2);
} else {
features.disable(FeatureFlag::ENABLE_LOADER_V2);
}

// If no chain ID is in storage, we assume we are in a testing environment.
let chain_id = fetch_config_and_update_hash::<ChainId>(&mut sha3_256, state_view)
Expand Down
4 changes: 2 additions & 2 deletions aptos-move/aptos-vm-profiling/src/bins/run_aptos_p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ fn main() -> Result<()> {
})
.collect();

let res = AptosVMBlockExecutor::new().execute_block_no_limit(&txns, &state_store)?;
let outputs = AptosVMBlockExecutor::new().execute_block_no_limit(&txns, &state_store)?;
for i in 0..NUM_TXNS {
assert!(res[i as usize].status().status().unwrap().is_success());
assert!(outputs[i as usize].status().status().unwrap().is_success());
}

Ok(())
Expand Down
Loading
Loading