Skip to content

Commit

Permalink
add execution latency metrics (MystenLabs#11222)
Browse files Browse the repository at this point in the history
## Description 

as title

## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes

---------

Co-authored-by: Xun Li <[email protected]>
  • Loading branch information
longbowlu and lxfind authored Apr 23, 2023
1 parent 59d645e commit ac6befd
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 62 deletions.
13 changes: 13 additions & 0 deletions crates/sui-json-rpc/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ pub struct JsonRpcMetrics {

pub get_stake_sui_result_size: Histogram,
pub get_stake_sui_result_size_total: IntCounter,

pub orchestrator_latency_ms: Histogram,
pub post_orchestrator_latency_ms: Histogram,
}

impl JsonRpcMetrics {
Expand Down Expand Up @@ -236,6 +239,16 @@ impl JsonRpcMetrics {
registry
)
.unwrap(),
orchestrator_latency_ms: Histogram::new_in_registry(
"json_rpc_orchestrator_latency",
"The latency of submitting transaction via transaction orchestrator, in ms",
registry,
),
post_orchestrator_latency_ms: Histogram::new_in_registry(
"json_rpc_post_orchestrator_latency",
"The latency of response processing after transaction orchestrator, in ms",
registry,
),
}
}

Expand Down
123 changes: 61 additions & 62 deletions crates/sui-json-rpc/src/transaction_execution_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use fastcrypto::traits::ToFromBytes;
use jsonrpsee::core::RpcResult;
use jsonrpsee::RpcModule;

use crate::api::JsonRpcMetrics;
use mysten_metrics::spawn_monitored_task;
use shared_crypto::intent::Intent;
use sui_core::authority::AuthorityState;
Expand Down Expand Up @@ -40,15 +41,18 @@ use crate::{
pub struct TransactionExecutionApi {
state: Arc<AuthorityState>,
transaction_orchestrator: Arc<TransactiondOrchestrator<NetworkAuthorityClient>>,
metrics: Arc<JsonRpcMetrics>,
}
impl TransactionExecutionApi {
pub fn new(
state: Arc<AuthorityState>,
transaction_orchestrator: Arc<TransactiondOrchestrator<NetworkAuthorityClient>>,
metrics: Arc<JsonRpcMetrics>,
) -> Self {
Self {
state,
transaction_orchestrator,
metrics,
}
}

Expand Down Expand Up @@ -97,76 +101,71 @@ impl TransactionExecutionApi {
};

let transaction_orchestrator = self.transaction_orchestrator.clone();
let orch_timer = self.metrics.orchestrator_latency_ms.start_timer();
let response = spawn_monitored_task!(transaction_orchestrator.execute_transaction_block(
ExecuteTransactionRequest {
transaction: txn,
request_type,
}
))
.await??;

match response {
ExecuteTransactionResponse::EffectsCert(cert) => {
let (effects, transaction_events, is_executed_locally) = *cert;
let mut events: Option<SuiTransactionBlockEvents> = None;
if opts.show_events {
let module_cache = self
.state
.load_epoch_store_one_call_per_task()
.module_cache()
.clone();
events = Some(SuiTransactionBlockEvents::try_from(
transaction_events,
digest,
None,
module_cache.as_ref(),
)?);
}

let object_cache = ObjectProviderCache::new(self.state.clone());
let balance_changes = if opts.show_balance_changes {
Some(
get_balance_changes_from_effect(
&object_cache,
&effects.effects,
input_objs,
None,
)
.await?,
)
} else {
None
};
let object_changes = if opts.show_object_changes {
Some(
get_object_changes(
&object_cache,
sender,
effects.effects.modified_at_versions(),
effects.effects.all_changed_objects(),
effects.effects.all_deleted(),
)
.await?,
)
} else {
None
};

Ok(SuiTransactionBlockResponse {
digest,
transaction,
raw_transaction,
effects: opts.show_effects.then_some(effects.effects.try_into()?),
events,
object_changes,
balance_changes,
timestamp_ms: None,
confirmed_local_execution: Some(is_executed_locally),
checkpoint: None,
errors: vec![],
})
}
drop(orch_timer);

let _post_orch_timer = self.metrics.post_orchestrator_latency_ms.start_timer();
let ExecuteTransactionResponse::EffectsCert(cert) = response;
let (effects, transaction_events, is_executed_locally) = *cert;
let mut events: Option<SuiTransactionBlockEvents> = None;
if opts.show_events {
let module_cache = self
.state
.load_epoch_store_one_call_per_task()
.module_cache()
.clone();
events = Some(SuiTransactionBlockEvents::try_from(
transaction_events,
digest,
None,
module_cache.as_ref(),
)?);
}

let object_cache = ObjectProviderCache::new(self.state.clone());
let balance_changes = if opts.show_balance_changes {
Some(
get_balance_changes_from_effect(&object_cache, &effects.effects, input_objs, None)
.await?,
)
} else {
None
};
let object_changes = if opts.show_object_changes {
Some(
get_object_changes(
&object_cache,
sender,
effects.effects.modified_at_versions(),
effects.effects.all_changed_objects(),
effects.effects.all_deleted(),
)
.await?,
)
} else {
None
};

Ok(SuiTransactionBlockResponse {
digest,
transaction,
raw_transaction,
effects: opts.show_effects.then_some(effects.effects.try_into()?),
events,
object_changes,
balance_changes,
timestamp_ms: None,
confirmed_local_execution: Some(is_executed_locally),
checkpoint: None,
errors: vec![],
})
}

async fn dry_run_transaction_block(
Expand Down
1 change: 1 addition & 0 deletions crates/sui-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,7 @@ pub async fn build_server(
server.register_module(TransactionExecutionApi::new(
state.clone(),
transaction_orchestrator.clone(),
metrics.clone(),
))?;
}

Expand Down

0 comments on commit ac6befd

Please sign in to comment.