split metric struct

This commit is contained in:
GroovieGermanikus 2024-03-27 18:40:04 +01:00
parent 2a87e2f8d7
commit 4a6a594873
No known key found for this signature in database
GPG Key ID: 5B6EB831A5CD2015
4 changed files with 61 additions and 60 deletions

View File

@ -12,8 +12,8 @@ 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 {
#[derive(Clone, Copy, Debug, Default, serde::Serialize)]
pub struct Metric {
tx_sent: u64,
tx_confirmed: u64,
// in ms
@ -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:?}");
@ -148,7 +148,7 @@ pub async fn send_bulk_txs_and_wait(
0.0
};
Ok(RpcStat {
Ok(Metric {
tx_sent,
tx_send_errors,
tx_confirmed,
@ -158,10 +158,10 @@ pub async fn send_bulk_txs_and_wait(
})
}
fn calc_stats_avg(stats: &[RpcStat]) -> RpcStat {
fn calc_stats_avg(stats: &[Metric]) -> Metric {
let len = stats.len();
let mut avg = RpcStat {
let mut avg = Metric {
tx_sent: 0,
tx_send_errors: 0,
tx_confirmed: 0,

View File

@ -1,6 +1,13 @@
use std::sync::Arc;
use std::time::Duration;
use log::error;
use solana_rpc_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::signature::Keypair;
use tokio::time::Instant;
use crate::metrics::Metric;
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;
@ -8,11 +15,16 @@ pub async fn benchnew_confirmation_rate_servicerunner(
bench_config: &BenchConfig,
rpc_addr: String,
funded_payer: Keypair,
size_tx: TxSize,
) -> Metric {
let started_at = Instant::now();
todo!()
) -> confirmation_rate::Metric {
let rpc = Arc::new(RpcClient::new(rpc_addr));
let tx_params = BenchmarkTransactionParams {
tx_size: TxSize::Small,
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;
result.unwrap_or_else(|err| {
error!("Failed to send bulk txs and wait: {}", err);
confirmation_rate::Metric::default()
})
}

View File

@ -24,7 +24,9 @@ use std::time::{Duration, SystemTime};
use async_trait::async_trait;
use postgres_types::ToSql;
use solana_sdk::signature::Keypair;
use bench::metrics::Metric;
use tokio::sync::OnceCell;
use bench::metrics;
use bench::benches::confirmation_rate;
use bench::tx_size::TxSize;
#[tokio::main]
@ -97,11 +99,11 @@ async fn main() {
let benchrun_at = SystemTime::now();
let factors = factorize(run_count, &[bench_configs.len(), NUM_BENCH_IMPLS]);
let permutation = factorize(run_count, &[bench_configs.len(), NUM_BENCH_IMPLS]);
let bench_config = bench_configs[factors[0]].clone();
let bench_config = bench_configs[permutation[0]].clone();
let bench_impl: Box<dyn BenchTrait<Metric>> = match factors[1] {
let bench_impl: Box<dyn BenchTrait> = match permutation[1] {
0 => {
Box::new(BenchRunnerBench1Impl {
benchrun_at,
@ -109,6 +111,7 @@ async fn main() {
bench_config: bench_config.clone(),
funded_payer: funded_payer.clone(),
size_tx,
metric: OnceCell::new(),
})
}
1 => {
@ -118,6 +121,7 @@ async fn main() {
bench_config: bench_config.clone(),
funded_payer: funded_payer.clone(),
size_tx,
metric: OnceCell::new(),
})
}
_ => unreachable!(),
@ -128,25 +132,6 @@ async fn main() {
run_count, tenant_id, &bench_config
);
// let bench_impl: Box<dyn BenchTrait<Metric>> = if true {
// Box::new(BenchRunnerBench1Impl {
// benchrun_at,
// tenant_config: tenant_config.clone(),
// bench_config: bench_config.clone(),
// funded_payer: funded_payer.clone(),
// size_tx,
// })
// } else {
// Box::new(BenchRunnerConfirmationRateImpl {
// benchrun_at,
// tenant_config: tenant_config.clone(),
// bench_config: bench_config.clone(),
// funded_payer: funded_payer.clone(),
// size_tx,
// })
// };
if let Some(postgres_session) = postgres_session.as_ref() {
let _dbstatus = upsert_benchrun_status(
postgres_session,
@ -161,14 +146,14 @@ async fn main() {
let metric = bench_impl.run_bench().await;
if let Some(postgres_session) = postgres_session.as_ref() {
let save_result = bench_impl.try_save_results_postgres(&metric, postgres_session).await;
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);
}
}
publish_metrics_on_prometheus(&tenant_config, &bench_config, &metric).await;
// publish_metrics_on_prometheus(&tenant_config, &bench_config).await;
if let Some(postgres_session) = postgres_session.as_ref() {
let _dbstatus = upsert_benchrun_status(
@ -219,16 +204,16 @@ fn test_factorize() {
// R: result
#[async_trait]
trait BenchRunner<M>: Send + Sync + 'static {
async fn run_bench(&self) -> M;
trait BenchRunner: Send + Sync + 'static {
async fn run_bench(&self);
}
trait BenchTrait<M>: BenchRunner<M> + BenchMetricsPostgresSaver<M> {}
trait BenchTrait: BenchRunner + BenchMetricsPostgresSaver {}
// R: result
#[async_trait]
trait BenchMetricsPostgresSaver<M>: Send + Sync + 'static {
async fn try_save_results_postgres(&self, metric: &M, postgres_session: &PostgresSessionCache) -> anyhow::Result<()>;
trait BenchMetricsPostgresSaver: Send + Sync + 'static {
async fn try_save_results_postgres(&self, postgres_session: &PostgresSessionCache) -> anyhow::Result<()>;
}
struct BenchRunnerBench1Impl {
@ -237,26 +222,27 @@ struct BenchRunnerBench1Impl {
pub bench_config: BenchConfig,
pub funded_payer: Arc<Keypair>,
pub size_tx: TxSize,
pub metric: OnceCell<metrics::Metric>,
}
impl BenchTrait<Metric> for BenchRunnerBench1Impl {}
impl BenchTrait for BenchRunnerBench1Impl {}
#[async_trait]
impl BenchRunner<Metric> for BenchRunnerBench1Impl {
async fn run_bench(&self) -> Metric {
bench::service_adapter1::bench_servicerunner(
impl BenchRunner for BenchRunnerBench1Impl {
async fn run_bench(&self) {
let metric = bench::service_adapter1::bench_servicerunner(
&self.bench_config,
self.tenant_config.rpc_addr.clone(),
self.funded_payer.insecure_clone(),
self.size_tx,
)
.await
.await;
}
}
impl BenchTrait<Metric> for BenchRunnerConfirmationRateImpl {}
impl BenchTrait for BenchRunnerConfirmationRateImpl {}
struct BenchRunnerConfirmationRateImpl {
pub benchrun_at: SystemTime,
@ -264,18 +250,19 @@ struct BenchRunnerConfirmationRateImpl {
pub bench_config: BenchConfig,
pub funded_payer: Arc<Keypair>,
pub size_tx: TxSize,
pub metric: OnceCell<confirmation_rate::Metric>,
}
#[async_trait]
impl BenchRunner<Metric> for BenchRunnerConfirmationRateImpl {
async fn run_bench(&self) -> Metric {
bench::service_adapter_new::benchnew_confirmation_rate_servicerunner(
impl BenchRunner for BenchRunnerConfirmationRateImpl {
async fn run_bench(&self) {
let metric = bench::service_adapter_new::benchnew_confirmation_rate_servicerunner(
&self.bench_config,
self.tenant_config.rpc_addr.clone(),
self.funded_payer.insecure_clone(),
self.size_tx,
)
.await
.await;
self.metric.set(metric).unwrap();
}
}

View File

@ -1,6 +1,7 @@
use crate::args::TenantConfig;
use crate::postgres::postgres_session_cache::PostgresSessionCache;
use bench::metrics::Metric;
use bench::metrics;
use bench::benches::confirmation_rate;
use bench::service_adapter1::BenchConfig;
use log::warn;
use postgres_types::ToSql;
@ -62,8 +63,9 @@ pub async fn upsert_benchrun_status(
#[async_trait]
impl BenchMetricsPostgresSaver<Metric> for BenchRunnerBench1Impl {
async fn try_save_results_postgres(&self, metric: &Metric, postgres_session: &PostgresSessionCache) -> anyhow::Result<()> {
impl BenchMetricsPostgresSaver for BenchRunnerBench1Impl {
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)] = &[
&self.tenant_config.tenant_id,
@ -103,8 +105,8 @@ impl BenchMetricsPostgresSaver<Metric> for BenchRunnerBench1Impl {
#[async_trait]
impl BenchMetricsPostgresSaver<Metric> for BenchRunnerConfirmationRateImpl {
async fn try_save_results_postgres(&self, metric: &Metric, postgres_session: &PostgresSessionCache) -> anyhow::Result<()> {
impl BenchMetricsPostgresSaver for BenchRunnerConfirmationRateImpl {
async fn try_save_results_postgres(&self, postgres_session: &PostgresSessionCache) -> anyhow::Result<()> {
todo!();
}
}