From 192adc81322c81acd76b39ba328308271da451d1 Mon Sep 17 00:00:00 2001 From: Zhe Wu Date: Mon, 9 Oct 2023 15:57:33 -0700 Subject: [PATCH 1/2] A draft of adding benchmark for transaction signing --- .../src/benchmark_context.rs | 15 ++++++++ .../sui-single-node-benchmark/src/command.rs | 2 + .../src/execution.rs | 37 +++++++++++++++++-- .../src/single_node.rs | 15 ++++++++ 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/crates/sui-single-node-benchmark/src/benchmark_context.rs b/crates/sui-single-node-benchmark/src/benchmark_context.rs index 54489cf7fcbc9..730f5f21821bf 100644 --- a/crates/sui-single-node-benchmark/src/benchmark_context.rs +++ b/crates/sui-single-node-benchmark/src/benchmark_context.rs @@ -232,4 +232,19 @@ impl BenchmarkContext { *gas_objects = Arc::new(refreshed_gas_objects); } } + + pub(crate) async fn validator_sign_transactions(&self, transactions: Vec) { + info!( + "Started signing {} transactions. You can now attach a profiler", + transactions.len(), + ); + let tasks: FuturesUnordered<_> = transactions + .into_iter() + .map(|tx| { + let validator = self.validator(); + tokio::spawn(async move { validator.sign_transaction(tx).await }) + }) + .collect(); + let _results: Vec<_> = tasks.collect().await; + } } diff --git a/crates/sui-single-node-benchmark/src/command.rs b/crates/sui-single-node-benchmark/src/command.rs index 32a90007fd129..6d64ff21fe88e 100644 --- a/crates/sui-single-node-benchmark/src/command.rs +++ b/crates/sui-single-node-benchmark/src/command.rs @@ -84,4 +84,6 @@ pub enum Component { /// and store the sequenced transactions into the store. It covers the consensus-independent /// portion of the code in consensus handler. ValidatorWithFakeConsensus, + /// Benchmark only validator signing compoment: `handle_transaction`. + TxnSigning, } diff --git a/crates/sui-single-node-benchmark/src/execution.rs b/crates/sui-single-node-benchmark/src/execution.rs index 0eeec8bcd37d9..d989e733297ee 100644 --- a/crates/sui-single-node-benchmark/src/execution.rs +++ b/crates/sui-single-node-benchmark/src/execution.rs @@ -22,7 +22,7 @@ pub async fn benchmark_simple_transfer(tx_count: u64, component: Component) { let transactions = ctx .generate_transactions(Arc::new(NonMoveTxGenerator::new())) .await; - benchmark_transactions(&ctx, transactions).await; + benchmark_transactions(&ctx, transactions, component).await; } /// Benchmark Move transactions. @@ -57,7 +57,7 @@ pub async fn benchmark_move_transactions( root_objects, ))) .await; - benchmark_transactions(&ctx, transactions).await; + benchmark_transactions(&ctx, transactions, component).await; } /// In order to benchmark transactions that can read dynamic fields, we must first create @@ -104,8 +104,23 @@ async fn preparing_dynamic_fields( root_objects } +async fn benchmark_transactions( + ctx: &BenchmarkContext, + transactions: Vec, + component: Component, +) { + match component { + Component::TxnSigning => { + benchmark_transaction_signing(ctx, transactions).await; + } + _ => { + benchmark_transaction_execution(ctx, transactions).await; + } + } +} + /// Benchmark parallel execution of a vector of transactions and measure the TPS. -async fn benchmark_transactions(ctx: &BenchmarkContext, transactions: Vec) { +async fn benchmark_transaction_execution(ctx: &BenchmarkContext, transactions: Vec) { let mut transactions = ctx.certify_transactions(transactions).await; // Print out a sample transaction and its effects so that we can get a rough idea @@ -129,3 +144,19 @@ async fn benchmark_transactions(ctx: &BenchmarkContext, transactions: Vec) { + let sample_transaction = &transactions[0]; + info!("Sample transaction: {:?}", sample_transaction.data()); + + let tx_count = transactions.len(); + let start_time = std::time::Instant::now(); + ctx.validator_sign_transactions(transactions).await; + let elapsed = start_time.elapsed().as_millis() as f64 / 1000f64; + info!( + "Transaction signing finished in {}s, TPS={}", + elapsed, + tx_count as f64 / elapsed + ); +} diff --git a/crates/sui-single-node-benchmark/src/single_node.rs b/crates/sui-single-node-benchmark/src/single_node.rs index cf64f6a86fb1e..be0efbb7ad881 100644 --- a/crates/sui-single-node-benchmark/src/single_node.rs +++ b/crates/sui-single-node-benchmark/src/single_node.rs @@ -18,6 +18,7 @@ use sui_types::committee::Committee; use sui_types::crypto::AccountKeyPair; use sui_types::effects::{TransactionEffects, TransactionEffectsAPI}; use sui_types::executable_transaction::VerifiedExecutableTransaction; +use sui_types::messages_grpc::HandleTransactionResponse; use sui_types::object::Object; use sui_types::transaction::{ CertifiedTransaction, Transaction, VerifiedCertificate, VerifiedTransaction, @@ -115,6 +116,7 @@ impl SingleValidator { cert: CertifiedTransaction, component: Component, ) -> TransactionEffects { + assert!(!matches!(component, Component::TxnSigning)); let effects = match component { Component::Baseline => { let cert = VerifiedExecutableTransaction::new_from_certificate( @@ -142,8 +144,21 @@ impl SingleValidator { .await; response.signed_effects.into_data() } + Component::TxnSigning => unreachable!(), }; assert!(effects.status().is_ok()); effects } + + pub async fn sign_transaction(&self, transaction: Transaction) -> HandleTransactionResponse { + let result = self + .get_validator() + .handle_transaction( + &self.epoch_store, + VerifiedTransaction::new_unchecked(transaction), + ) + .await + .unwrap(); + result + } } From c597dcb780b8e2be6c2f4010fa2eacdb8ad415ca Mon Sep 17 00:00:00 2001 From: Zhe Wu Date: Tue, 10 Oct 2023 17:19:11 -0700 Subject: [PATCH 2/2] Create handle_transaction_for_testing to use transaction trait to measure signing performance --- crates/sui-core/src/authority_server.rs | 10 ++++++++++ .../sui-single-node-benchmark/src/benchmark_context.rs | 9 +++++++-- crates/sui-single-node-benchmark/src/execution.rs | 4 ++-- crates/sui-single-node-benchmark/src/single_node.rs | 10 ++-------- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/crates/sui-core/src/authority_server.rs b/crates/sui-core/src/authority_server.rs index 82657614bc0ef..cac6ec29236c0 100644 --- a/crates/sui-core/src/authority_server.rs +++ b/crates/sui-core/src/authority_server.rs @@ -248,6 +248,16 @@ impl ValidatorService { .into_inner() } + pub async fn handle_transaction_for_testing( + &self, + transaction: Transaction, + ) -> HandleTransactionResponse { + self.transaction(tonic::Request::new(transaction)) + .await + .unwrap() + .into_inner() + } + async fn handle_transaction( self, request: tonic::Request, diff --git a/crates/sui-single-node-benchmark/src/benchmark_context.rs b/crates/sui-single-node-benchmark/src/benchmark_context.rs index 730f5f21821bf..5f5e1f584f6ca 100644 --- a/crates/sui-single-node-benchmark/src/benchmark_context.rs +++ b/crates/sui-single-node-benchmark/src/benchmark_context.rs @@ -13,6 +13,7 @@ use std::sync::Arc; use sui_types::base_types::{ObjectID, ObjectRef, SuiAddress, SUI_ADDRESS_LENGTH}; use sui_types::crypto::{get_account_key_pair, AccountKeyPair}; use sui_types::effects::TransactionEffects; +use sui_types::messages_grpc::HandleTransactionResponse; use sui_types::object::Object; use sui_types::transaction::{CertifiedTransaction, SignedTransaction, Transaction}; use tracing::info; @@ -233,7 +234,10 @@ impl BenchmarkContext { } } - pub(crate) async fn validator_sign_transactions(&self, transactions: Vec) { + pub(crate) async fn validator_sign_transactions( + &self, + transactions: Vec, + ) -> Vec { info!( "Started signing {} transactions. You can now attach a profiler", transactions.len(), @@ -245,6 +249,7 @@ impl BenchmarkContext { tokio::spawn(async move { validator.sign_transaction(tx).await }) }) .collect(); - let _results: Vec<_> = tasks.collect().await; + let results: Vec<_> = tasks.collect().await; + results.into_iter().map(|r| r.unwrap()).collect() } } diff --git a/crates/sui-single-node-benchmark/src/execution.rs b/crates/sui-single-node-benchmark/src/execution.rs index d989e733297ee..654ea53046838 100644 --- a/crates/sui-single-node-benchmark/src/execution.rs +++ b/crates/sui-single-node-benchmark/src/execution.rs @@ -155,8 +155,8 @@ async fn benchmark_transaction_signing(ctx: &BenchmarkContext, transactions: Vec ctx.validator_sign_transactions(transactions).await; let elapsed = start_time.elapsed().as_millis() as f64 / 1000f64; info!( - "Transaction signing finished in {}s, TPS={}", + "Transaction signing finished in {}s, TPS={}.", elapsed, - tx_count as f64 / elapsed + tx_count as f64 / elapsed, ); } diff --git a/crates/sui-single-node-benchmark/src/single_node.rs b/crates/sui-single-node-benchmark/src/single_node.rs index be0efbb7ad881..06b3f306d7282 100644 --- a/crates/sui-single-node-benchmark/src/single_node.rs +++ b/crates/sui-single-node-benchmark/src/single_node.rs @@ -151,14 +151,8 @@ impl SingleValidator { } pub async fn sign_transaction(&self, transaction: Transaction) -> HandleTransactionResponse { - let result = self - .get_validator() - .handle_transaction( - &self.epoch_store, - VerifiedTransaction::new_unchecked(transaction), - ) + self.validator_service + .handle_transaction_for_testing(transaction) .await - .unwrap(); - result } }