From e1f70456e86acef036bf8067e4e05349be148a26 Mon Sep 17 00:00:00 2001 From: Dennis Meister Date: Mon, 13 May 2024 20:41:48 +0200 Subject: [PATCH] Make databroker host and port configurable --- databroker-perf/src/main.rs | 15 +++++++++++---- databroker-perf/src/provider.rs | 4 ++-- databroker-perf/src/subscriber.rs | 7 +++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/databroker-perf/src/main.rs b/databroker-perf/src/main.rs index e0df1817..e69d8f18 100644 --- a/databroker-perf/src/main.rs +++ b/databroker-perf/src/main.rs @@ -16,6 +16,10 @@ struct Config { iterations: u64, #[clap(long, display_order = 2, default_value_t = 32)] sample_size: u64, + #[clap(long, display_order = 3, default_value = "http://127.0.0.1")] + databroker_host: String, + #[clap(long, display_order = 4, default_value_t = 55555)] + databroker_port: u64, } #[tokio::main] @@ -23,13 +27,16 @@ async fn main() { let config = Config::parse(); let iterations = config.iterations; let sample_size = config.sample_size; + let databroker_address: &'static str = Box::leak( + format!("{}:{}", config.databroker_host, config.databroker_port).into_boxed_str(), + ); let (subscriber_tx, mut subscriber_rx) = mpsc::channel(100); let (provider_tx, mut provider_rx) = mpsc::channel(100); let subscriber_sampler = Sampler::new(iterations, sample_size, subscriber_tx); let provider_sampler = Sampler::new(iterations, sample_size, provider_tx); - let _subscriber = tokio::spawn(async { - match subscriber::subscribe(subscriber_sampler).await { + let _subscriber = tokio::spawn(async move { + match subscriber::subscribe(subscriber_sampler, &databroker_address).await { Ok(_) => {} Err(err) => { println!("{}", err); @@ -37,8 +44,8 @@ async fn main() { } }); - let _provider = tokio::spawn(async { - provider::provide(provider_sampler).await; + let _provider = tokio::spawn(async move { + provider::provide(provider_sampler, &databroker_address).await; }); let mut hist = Histogram::::new_with_bounds(1, 60 * 60 * 1000 * 1000, 3).unwrap(); diff --git a/databroker-perf/src/provider.rs b/databroker-perf/src/provider.rs index 50986a7e..af4d4e97 100644 --- a/databroker-perf/src/provider.rs +++ b/databroker-perf/src/provider.rs @@ -38,8 +38,8 @@ fn create_payload(value: impl ToString, id: i32) -> proto::StreamDatapointsReque } } -pub(crate) async fn provide(sampler: sampler::Sampler) { - let connect = tonic::transport::Channel::from_static("http://127.0.0.1:55555") +pub(crate) async fn provide(sampler: sampler::Sampler, databroker_address: &'static str) { + let connect = tonic::transport::Channel::from_static(databroker_address) .connect() .await; match connect { diff --git a/databroker-perf/src/subscriber.rs b/databroker-perf/src/subscriber.rs index ef6937c9..c9be7e19 100644 --- a/databroker-perf/src/subscriber.rs +++ b/databroker-perf/src/subscriber.rs @@ -15,8 +15,11 @@ use crate::sampler; use databroker_proto::v1 as proto; use tokio::time::Instant; -pub(crate) async fn subscribe(sampler: sampler::Sampler) -> Result<(), Box> { - match tonic::transport::Channel::from_static("http://127.0.0.1:55555") +pub(crate) async fn subscribe( + sampler: sampler::Sampler, + databroker_address: &'static str, +) -> Result<(), Box> { + match tonic::transport::Channel::from_static(databroker_address) .connect() .await {