Skip to content

Commit

Permalink
fix gross total time value
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Oct 4, 2023
1 parent 6b61f0b commit 9785dd3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
16 changes: 11 additions & 5 deletions bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ use solana_sdk::{
commitment_config::CommitmentConfig, hash::Hash, signature::Keypair, signer::Signer,
slot_history::Slot,
};
use std::sync::{atomic::{AtomicU64, Ordering}, Arc};
use std::sync::{
atomic::{AtomicU64, Ordering},
Arc,
};
use tokio::sync::OnceCell;
use tokio::{
sync::{mpsc::UnboundedSender, RwLock},
time::{Duration, Instant},
};
use tokio::sync::OnceCell;

#[tokio::main(flavor = "multi_thread", worker_threads = 16)]
async fn main() {
Expand Down Expand Up @@ -187,11 +190,12 @@ async fn bench(
}
}
}
total_gross_send_time.set(bench_start_time.elapsed()).unwrap();
total_gross_send_time
.set(bench_start_time.elapsed())
.unwrap();
});
} // -- main act: send the transactions


let mut metric = Metric::default();
let confirmation_time = Instant::now();
let mut confirmed_count = 0;
Expand Down Expand Up @@ -233,7 +237,9 @@ async fn bench(
metric.add_unsuccessful_transaction(tx.sent_duration);
}

metric.set_total_gross_send_time(total_gross_send_time.get().unwrap().as_millis() as f64);
metric.set_total_gross_send_time(
total_gross_send_time.get().unwrap().as_micros() as f64 / 1_000.0,
);

metric.finalize();
metric
Expand Down
10 changes: 5 additions & 5 deletions bench/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@ impl Metric {
}

if self.total_gross_send_time_ms > 0.01 {
self.send_tps =
1000.0 * self.txs_sent as f64 / self.total_gross_send_time_ms;
let total_gross_send_time_secs = self.total_gross_send_time_ms / 1_000.0;
self.send_tps = self.txs_sent as f64 / total_gross_send_time_secs;
}

if self.txs_confirmed > 0 {
self.average_confirmation_time_ms =
self.total_confirmation_time.as_millis() as f64 / self.txs_confirmed as f64;
}

}

pub fn set_total_gross_send_time(&mut self, total_gross_send_time_ms: f64) {
Expand Down Expand Up @@ -84,6 +83,7 @@ impl AddAssign<&Self> for Metric {

self.total_confirmation_time += rhs.total_confirmation_time;
self.total_sent_time += rhs.total_sent_time;
self.total_gross_send_time_ms += rhs.total_gross_send_time_ms;
self.send_tps += rhs.send_tps;

self.finalize();
Expand All @@ -104,8 +104,8 @@ 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.send_tps =
self.send_tps / rhs as f64;
self.send_tps = self.send_tps / rhs as f64;
self.total_gross_send_time_ms = self.total_gross_send_time_ms / rhs as f64;

self.finalize();
}
Expand Down

0 comments on commit 9785dd3

Please sign in to comment.