Skip to content

Commit

Permalink
add transaction bytes to metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Sep 29, 2023
1 parent fbd710e commit 6301b81
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
18 changes: 13 additions & 5 deletions bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use dashmap::DashMap;
use futures::future::join_all;
use log::{error, info, warn};
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::signature::Signature;
use solana_sdk::{
commitment_config::CommitmentConfig, hash::Hash, signature::Keypair, signer::Signer,
slot_history::Slot,
Expand Down Expand Up @@ -43,14 +44,14 @@ async fn main() {
TransactionSize::Small
};

info!("Connecting to {lite_rpc_addr}");
info!("Connecting to LiteRPC using {lite_rpc_addr}");

let mut avg_metric = AvgMetric::default();

let mut tasks = vec![];

let funded_payer = BenchHelper::get_payer().await.unwrap();
println!("payer : {}", funded_payer.pubkey());
info!("Payer: {}", funded_payer.pubkey());

let rpc_client = Arc::new(RpcClient::new_with_commitment(
lite_rpc_addr.clone(),
Expand Down Expand Up @@ -150,6 +151,7 @@ struct TxSendData {
sent_duration: Duration,
sent_instant: Instant,
sent_slot: Slot,
transaction_bytes: u64,
}

#[allow(clippy::too_many_arguments)]
Expand All @@ -164,7 +166,7 @@ async fn bench(
log_txs: bool,
transaction_size: TransactionSize,
) -> Metric {
let map_of_txs = Arc::new(DashMap::new());
let map_of_txs: Arc<DashMap<Signature, TxSendData>> = Arc::new(DashMap::new());
// transaction sender task
{
let map_of_txs = map_of_txs.clone();
Expand Down Expand Up @@ -197,6 +199,7 @@ async fn bench(
sent_duration: start_time.elapsed(),
sent_instant: Instant::now(),
sent_slot: current_slot.load(std::sync::atomic::Ordering::Relaxed),
transaction_bytes: bincode::serialized_size(&tx).unwrap(),
},
);
}
Expand Down Expand Up @@ -226,7 +229,12 @@ async fn bench(
if tx_status.is_some() {
let tx_data = map_of_txs.get(signature).unwrap();
let time_to_confirm = tx_data.sent_instant.elapsed();
metric.add_successful_transaction(tx_data.sent_duration, time_to_confirm);
let transaction_bytes = tx_data.transaction_bytes;
metric.add_successful_transaction(
tx_data.sent_duration,
time_to_confirm,
transaction_bytes,
);

if log_txs {
let _ = tx_metric_sx.send(TxMetricData {
Expand All @@ -246,7 +254,7 @@ async fn bench(
}

for tx in map_of_txs.iter() {
metric.add_unsuccessful_transaction(tx.sent_duration);
metric.add_unsuccessful_transaction(tx.sent_duration, tx.transaction_bytes);
}
metric.finalize();
metric
Expand Down
12 changes: 11 additions & 1 deletion bench/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ pub struct Metric {
pub txs_un_confirmed: u64,
pub average_confirmation_time_ms: f64,
pub average_time_to_send_txs: f64,
pub average_transaction_bytes: f64,

#[serde(skip_serializing)]
total_sent_time: Duration,
#[serde(skip_serializing)]
total_transaction_bytes: u64,
#[serde(skip_serializing)]
total_confirmation_time: Duration,
}

Expand All @@ -24,16 +27,19 @@ impl Metric {
&mut self,
time_to_send: Duration,
time_to_confrim: Duration,
transaction_bytes: u64,
) {
self.total_sent_time += time_to_send;
self.total_confirmation_time += time_to_confrim;
self.total_transaction_bytes += transaction_bytes;

self.txs_confirmed += 1;
self.txs_sent += 1;
}

pub fn add_unsuccessful_transaction(&mut self, time_to_send: Duration) {
pub fn add_unsuccessful_transaction(&mut self, time_to_send: Duration, transaction_bytes: u64) {
self.total_sent_time += time_to_send;
self.total_transaction_bytes += transaction_bytes;
self.txs_un_confirmed += 1;
self.txs_sent += 1;
}
Expand All @@ -42,6 +48,8 @@ impl Metric {
if self.txs_sent > 0 {
self.average_time_to_send_txs =
self.total_sent_time.as_millis() as f64 / self.txs_sent as f64;
self.average_transaction_bytes =
self.total_transaction_bytes as f64 / self.txs_sent as f64;
}

if self.txs_confirmed > 0 {
Expand Down Expand Up @@ -71,6 +79,7 @@ impl AddAssign<&Self> for Metric {

self.total_confirmation_time += rhs.total_confirmation_time;
self.total_sent_time += rhs.total_sent_time;
self.total_transaction_bytes += rhs.total_transaction_bytes;
self.finalize();
}
}
Expand All @@ -89,6 +98,7 @@ impl DivAssign<u64> for Metric {
Duration::from_micros((self.total_confirmation_time.as_micros() / rhs as u128) as u64);
self.total_sent_time =
Duration::from_micros((self.total_sent_time.as_micros() / rhs as u128) as u64);
self.total_transaction_bytes = self.total_transaction_bytes / rhs;
self.finalize();
}
}
Expand Down

0 comments on commit 6301b81

Please sign in to comment.