diff --git a/bench/src/benches/confirmation_rate.rs b/bench/src/benches/confirmation_rate.rs index ee4be7af..e24c81e0 100644 --- a/bench/src/benches/confirmation_rate.rs +++ b/bench/src/benches/confirmation_rate.rs @@ -14,14 +14,14 @@ use solana_sdk::signature::{read_keypair_file, Keypair, Signature, Signer}; #[derive(Clone, Copy, Debug, Default, serde::Serialize)] pub struct Metric { - tx_sent: u64, - tx_confirmed: u64, + 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 @@ -149,10 +149,10 @@ pub async fn send_bulk_txs_and_wait( }; Ok(Metric { - tx_sent, - tx_send_errors, - tx_confirmed, - tx_unconfirmed, + 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, }) @@ -162,27 +162,27 @@ fn calc_stats_avg(stats: &[Metric]) -> Metric { let len = stats.len(); let mut avg = Metric { - tx_sent: 0, - tx_send_errors: 0, - tx_confirmed: 0, - tx_unconfirmed: 0, + 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; diff --git a/bench/src/service_adapter_new.rs b/bench/src/service_adapter_new.rs index 58caacd1..e92276e4 100644 --- a/bench/src/service_adapter_new.rs +++ b/bench/src/service_adapter_new.rs @@ -22,7 +22,7 @@ pub async fn benchnew_confirmation_rate_servicerunner( 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, 1, &tx_params, max_timeout).await; + 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() diff --git a/benchrunner-service/src/main.rs b/benchrunner-service/src/main.rs index f64b5f0b..7eeccec3 100644 --- a/benchrunner-service/src/main.rs +++ b/benchrunner-service/src/main.rs @@ -99,13 +99,13 @@ async fn main() { let benchrun_at = SystemTime::now(); - let permutation = factorize(run_count, &[bench_configs.len(), NUM_BENCH_IMPLS]); + let permutation = factorize(run_count, &[NUM_BENCH_IMPLS, bench_configs.len()]); - let bench_config = bench_configs[permutation[0]].clone(); + let bench_config = bench_configs[permutation[1]].clone(); - let bench_impl: Box = match permutation[1] { + let bench_impl: Box = match permutation[0] { 0 => { - Box::new(BenchRunnerBench1Impl { + Box::new(BenchRunnerConfirmationRateImpl { benchrun_at, tenant_config: tenant_config.clone(), bench_config: bench_config.clone(), @@ -115,7 +115,7 @@ async fn main() { }) } 1 => { - Box::new(BenchRunnerConfirmationRateImpl { + Box::new(BenchRunnerBench1Impl { benchrun_at, tenant_config: tenant_config.clone(), bench_config: bench_config.clone(), @@ -238,6 +238,7 @@ impl BenchRunner for BenchRunnerBench1Impl { self.size_tx, ) .await; + self.metric.set(metric).unwrap(); } } diff --git a/benchrunner-service/src/postgres/metrics_dbstore.rs b/benchrunner-service/src/postgres/metrics_dbstore.rs index da91567f..54920d89 100644 --- a/benchrunner-service/src/postgres/metrics_dbstore.rs +++ b/benchrunner-service/src/postgres/metrics_dbstore.rs @@ -83,7 +83,7 @@ impl BenchMetricsPostgresSaver for BenchRunnerBench1Impl { .execute( r#" INSERT INTO - benchrunner.bench_metrics ( + benchrunner.bench_metrics_bench1 ( tenant, ts, prio_fees, @@ -107,7 +107,44 @@ impl BenchMetricsPostgresSaver for BenchRunnerBench1Impl { #[async_trait] impl BenchMetricsPostgresSaver for BenchRunnerConfirmationRateImpl { async fn try_save_results_postgres(&self, postgres_session: &PostgresSessionCache) -> anyhow::Result<()> { - todo!(); + let metric = self.metric.get().expect("metric not set"); + let metricjson = serde_json::to_value(metric).unwrap(); + let values: &[&(dyn ToSql + Sync)] = &[ + &self.tenant_config.tenant_id, + &self.benchrun_at, + &(self.bench_config.cu_price_micro_lamports as i64), + &(metric.txs_sent as i64), + &(metric.txs_confirmed as i64), + &(metric.txs_un_confirmed as i64), + &(metric.average_confirmation_time as f32), + &(metric.average_slot_confirmation_time as f32), + &metricjson, + ]; + postgres_session + .get_session() + .await? + .execute( + r#" + INSERT INTO + benchrunner.bench_metrics_confirmation_rate ( + tenant, + ts, + prio_fees, + txs_sent, + txs_confirmed, + txs_un_confirmed, + average_confirmation_time_ms, + average_slot_confirmation_time_ms, + metric_json + ) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) + "#, + values, + ) + .await?; + + + Ok(()) } } diff --git a/migrations/create_benchrunner.sql b/migrations/create_benchrunner.sql index 77d32450..240b3a5b 100644 --- a/migrations/create_benchrunner.sql +++ b/migrations/create_benchrunner.sql @@ -1,7 +1,16 @@ CREATE SCHEMA benchrunner; -CREATE TABLE benchrunner.bench_metrics ( + +CREATE TABLE benchrunner.bench_runs ( + tenant text NOT NULL, + ts timestamp NOT NULL, + status text NOT NULL, + PRIMARY KEY (tenant, ts) +); + + +CREATE TABLE benchrunner.bench_metrics_bench1 ( tenant text NOT NULL, ts timestamp NOT NULL, prio_fees int8 NOT NULL, @@ -13,14 +22,28 @@ CREATE TABLE benchrunner.bench_metrics ( PRIMARY KEY (tenant, ts) ); -CREATE TABLE benchrunner.bench_runs ( - tenant text NOT NULL, - ts timestamp NOT NULL, - status text NOT NULL, - PRIMARY KEY (tenant, ts) + +CREATE TABLE benchrunner.bench_metrics_confirmation_rate ( + tenant text NOT NULL, + ts timestamp NOT NULL, + prio_fees int8 NOT NULL, + txs_sent int8 NOT NULL, + txs_confirmed int8 NOT NULL, + txs_un_confirmed int8 NOT NULL, + average_confirmation_time_ms real NOT NULL, + average_slot_confirmation_time_ms real NOT NULL, + metric_json jsonb NOT NULL, + PRIMARY KEY (tenant, ts) ); + GRANT USAGE ON SCHEMA benchrunner TO r_benchrunner; -GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA benchrunner TO r_benchrunner; GRANT USAGE ON SCHEMA benchrunner TO ro_benchrunner; + +GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA benchrunner TO r_benchrunner; +ALTER DEFAULT PRIVILEGES IN SCHEMA benchrunner GRANT SELECT, INSERT, UPDATE ON TABLES TO r_benchrunner; + GRANT SELECT ON ALL TABLES IN SCHEMA benchrunner TO ro_benchrunner; +ALTER DEFAULT PRIVILEGES IN SCHEMA benchrunner GRANT SELECT ON TABLES TO ro_benchrunner; + +ALTER TABLE benchrunner.bench_metrics RENAME TO bench_metrics_bench1;