Skip to content

Commit

Permalink
benchmark with native executor
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Oct 27, 2024
1 parent c070f4c commit 05826a1
Show file tree
Hide file tree
Showing 13 changed files with 833 additions and 352 deletions.
22 changes: 5 additions & 17 deletions crates/aptos-rosetta/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use aptos_crypto::{
};
use aptos_rest_client::aptos_api_types::{ResourceGroup, TransactionOnChainData};
use aptos_types::{
account_config::fungible_store::FungibleStoreResource,
account_config::{fungible_store::FungibleStoreResource, DepositFAEvent, MoveEventV2, WithdrawFAEvent},
chain_id::ChainId,
contract_event::ContractEvent,
event::{EventHandle, EventKey},
Expand Down Expand Up @@ -126,35 +126,23 @@ impl FaData {
};

let (new_balance, contract_event) = if self.deposit {
let type_tag = TypeTag::Struct(Box::new(StructTag {
address: AccountAddress::ONE,
module: ident_str!(FUNGIBLE_ASSET_MODULE).into(),
name: ident_str!("Deposit").into(),
type_args: vec![],
}));
let event = FungibleAssetChangeEvent {
let event = DepositFAEvent {
store: self.store_address,
amount: self.amount,
};
(
self.previous_balance + self.amount,
ContractEvent::new_v2(type_tag, bcs::to_bytes(&event).unwrap()),
event.create_event_v2(),
)
} else {
let event = FungibleAssetChangeEvent {
let event = WithdrawFAEvent {
store: self.store_address,
amount: self.amount,
};
let type_tag = TypeTag::Struct(Box::new(StructTag {
address: AccountAddress::ONE,
module: ident_str!(FUNGIBLE_ASSET_MODULE).into(),
name: ident_str!("Withdraw").into(),
type_args: vec![],
}));

(
self.previous_balance - self.amount,
ContractEvent::new_v2(type_tag, bcs::to_bytes(&event).unwrap()),
event.create_event_v2(),
)
};

Expand Down
6 changes: 0 additions & 6 deletions crates/aptos-rosetta/src/types/move_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,6 @@ pub struct WithdrawUndelegatedEvent {
pub amount_withdrawn: u64,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct FungibleAssetChangeEvent {
pub store: AccountAddress,
pub amount: u64,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ObjectCore {
pub guid_creation_num: u64,
Expand Down
35 changes: 20 additions & 15 deletions execution/executor-benchmark/src/block_preparation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use crate::{metrics::TIMER, pipeline::ExecuteBlockMessage};
use crate::{metrics::{NUM_TXNS, TIMER}, pipeline::ExecuteBlockMessage};
use aptos_block_partitioner::{BlockPartitioner, PartitionerConfig};
use aptos_crypto::HashValue;
use aptos_experimental_runtimes::thread_manager::optimal_min_len;
Expand All @@ -10,39 +10,35 @@ use aptos_types::{
block_executor::partitioner::{ExecutableBlock, ExecutableTransactions},
transaction::{signature_verified_transaction::SignatureVerifiedTransaction, Transaction},
};
use once_cell::sync::Lazy;
use rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};
use std::{sync::Arc, time::Instant};

pub static SIG_VERIFY_POOL: Lazy<Arc<rayon::ThreadPool>> = Lazy::new(|| {
Arc::new(
rayon::ThreadPoolBuilder::new()
.num_threads(8) // More than 8 threads doesn't seem to help much
.thread_name(|index| format!("signature-checker-{}", index))
.build()
.unwrap(),
)
});
use std::time::Instant;

pub(crate) struct BlockPreparationStage {
num_executor_shards: usize,
num_blocks_processed: usize,
maybe_partitioner: Option<Box<dyn BlockPartitioner>>,
sig_verify_pool: rayon::ThreadPool,
}

impl BlockPreparationStage {
pub fn new(num_shards: usize, partitioner_config: &dyn PartitionerConfig) -> Self {
pub fn new(sig_verify_num_threads: usize, num_shards: usize, partitioner_config: &dyn PartitionerConfig) -> Self {
let maybe_partitioner = if num_shards == 0 {
None
} else {
let partitioner = partitioner_config.build();
Some(partitioner)
};

let sig_verify_pool = rayon::ThreadPoolBuilder::new()
.num_threads(sig_verify_num_threads) // More than 8 threads doesn't seem to help much
.thread_name(|index| format!("signature-checker-{}", index))
.build()
.unwrap();
Self {
num_executor_shards: num_shards,
num_blocks_processed: 0,
maybe_partitioner,
sig_verify_pool,
}
}

Expand All @@ -54,8 +50,14 @@ impl BlockPreparationStage {
txns.len()
);
let block_id = HashValue::random();
let sig_verified_txns: Vec<SignatureVerifiedTransaction> = SIG_VERIFY_POOL.install(|| {
let sig_verified_txns: Vec<SignatureVerifiedTransaction> = self.sig_verify_pool.install(|| {
let _timer = TIMER.with_label_values(&["sig_verify"]).start_timer();

let num_txns = txns.len();
NUM_TXNS
.with_label_values(&["sig_verify"])
.inc_by(num_txns as u64);

txns.into_par_iter()
.with_min_len(optimal_min_len(num_txns, 32))
.map(|t| t.into())
Expand All @@ -64,6 +66,9 @@ impl BlockPreparationStage {
let block: ExecutableBlock = match &self.maybe_partitioner {
None => (block_id, sig_verified_txns).into(),
Some(partitioner) => {
NUM_TXNS
.with_label_values(&["partition"])
.inc_by(sig_verified_txns.len() as u64);
let analyzed_transactions =
sig_verified_txns.into_iter().map(|t| t.into()).collect();
let timer = TIMER.with_label_values(&["partition"]).start_timer();
Expand Down
37 changes: 23 additions & 14 deletions execution/executor-benchmark/src/db_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
use anyhow::Result;
use aptos_storage_interface::state_view::DbStateView;
use aptos_types::{
account_address::AccountAddress,
state_store::{state_key::StateKey, StateView},
write_set::TOTAL_SUPPLY_STATE_KEY,
account_address::AccountAddress, account_config::{CoinStoreResource, FungibleStoreResource, ObjectGroupResource}, state_store::{state_key::StateKey, StateView}, write_set::TOTAL_SUPPLY_STATE_KEY, AptosCoinType
};
use move_core_types::{
identifier::Identifier,
language_storage::{StructTag, TypeTag},
language_storage::{StructTag, TypeTag}, move_resource::MoveStructType,
};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::str::FromStr;
use std::{collections::BTreeMap, str::FromStr};

#[derive(Debug, Default, Deserialize, Serialize)]
pub struct CoinStore {
Expand Down Expand Up @@ -88,15 +86,12 @@ impl DbAccessUtil {
Self::new_state_key(address, AccountAddress::ONE, "account", "Account", vec![])
}

pub fn new_state_key_aptos_coin(address: AccountAddress) -> StateKey {
Self::new_state_key(address, AccountAddress::ONE, "coin", "CoinStore", vec![
TypeTag::Struct(Box::new(Self::new_struct_tag(
AccountAddress::ONE,
"aptos_coin",
"AptosCoin",
vec![],
))),
])
pub fn new_state_key_aptos_coin(address: &AccountAddress) -> StateKey {
StateKey::resource_typed::<CoinStoreResource<AptosCoinType>>(address).unwrap()
}

pub fn new_state_key_object_resource_group(address: &AccountAddress) -> StateKey {
StateKey::resource_group(address, &ObjectGroupResource::struct_tag())
}

pub fn get_account(
Expand All @@ -106,6 +101,13 @@ impl DbAccessUtil {
Self::get_value(account_key, state_view)
}

pub fn get_fa_store(
store_key: &StateKey,
state_view: &impl StateView,
) -> Result<Option<FungibleStoreResource>> {
Self::get_value(store_key, state_view)
}

pub fn get_coin_store(
coin_store_key: &StateKey,
state_view: &impl StateView,
Expand All @@ -123,6 +125,13 @@ impl DbAccessUtil {
value.transpose().map_err(anyhow::Error::msg)
}

pub fn get_resource_group(
state_key: &StateKey,
state_view: &impl StateView,
) -> Result<Option<BTreeMap<StructTag, Vec<u8>>>> {
Self::get_value(state_key, state_view)
}

pub fn get_db_value<T: DeserializeOwned>(
state_key: &StateKey,
state_view: &DbStateView,
Expand Down
2 changes: 1 addition & 1 deletion execution/executor-benchmark/src/db_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn create_db_with_accounts<V>(
);
}

fn bootstrap_with_genesis(
pub(crate) fn bootstrap_with_genesis(
db_dir: impl AsRef<Path>,
enable_storage_sharding: bool,
init_features: Features,
Expand Down
2 changes: 1 addition & 1 deletion execution/executor-benchmark/src/db_reliable_submitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct DbReliableTransactionSubmitter {
impl ReliableTransactionSubmitter for DbReliableTransactionSubmitter {
async fn get_account_balance(&self, account_address: AccountAddress) -> Result<u64> {
let db_state_view = self.db.reader.latest_state_checkpoint_view().unwrap();
let sender_coin_store_key = DbAccessUtil::new_state_key_aptos_coin(account_address);
let sender_coin_store_key = DbAccessUtil::new_state_key_aptos_coin(&account_address);
let sender_coin_store =
DbAccessUtil::get_db_value::<CoinStore>(&sender_coin_store_key, &db_state_view)?
.unwrap();
Expand Down
Loading

0 comments on commit 05826a1

Please sign in to comment.