Skip to content

Commit

Permalink
Make databroker host and port configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
dennismeister93 committed May 13, 2024
1 parent 53aac2f commit e1f7045
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
15 changes: 11 additions & 4 deletions databroker-perf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,36 @@ 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]
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);
}
}
});

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::<u64>::new_with_bounds(1, 60 * 60 * 1000 * 1000, 3).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions databroker-perf/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions databroker-perf/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
match tonic::transport::Channel::from_static(databroker_address)
.connect()
.await
{
Expand Down

0 comments on commit e1f7045

Please sign in to comment.