Skip to content

Commit

Permalink
Merge pull request #376 from blockworks-foundation/feature/benchrunne…
Browse files Browse the repository at this point in the history
…r-tc1-tc2

benchrunner tc2 integration
  • Loading branch information
Lou-Kamades authored Mar 28, 2024
2 parents bc096d1 + 9f73f8e commit 9926d2e
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 100 deletions.
56 changes: 28 additions & 28 deletions bench/src/benches/confirmation_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ use crate::benches::rpc_interface::{
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::signature::{read_keypair_file, Keypair, Signature, Signer};

#[derive(Debug, serde::Serialize)]
pub struct RpcStat {
tx_sent: u64,
tx_confirmed: u64,
#[derive(Clone, Copy, Debug, Default, serde::Serialize)]
pub struct Metric {
pub txs_sent: u64,
pub txs_confirmed: u64,
// in ms
average_confirmation_time: f32,
pub average_confirmation_time: f32,
// in slots
average_slot_confirmation_time: f32,
tx_send_errors: u64,
tx_unconfirmed: u64,
pub average_slot_confirmation_time: f32,
pub txs_send_errors: u64,
pub txs_un_confirmed: u64,
}

/// TC2 send multiple runs of num_txs, measure the confirmation rate
Expand Down Expand Up @@ -76,7 +76,7 @@ pub async fn send_bulk_txs_and_wait(
num_txs: usize,
tx_params: &BenchmarkTransactionParams,
max_timeout: Duration,
) -> anyhow::Result<RpcStat> {
) -> anyhow::Result<Metric> {
trace!("Get latest blockhash and generate transactions");
let hash = rpc.get_latest_blockhash().await.map_err(|err| {
log::error!("Error get latest blockhash : {err:?}");
Expand Down Expand Up @@ -148,41 +148,41 @@ pub async fn send_bulk_txs_and_wait(
0.0
};

Ok(RpcStat {
tx_sent,
tx_send_errors,
tx_confirmed,
tx_unconfirmed,
Ok(Metric {
txs_sent: tx_sent,
txs_send_errors: tx_send_errors,
txs_confirmed: tx_confirmed,
txs_un_confirmed: tx_unconfirmed,
average_confirmation_time: average_confirmation_time_ms,
average_slot_confirmation_time,
})
}

fn calc_stats_avg(stats: &[RpcStat]) -> RpcStat {
fn calc_stats_avg(stats: &[Metric]) -> Metric {
let len = stats.len();

let mut avg = RpcStat {
tx_sent: 0,
tx_send_errors: 0,
tx_confirmed: 0,
tx_unconfirmed: 0,
let mut avg = Metric {
txs_sent: 0,
txs_send_errors: 0,
txs_confirmed: 0,
txs_un_confirmed: 0,
average_confirmation_time: 0.0,
average_slot_confirmation_time: 0.0,
};

for stat in stats {
avg.tx_sent += stat.tx_sent;
avg.tx_send_errors += stat.tx_send_errors;
avg.tx_confirmed += stat.tx_confirmed;
avg.tx_unconfirmed += stat.tx_unconfirmed;
avg.txs_sent += stat.txs_sent;
avg.txs_send_errors += stat.txs_send_errors;
avg.txs_confirmed += stat.txs_confirmed;
avg.txs_un_confirmed += stat.txs_un_confirmed;
avg.average_confirmation_time += stat.average_confirmation_time;
avg.average_slot_confirmation_time += stat.average_slot_confirmation_time;
}

avg.tx_sent /= len as u64;
avg.tx_send_errors /= len as u64;
avg.tx_confirmed /= len as u64;
avg.tx_unconfirmed /= len as u64;
avg.txs_sent /= len as u64;
avg.txs_send_errors /= len as u64;
avg.txs_confirmed /= len as u64;
avg.txs_un_confirmed /= len as u64;
avg.average_confirmation_time /= len as f32;
avg.average_slot_confirmation_time /= len as f32;

Expand Down
3 changes: 2 additions & 1 deletion bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub mod bench1;
pub mod benches;
pub mod helpers;
pub mod metrics;
pub mod service_adapter;
pub mod service_adapter1;
pub mod service_adapter_new;
pub mod tx_size;

#[derive(Parser, Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use tokio::time::Instant;
#[derive(Debug, Clone)]
pub struct BenchConfig {
pub tx_count: usize,
pub tx_size: TxSize,
pub cu_price_micro_lamports: u64,
}

Expand All @@ -33,11 +34,10 @@ pub async fn bench_servicerunner(
bench_config: &BenchConfig,
rpc_addr: String,
funded_payer: Keypair,
size_tx: TxSize,
) -> Metric {
let started_at = Instant::now();

let transaction_size = match size_tx {
let transaction_size = match bench_config.tx_size {
TxSize::Small => TransactionSize::Small,
TxSize::Large => TransactionSize::Large,
};
Expand Down
34 changes: 34 additions & 0 deletions bench/src/service_adapter_new.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::benches::confirmation_rate;
use crate::benches::confirmation_rate::send_bulk_txs_and_wait;
use crate::service_adapter1::BenchConfig;
use crate::BenchmarkTransactionParams;
use log::error;
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::signature::Keypair;
use std::sync::Arc;
use std::time::Duration;

pub async fn benchnew_confirmation_rate_servicerunner(
bench_config: &BenchConfig,
rpc_addr: String,
funded_payer: Keypair,
) -> confirmation_rate::Metric {
let rpc = Arc::new(RpcClient::new(rpc_addr));
let tx_params = BenchmarkTransactionParams {
tx_size: bench_config.tx_size,
cu_price_micro_lamports: bench_config.cu_price_micro_lamports,
};
let max_timeout = Duration::from_secs(60);
let result = send_bulk_txs_and_wait(
&rpc,
&funded_payer,
bench_config.tx_count,
&tx_params,
max_timeout,
)
.await;
result.unwrap_or_else(|err| {
error!("Failed to send bulk txs and wait: {}", err);
confirmation_rate::Metric::default()
})
}
19 changes: 19 additions & 0 deletions benchrunner-service/QUERIES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

### Inspect the BenchRunner executions
```postgresql
SELECT * FROM benchrunner.bench_runs
ORDER BY ts DESC
```

### Bench1 (old bench)
```postgresql
SELECT * FROM benchrunner.bench_metrics_bench1
ORDER BY ts DESC
```

### Bench Confirmation Rate
```postgresql
SELECT * FROM benchrunner.bench_metrics_confirmation_rate
ORDER BY ts DESC
```

Loading

0 comments on commit 9926d2e

Please sign in to comment.