Skip to content

Commit

Permalink
chore: use join_all to concurrently build clients in benchmark
Browse files Browse the repository at this point in the history
Signed-off-by: bsbds <[email protected]>
  • Loading branch information
bsbds committed Aug 23, 2024
1 parent 7bf01d5 commit c6d7d9b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ anyhow = "1.0.83"
clap = { version = "4", features = ["derive"] }
clippy-utilities = "0.2.0"
etcd-client = { version = "0.13.0", features = ["tls"] }
futures = "0.3.30"
indicatif = "0.17.8"
rand = "0.8.5"
thiserror = "1.0.61"
Expand Down
16 changes: 10 additions & 6 deletions crates/benchmark/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{

use anyhow::Result;
use clippy_utilities::{NumericCast, OverflowArithmetic};
use futures::future::join_all;
use indicatif::ProgressBar;
use rand::RngCore;
use tokio::{
Expand Down Expand Up @@ -158,7 +159,6 @@ impl CommandRunner {

/// Create clients
async fn create_clients(&self) -> Result<Vec<BenchClient>> {
let mut clients = Vec::with_capacity(self.args.clients);
let client_options = ClientOptions::default().with_client_config(ClientConfig::new(
Duration::from_secs(10),
Duration::from_secs(5),
Expand All @@ -180,11 +180,15 @@ impl CommandRunner {
}
})
.collect::<Vec<_>>();
for _ in 0..self.args.clients {
let client =
BenchClient::new(addrs.clone(), self.args.use_curp, client_options.clone()).await?;
clients.push(client);
}
let clients_futs = std::iter::repeat_with(|| {
BenchClient::new(addrs.clone(), self.args.use_curp, client_options.clone())
})
.take(self.args.clients);
let clients = join_all(clients_futs)
.await
.into_iter()
.collect::<Result<_, _>>()?;

Ok(clients)
}

Expand Down

0 comments on commit c6d7d9b

Please sign in to comment.