Merge pull request #220 from blockworks-foundation/groovie/bench-send-tps-metric

bench: add send_tps metric
This commit is contained in:
Steve 2023-10-04 21:05:12 +02:00 committed by GitHub
commit e8d4c95142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 3 deletions

View File

@ -154,6 +154,10 @@ struct TxSendData {
transaction_bytes: u64,
}
struct ApiCallerResult {
gross_send_time: Duration,
}
#[allow(clippy::too_many_arguments)]
async fn bench(
rpc_client: Arc<RpcClient>,
@ -168,7 +172,7 @@ async fn bench(
) -> Metric {
let map_of_txs: Arc<DashMap<Signature, TxSendData>> = Arc::new(DashMap::new());
// transaction sender task
{
let api_caller_result = {
let map_of_txs = map_of_txs.clone();
let rpc_client = rpc_client.clone();
let current_slot = current_slot.clone();
@ -180,6 +184,8 @@ async fn bench(
};
let rand_strings = BenchHelper::generate_random_strings(tx_count, Some(seed), n_chars);
let bench_start_time = Instant::now();
for rand_string in &rand_strings {
let blockhash = { *block_hash.read().await };
let tx = match transaction_size {
@ -208,8 +214,11 @@ async fn bench(
}
}
}
});
ApiCallerResult {
gross_send_time: bench_start_time.elapsed(),
}
})
};
let mut metric = Metric::default();
let confirmation_time = Instant::now();
@ -256,6 +265,14 @@ async fn bench(
for tx in map_of_txs.iter() {
metric.add_unsuccessful_transaction(tx.sent_duration, tx.transaction_bytes);
}
let api_caller_result = api_caller_result
.await
.expect("api caller task must succeed");
metric
.set_total_gross_send_time(api_caller_result.gross_send_time.as_micros() as f64 / 1_000.0);
metric.finalize();
metric
}

View File

@ -13,6 +13,7 @@ pub struct Metric {
pub average_confirmation_time_ms: f64,
pub average_time_to_send_txs: f64,
pub average_transaction_bytes: f64,
pub send_tps: f64,
#[serde(skip_serializing)]
total_sent_time: Duration,
@ -20,6 +21,8 @@ pub struct Metric {
total_transaction_bytes: u64,
#[serde(skip_serializing)]
total_confirmation_time: Duration,
#[serde(skip_serializing)]
total_gross_send_time_ms: f64,
}
impl Metric {
@ -52,11 +55,20 @@ impl Metric {
self.total_transaction_bytes as f64 / self.txs_sent as f64;
}
if self.total_gross_send_time_ms > 0.01 {
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) {
self.total_gross_send_time_ms = total_gross_send_time_ms;
}
}
#[derive(Default)]
@ -80,6 +92,9 @@ 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.total_gross_send_time_ms += rhs.total_gross_send_time_ms;
self.send_tps += rhs.send_tps;
self.finalize();
}
}
@ -99,6 +114,9 @@ impl DivAssign<u64> for Metric {
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.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();
}
}