Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Mar 27, 2024
1 parent f3657d7 commit 1f502a3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 67 deletions.
22 changes: 14 additions & 8 deletions bench/src/service_adapter_new.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::sync::Arc;
use std::time::Duration;
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 crate::benches::confirmation_rate;
use crate::benches::confirmation_rate::{send_bulk_txs_and_wait};
use crate::BenchmarkTransactionParams;
use crate::service_adapter1::BenchConfig;
use crate::tx_size::TxSize;
use std::sync::Arc;
use std::time::Duration;

pub async fn benchnew_confirmation_rate_servicerunner(
bench_config: &BenchConfig,
Expand All @@ -20,7 +19,14 @@ 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, bench_config.tx_count, &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()
Expand Down
73 changes: 29 additions & 44 deletions benchrunner-service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,24 @@ mod prometheus;

use crate::args::{get_funded_payer_from_env, read_tenant_configs, TenantConfig};
use crate::cli::Args;
use crate::postgres::metrics_dbstore::{
upsert_benchrun_status, BenchRunStatus,
};
use crate::postgres::metrics_dbstore::{upsert_benchrun_status, BenchRunStatus};
use crate::postgres::postgres_session::PostgresSessionConfig;
use crate::postgres::postgres_session_cache::PostgresSessionCache;
use crate::prometheus::metrics_prometheus::publish_metrics_on_prometheus;
use crate::prometheus::prometheus_sync::PrometheusSync;
use async_trait::async_trait;
use bench::benches::confirmation_rate;
use bench::metrics;
use bench::service_adapter1::BenchConfig;
use clap::Parser;
use futures_util::future::join_all;
use itertools::Itertools;
use log::{debug, error, info, warn};
use solana_sdk::signature::Keypair;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
use std::time::{Duration, SystemTime};
use async_trait::async_trait;
use postgres_types::ToSql;
use solana_sdk::signature::Keypair;
use tokio::sync::OnceCell;
use bench::metrics;
use bench::benches::confirmation_rate;
use bench::tx_size::TxSize;

#[tokio::main]
async fn main() {
Expand Down Expand Up @@ -105,26 +100,20 @@ async fn main() {
let bench_config = bench_configs[permutation[1]].clone();

let bench_impl: Box<dyn BenchTrait> = match permutation[0] {
0 => {
Box::new(BenchRunnerConfirmationRateImpl {
benchrun_at,
tenant_config: tenant_config.clone(),
bench_config: bench_config.clone(),
funded_payer: funded_payer.clone(),
size_tx,
metric: OnceCell::new(),
})
}
1 => {
Box::new(BenchRunnerBench1Impl {
benchrun_at,
tenant_config: tenant_config.clone(),
bench_config: bench_config.clone(),
funded_payer: funded_payer.clone(),
size_tx,
metric: OnceCell::new(),
})
}
0 => Box::new(BenchRunnerConfirmationRateImpl {
benchrun_at,
tenant_config: tenant_config.clone(),
bench_config: bench_config.clone(),
funded_payer: funded_payer.clone(),
metric: OnceCell::new(),
}),
1 => Box::new(BenchRunnerBench1Impl {
benchrun_at,
tenant_config: tenant_config.clone(),
bench_config: bench_config.clone(),
funded_payer: funded_payer.clone(),
metric: OnceCell::new(),
}),
_ => unreachable!(),
};

Expand All @@ -144,14 +133,16 @@ async fn main() {
.await;
}

let metric = bench_impl.run_bench().await;
bench_impl.run_bench().await;

if let Some(postgres_session) = postgres_session.as_ref() {
let save_result = bench_impl.try_save_results_postgres(postgres_session).await;
if let Err(err) = save_result {
warn!("Failed to save metrics to postgres (err {:?}) - continue", err);
warn!(
"Failed to save metrics to postgres (err {:?}) - continue",
err
);
}

}

// publish_metrics_on_prometheus(&tenant_config, &bench_config).await;
Expand Down Expand Up @@ -180,8 +171,6 @@ async fn main() {
join_all(jh_tenant_task).await;
}



// dimensions: least-significant first
fn factorize(i: usize, dimensions: &[usize]) -> Vec<usize> {
let mut i = i;
Expand Down Expand Up @@ -214,21 +203,22 @@ trait BenchTrait: BenchRunner + BenchMetricsPostgresSaver {}
// R: result
#[async_trait]
trait BenchMetricsPostgresSaver: Send + Sync + 'static {
async fn try_save_results_postgres(&self, postgres_session: &PostgresSessionCache) -> anyhow::Result<()>;
async fn try_save_results_postgres(
&self,
postgres_session: &PostgresSessionCache,
) -> anyhow::Result<()>;
}

struct BenchRunnerBench1Impl {
pub benchrun_at: SystemTime,
pub tenant_config: TenantConfig,
pub bench_config: BenchConfig,
pub funded_payer: Arc<Keypair>,
pub size_tx: TxSize,
pub metric: OnceCell<metrics::Metric>,
}

impl BenchTrait for BenchRunnerBench1Impl {}


#[async_trait]
impl BenchRunner for BenchRunnerBench1Impl {
async fn run_bench(&self) {
Expand All @@ -242,15 +232,13 @@ impl BenchRunner for BenchRunnerBench1Impl {
}
}


impl BenchTrait for BenchRunnerConfirmationRateImpl {}

struct BenchRunnerConfirmationRateImpl {
pub benchrun_at: SystemTime,
pub tenant_config: TenantConfig,
pub bench_config: BenchConfig,
pub funded_payer: Arc<Keypair>,
pub size_tx: TxSize,
pub metric: OnceCell<confirmation_rate::Metric>,
}

Expand All @@ -262,10 +250,7 @@ impl BenchRunner for BenchRunnerConfirmationRateImpl {
self.tenant_config.rpc_addr.clone(),
self.funded_payer.insecure_clone(),
)
.await;
.await;
self.metric.set(metric).unwrap();
}
}



26 changes: 12 additions & 14 deletions benchrunner-service/src/postgres/metrics_dbstore.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::args::TenantConfig;
use crate::postgres::postgres_session_cache::PostgresSessionCache;
use bench::metrics;
use bench::benches::confirmation_rate;
use crate::{BenchMetricsPostgresSaver, BenchRunnerBench1Impl, BenchRunnerConfirmationRateImpl};
use async_trait::async_trait;
use bench::service_adapter1::BenchConfig;
use log::warn;
use postgres_types::ToSql;
use std::time::SystemTime;
use async_trait::async_trait;
use crate::{BenchMetricsPostgresSaver, BenchRunner, BenchRunnerBench1Impl, BenchRunnerConfirmationRateImpl};

#[allow(clippy::upper_case_acronyms)]
pub enum BenchRunStatus {
Expand Down Expand Up @@ -60,11 +58,12 @@ pub async fn upsert_benchrun_status(
Ok(())
}



#[async_trait]
impl BenchMetricsPostgresSaver for BenchRunnerBench1Impl {
async fn try_save_results_postgres(&self, postgres_session: &PostgresSessionCache) -> anyhow::Result<()> {
async fn try_save_results_postgres(
&self,
postgres_session: &PostgresSessionCache,
) -> anyhow::Result<()> {
let metric = self.metric.get().expect("metric not set");
let metricjson = serde_json::to_value(metric).unwrap();
let values: &[&(dyn ToSql + Sync)] = &[
Expand Down Expand Up @@ -98,15 +97,16 @@ impl BenchMetricsPostgresSaver for BenchRunnerBench1Impl {
)
.await?;


Ok(())
}
}


#[async_trait]
impl BenchMetricsPostgresSaver for BenchRunnerConfirmationRateImpl {
async fn try_save_results_postgres(&self, postgres_session: &PostgresSessionCache) -> anyhow::Result<()> {
async fn try_save_results_postgres(
&self,
postgres_session: &PostgresSessionCache,
) -> anyhow::Result<()> {
let metric = self.metric.get().expect("metric not set");
let metricjson = serde_json::to_value(metric).unwrap();
let values: &[&(dyn ToSql + Sync)] = &[
Expand All @@ -116,8 +116,8 @@ impl BenchMetricsPostgresSaver for BenchRunnerConfirmationRateImpl {
&(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),
&(metric.average_confirmation_time),
&(metric.average_slot_confirmation_time),
&metricjson,
];
postgres_session
Expand All @@ -143,8 +143,6 @@ impl BenchMetricsPostgresSaver for BenchRunnerConfirmationRateImpl {
)
.await?;


Ok(())
}
}

2 changes: 1 addition & 1 deletion benchrunner-service/src/prometheus/metrics_prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lazy_static::lazy_static! {
}

// TODO implement
pub async fn publish_metrics_on_prometheus(
pub async fn _publish_metrics_on_prometheus(
tenant_config: &TenantConfig,
_bench_config: &BenchConfig,
metric: &Metric,
Expand Down

0 comments on commit 1f502a3

Please sign in to comment.